public class EnumMap<K extends Enum<K>,V> extends AbstractMap<K,V> implements Cloneable, Serializable
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Constructor and Description |
|---|
EnumMap(Class<K> keyType) |
EnumMap(EnumMap<K,? extends V> map) |
EnumMap(Map<K,? extends V> map) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Remove all entries from this Map (optional operation).
|
EnumMap<K,V> |
clone()
Create a shallow copy of this Map, no keys or values are copied.
|
boolean |
containsKey(Object key)
Returns true if this contains a mapping for the given key.
|
boolean |
containsValue(Object value)
Returns true if this contains at least one mapping with the given value.
|
Set<Map.Entry<K,V>> |
entrySet()
Returns a set view of the mappings in this Map.
|
boolean |
equals(Object o)
Compares the specified object with this map for equality.
|
V |
get(Object key)
Returns the value mapped by the given key.
|
Set<K> |
keySet()
Returns a set view of this map's keys.
|
V |
put(K key,
V value)
Associates the given key to the given value (optional operation).
|
void |
putAll(Map<? extends K,? extends V> map)
Copies all entries of the given map to this one (optional operation).
|
V |
remove(Object key)
Removes the mapping for this key if present (optional operation).
|
int |
size()
Returns the number of key-value mappings in the map.
|
Collection<V> |
values()
Returns a collection or bag view of this map's values.
|
hashCode, isEmpty, toStringpublic int size()
AbstractMapentrySet().size().public boolean containsValue(Object value)
AbstractMapentrySet(), returning true if a match
is found, false if the iteration ends. A match is
defined as a value, v, where (value == null ? v == null :
value.equals(v)). Subclasses are unlikely to implement
this more efficiently.containsValue in interface Map<K extends Enum<K>,V>containsValue in class AbstractMap<K extends Enum<K>,V>value - the value to search forAbstractMap.containsKey(Object)public boolean containsKey(Object key)
AbstractMapentrySet(), returning true if a match
is found, false if the iteration ends. Many subclasses
can implement this more efficiently.containsKey in interface Map<K extends Enum<K>,V>containsKey in class AbstractMap<K extends Enum<K>,V>key - the key to search forAbstractMap.containsValue(Object)public V get(Object key)
AbstractMapnull if
there is no mapping. However, in Maps that accept null values, you
must rely on containsKey to determine if a mapping exists.
This iteration takes linear time, searching entrySet().iterator() of
the key. Many implementations override this method.public V put(K key, V value)
AbstractMapnull values, a null return does not always
imply that the mapping was created.public V remove(Object key)
AbstractMapremove method.
It returns the result of getValue() on the entry, if found,
or null if no entry is found. Note that maps which permit null values
may also return null if the key was removed. If the entrySet does not
support removal, this will also fail. This is O(n), so many
implementations override it for efficiency.remove in interface Map<K extends Enum<K>,V>remove in class AbstractMap<K extends Enum<K>,V>key - the key to removeIterator.remove()public void putAll(Map<? extends K,? extends V> map)
AbstractMapput,
so it is not supported if puts are not.public void clear()
AbstractMapAbstractMap.clear unless you want an infinite loop.public Set<K> keySet()
AbstractMapThis implementation creates an AbstractSet, where the iterator wraps the entrySet iterator, size defers to the Map's size, and contains defers to the Map's containsKey. The set is created on first use, and returned on subsequent uses, although since no synchronization occurs, there is a slight possibility of creating two sets.
keySet in interface Map<K extends Enum<K>,V>keySet in class AbstractMap<K extends Enum<K>,V>Set.iterator(),
AbstractMap.size(),
AbstractMap.containsKey(Object),
AbstractMap.values()public Collection<V> values()
AbstractMapThis implementation creates an AbstractCollection, where the iterator wraps the entrySet iterator, size defers to the Map's size, and contains defers to the Map's containsValue. The collection is created on first use, and returned on subsequent uses, although since no synchronization occurs, there is a slight possibility of creating two collections.
values in interface Map<K extends Enum<K>,V>values in class AbstractMap<K extends Enum<K>,V>Collection.iterator(),
AbstractMap.size(),
AbstractMap.containsValue(Object),
AbstractMap.keySet()public Set<Map.Entry<K,V>> entrySet()
AbstractMapIterator.remove, Set.remove,
removeAll, retainAll, and clear.
Element addition is not supported via this set.public boolean equals(Object o)
AbstractMaptrue if the other object is a Map with the same mappings,
that is,o instanceof Map && entrySet().equals(((Map) o).entrySet();public EnumMap<K,V> clone()
AbstractMapsuper.clone().clone in class AbstractMap<K extends Enum<K>,V>Cloneable,
Object.clone()