加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090309031309/http://developer.android.com:80/reference/java/util/EnumMap.html
public class

EnumMap

extends AbstractMap<K, V>
implements Serializable Cloneable Map<K, V>
java.lang.Object
   ↳ java.util.AbstractMap<K, V>
     ↳ java.util.EnumMap<K extends java.lang.Enum<K>, V>

Summary

Public Constructors
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.
Public Methods
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<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.
[Expand]
Inherited Methods
From class java.util.AbstractMap
From class java.lang.Object
From interface java.util.Map

Public Constructors

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

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

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

Public Methods

public void clear ()

Removes all mappings in this map.

public EnumMap<K, V> clone ()

Returns a shallow copy of this map.

Returns
  • a shallow copy of this map

public boolean containsKey (Object key)

Returns true if this map has a mapping for the given key.

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.

public boolean containsValue (Object value)

Returns true if this map has one or more keys mapped to the given value.

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.

public Set<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 entrySet()}. The set's iterator will return the mappings in the their keys' natural order(the enum constants are declared in this order)

Returns
  • a set view of the mappings contained in this map.

public boolean equals (Object object)

Compares the given object with this map. Returns true if the given object is equal to this map.

Parameters
object the object to be compared with this map
Returns
  • true if the given object is equal to this map.

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.

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.

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 keySet()}. The set's iterator will return the keys in the their natural order(the enum constants are declared in this order)

Returns
  • a set view of the keys contained in this map.

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.

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

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.

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

public V remove (Object key)

Removes the mapping for this key from this map if it is present.

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.

public int size ()

Returns the number of the mappings in this map.

Returns
  • the number of the mappings in this map

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 values()}. The collection's iterator will return the values in the their corresponding keys' natural order(the enum constants are declared in this order)

Returns
  • a collection view of the mappings contained in this map.