Build 1.0_r1(from source)

java.util
Class EnumMap<K extends Enum<K>,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.EnumMap<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>

public class EnumMap<K extends Enum<K>,V>
extends AbstractMap<K,V>
implements Map<K,V>, Serializable, Cloneable

See Also:
Serialized Form

Field Summary
(package private)  int enumSize
           
(package private)  boolean[] hasMapping
           
(package private)  Enum[] keys
           
(package private)  Object[] values
           
 
Fields inherited from class java.util.AbstractMap
keySet, valuesCollection
 
Constructor Summary
EnumMap(Class<K> keyType)
          Constructs an empty enum map using the given key type.
EnumMap(EnumMap<K,? extends V> map)
          Constructs an enum map using the same key type as the given enum map and initially containing the same mappings.
EnumMap(Map<K,? extends V> map)
          Constructs an enum map initialized from the given map.
 
Method Summary
 void clear()
          Removes all mappings in this map.
 EnumMap<K,V> clone()
          Returns a shallow copy of this map.
 boolean containsKey(Object key)
          Returns true if this map has a mapping for the given key.
 boolean containsValue(Object value)
          Returns true if this map has one or more keys mapped to the given value.
 Set<Map.Entry<K,V>> entrySet()
          Returns a Set} view of the mappings contained in this map.
 boolean equals(Object object)
          Compares the given object with this map.
 V get(Object key)
          Returns the value which is mapped to the given key in this map, or null if this map has no mapping for the given key.
 Set<K> keySet()
          Returns a Set} view of the keys contained in this map.
 V put(K key, V value)
          Associates the given value with the given key in this map.
 void putAll(Map<? extends K,? extends V> map)
          Copies all the mappings in the given map to this map.
 V remove(Object key)
          Removes the mapping for this key from this map if it is present.
 int size()
          Returns the number of the mappings in this map.
 Collection<V> values()
          Returns a Collection} view of the values contained in this map.
 
Methods inherited from class java.util.AbstractMap
hashCode, isEmpty, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
hashCode, isEmpty
 

Field Detail

keys

transient Enum[] keys

values

transient Object[] values

hasMapping

transient boolean[] hasMapping

enumSize

transient int enumSize
Constructor Detail

EnumMap

public EnumMap(Class<K> keyType)
Constructs an empty enum map using the given key type.

Parameters:
keyType - the class object of the key type used by this enum map
Throws:
NullPointerException - if the keyType is null

EnumMap

public EnumMap(EnumMap<K,? extends V> map)
Constructs an enum map using the same key type as the given enum map and initially containing the same mappings.

Parameters:
map - the enum map from which this enum map is initialized
Throws:
NullPointerException - if the map is null

EnumMap

public EnumMap(Map<K,? extends V> map)
Constructs an enum map initialized from the given map. If the given map is an EnumMap instance, this constructor behaves in the exactly the same way as EnumMap(EnumMap)}. Otherwise, the given map at least should contain one mapping.

Parameters:
map - the map from which this enum map is initialized
Throws:
IllegalArgumentException - if the map is not an enum map instance and does not contain any mappings
NullPointerException - if the map is null
Method Detail

clear

public void clear()
Removes all mappings in this map.

Specified by:
clear in interface Map<K extends Enum<K>,V>
Overrides:
clear in class AbstractMap<K extends Enum<K>,V>
See Also:
AbstractMap.isEmpty(), AbstractMap.size()

clone

public EnumMap<K,V> clone()
Returns a shallow copy of this map.

Overrides:
clone in class AbstractMap<K extends Enum<K>,V>
Returns:
a shallow copy of this map

containsKey

public boolean containsKey(Object key)
Returns true if this map has a mapping for the given key.

Specified by:
containsKey in interface Map<K extends Enum<K>,V>
Overrides:
containsKey in class AbstractMap<K extends Enum<K>,V>
Parameters:
key - the key whose presence in this map is to be tested
Returns:
true if this map has a mapping for the given key.

containsValue

