Package org.apache.pivot.collections
Class EnumMap<E extends java.lang.Enum<E>,V>
- java.lang.Object
-
- org.apache.pivot.collections.EnumMap<E,V>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<E>,Collection<E>,Dictionary<E,V>,Map<E,V>
public class EnumMap<E extends java.lang.Enum<E>,V> extends java.lang.Object implements Map<E,V>, java.io.Serializable
Implementation of theMapinterface whose keys are backed by an enum.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Dictionary
Dictionary.Pair<K,V>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all entries in the map.booleancontainsKey(E key)Tests the existence of a key in the dictionary.Vget(E key)Retrieves the value for the given key.java.util.Comparator<E>getComparator()Returns the collection's sort order.intgetCount()Returns the number of entries in the map.ListenerList<MapListener<E,V>>getMapListeners()Returns the map listener collection.booleanisEmpty()Tests the emptiness of the collection.java.util.Iterator<E>iterator()Vput(E key, V value)Sets the value of the given key, creating a new entry or replacing the existing value, and firing a corresponding event.Vremove(E key)Removes a key/value pair from the map.voidsetComparator(java.util.Comparator<E> comparator)Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.pivot.collections.Dictionary
containsAny, copy, getBoolean, getBoolean, getColor, getFirst, getFont, getInt, getInt, getString, getString, putAll
-
-
-
-
Constructor Detail
-
EnumMap
public EnumMap(java.lang.Class<E> enumClass)
-
-
Method Detail
-
get
public V get(E key)
Description copied from interface:DictionaryRetrieves the value for the given key.- Specified by:
getin interfaceDictionary<E extends java.lang.Enum<E>,V>- Parameters:
key- The key whose value is to be returned.- Returns:
- The value corresponding to
key, or null if the key does not exist. Will also return null if the key refers to a null value. UseDictionary.containsKey(K)to distinguish between these two cases.
-
put
public V put(E key, V value)
Description copied from interface:MapSets the value of the given key, creating a new entry or replacing the existing value, and firing a corresponding event.- Specified by:
putin interfaceDictionary<E extends java.lang.Enum<E>,V>- Specified by:
putin interfaceMap<E extends java.lang.Enum<E>,V>- Parameters:
key- The key whose value is to be set.value- The value to be associated with the given key.- Returns:
- The value previously associated with the key.
- See Also:
MapListener.valueAdded(Map, Object),MapListener.valueUpdated(Map, Object, Object)
-
remove
public V remove(E key)
Description copied from interface:DictionaryRemoves a key/value pair from the map.
-
clear
public void clear()
Description copied from interface:MapRemoves all entries in the map.- Specified by:
clearin interfaceCollection<E extends java.lang.Enum<E>>- Specified by:
clearin interfaceMap<E extends java.lang.Enum<E>,V>- See Also:
MapListener.mapCleared(Map)
-
containsKey
public boolean containsKey(E key)
Description copied from interface:DictionaryTests the existence of a key in the dictionary.- Specified by:
containsKeyin interfaceDictionary<E extends java.lang.Enum<E>,V>- Parameters:
key- The key whose presence in the dictionary is to be tested.- Returns:
trueif the key exists in the dictionary;false, otherwise.
-
isEmpty
public boolean isEmpty()
Description copied from interface:CollectionTests the emptiness of the collection.- Specified by:
isEmptyin interfaceCollection<E extends java.lang.Enum<E>>- Returns:
trueif the collection contains no elements;false, otherwise.
-
getCount
public int getCount()
Description copied from interface:MapReturns the number of entries in the map.
-
getComparator
public java.util.Comparator<E> getComparator()
Description copied from interface:CollectionReturns the collection's sort order.- Specified by:
getComparatorin interfaceCollection<E extends java.lang.Enum<E>>- Returns:
- The comparator used to order elements in the collection, or
nullif the sort order is undefined. - See Also:
Collection.setComparator(Comparator)
-
setComparator
@UnsupportedOperation public void setComparator(java.util.Comparator<E> comparator)
Description copied from interface:CollectionSets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.Calling this method more than once with the same comparator will re-sort the collection.
- Specified by:
setComparatorin interfaceCollection<E extends java.lang.Enum<E>>- Specified by:
setComparatorin interfaceMap<E extends java.lang.Enum<E>,V>- Parameters:
comparator- The comparator used to order elements in the collection, or null if the collection is unsorted.- See Also:
MapListener.comparatorChanged(Map, Comparator)
-
iterator
public java.util.Iterator<E> iterator()
-
getMapListeners
public ListenerList<MapListener<E,V>> getMapListeners()
Description copied from interface:MapReturns the map listener collection.- Specified by:
getMapListenersin interfaceMap<E extends java.lang.Enum<E>,V>- Returns:
- Current list of listeners on this map.
-
-