public boolean containsValue(Object value)
Returns true if this map has one or more keys mapped to the given value.

Specified by:
containsValue in interface Map<K extends Enum<K>,V>
Overrides:
containsValue in class AbstractMap<K extends Enum<K>,V>
Parameters:
value - the value whose presence in this map is to be tested
Returns:
true if this map has one or more keys mapped to the given value.

entrySet

public Set<Map.Entry<K,V>> entrySet()
Returns a Set} view of the mappings contained in this map. The returned set complies with the general rule specified in Map.entrySet()}. The set's iterator will return the mappings in the their keys' natural order(the enum constants are declared in this order)

Specified by:
entrySet in interface Map<K extends Enum<K>,V>
Specified by:
entrySet in class AbstractMap<K extends Enum<K>,V>
Returns:
a set view of the mappings contained in this map.

equals

public boolean equals(Object object)
Compares the given object with this map. Returns true if the given object is equal to this map.

Specified by:
equals in interface Map<K extends Enum<K>,V>
Overrides:
equals in class AbstractMap<K extends Enum<K>,V>
Parameters:
object - the object to be compared with this map
Returns:
true if the given object is equal to this map.
See Also:
AbstractMap.hashCode()

get

public V get(Object key)
Returns the value which is mapped to the given key in this map, or null if this map has no mapping for the given key.

Specified by:
get in interface Map<K extends Enum<K>,V>
Overrides:
get in class AbstractMap<K extends Enum<K>,V>
Parameters:
key - the key whose associated value is to be returned
Returns:
the value to which this map maps the given key, or null if this map has no mapping for the given key.

keySet

public Set<K> keySet()
Returns a Set} view of the keys contained in this map. The returned set complies with the general rule specified in Map.keySet()}. The set's iterator will return the keys in the their natural order(the enum constants are declared in this order)

Specified by:
keySet in interface Map<K extends Enum<K>,V>
Overrides:
keySet in class AbstractMap<K extends Enum<K>,V>
Returns:
a set view of the keys contained in this map.

put

public V put(K key,
             V value)
Associates the given value with the given key in this map. If the map previously had a mapping for this key, the old value is replaced.

Specified by:
put in interface Map<K extends Enum<K>,V>
Overrides:
put in class AbstractMap<K extends Enum<K>,V>
Parameters:
key - the key with which the given value is to be associated value
value - the value to be associated with the given key
Returns:
the value to which this map maps the given key, or null if this map has no mapping for the given key.
Throws:
NullPointerException - if the given key is null

putAll

public void putAll(Map<? extends K,? extends V> map)
Copies all the mappings in the given map to this map. These mappings will replace all mappings that this map had for all of the keys currently in the given map.

Specified by:
putAll in interface Map<K extends Enum<K>,V>
Overrides:
putAll in class AbstractMap<K extends Enum<K>,V>
Parameters:
map - the key whose presence in this map is to be tested
Throws:
NullPointerException - if the given map is null, or if one or more keys in the given map are null

remove

public V remove(Object key)
Removes the mapping for this key from this map if it is present.

Specified by:
remove in interface Map<K extends Enum<K>,V>
Overrides:
remove in class AbstractMap<K extends Enum<K>,V>
Parameters:
key - the key whose mapping is to be removed from this map
Returns:
the previous value associated with the given key, or null if this map has no mapping for this key.

size

public int size()
Returns the number of the mappings in this map.

Specified by:
size in interface Map<K extends Enum<K>,V>
Overrides:
size in class AbstractMap<K extends Enum<K>,V>
Returns:
the number of the mappings in this map

values

public Collection<V> values()
Returns a Collection} view of the values contained in this map. The returned collection complys with the general rule specified in Map.values()}. The collection's iterator will return the values in the their corresponding keys' natural order(the enum constants are declared in this order)

Specified by:
values in interface Map<K extends Enum<K>,V>
Overrides:
values in class AbstractMap<K extends Enum<K>,V>
Returns:
a collection view of the mappings contained in this map.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature