org.apache.pivot.collections
Class EnumMap<E extends Enum<E>,V>

java.lang.Object
  extended by org.apache.pivot.collections.EnumMap<E,V>
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, Dictionary<E,V>, Map<E,V>

public class EnumMap<E extends Enum<E>,V>
extends Object
implements Map<E,V>, Serializable

Implementation of the Set interface whose keys are backed by a set of enum values.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Map
Map.MapListenerList<K,V>
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Dictionary
Dictionary.Pair<K,V>
 
Constructor Summary
EnumMap(Class<E> enumClass)
           
 
Method Summary
 void clear()
          Removes all entries in the map.
 boolean containsKey(E key)
          Tests the existence of a key in the dictionary.
 V get(E key)
          Retrieves the value for the given key.
 Comparator<E> getComparator()
          Returns the collection's sort order.
 int getCount()
          Returns the number of entries in the map.
 ListenerList<MapListener<E,V>> getMapListeners()
          Returns the map listener collection.
 boolean isEmpty()
          Tests the emptiness of the collection.
 Iterator<E> iterator()
           
 V put(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.
 V remove(E key)
          Removes a key/value pair from the map.
 void setComparator(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
 

Constructor Detail

EnumMap

public EnumMap(Class<E> enumClass)
Method Detail

get

public V get(E key)
Description copied from interface: Dictionary
Retrieves the value for the given key.

Specified by:
get in interface Dictionary<E extends 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. Use containsKey() to distinguish between these two cases.

put

public V put(E key,
             V value)
Description copied from interface: Map
Sets the value of the given key, creating a new entry or replacing the existing value, and firing a corresponding event.

Specified by:
put in interface Dictionary<E extends Enum<E>,V>
Specified by:
put in interface Map<E extends 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: Dictionary
Removes a key/value pair from the map.

Specified by:
remove in interface Dictionary<E extends Enum<E>,V>
Specified by:
remove in interface Map<E extends Enum<E>,V>
Parameters:
key - The key whose mapping is to be removed.
Returns:
The value that was removed.
See Also:
MapListener.valueRemoved(Map, Object, Object)

clear

public void clear()
Description copied from interface: Map
Removes all entries in the map.

Specified by:
clear in interface Collection<E extends Enum<E>>
Specified by:
clear in interface Map<E extends Enum<E>,V>
See Also:
MapListener.mapCleared(Map)

containsKey

public boolean containsKey(E key)
Description copied from interface: Dictionary
Tests the existence of a key in the dictionary.

Specified by:
containsKey in interface Dictionary<E extends Enum<E>,V>
Parameters:
key - The key whose presence in the dictionary is to be tested.
Returns:
true if the key exists in the dictionary; false, otherwise.

isEmpty

public boolean isEmpty()
Description copied from interface: Collection
Tests the emptiness of the collection.

Specified by:
isEmpty in interface Collection<E extends Enum<E>>
Returns:
true if the collection contains no elements; false, otherwise.

getCount

public int getCount()
Description copied from interface: Map
Returns the number of entries in the map.

Specified by:
getCount in interface Map<E extends Enum<E>,V>

getComparator

public Comparator<E> getComparator()
Description copied from interface: Collection
Returns the collection's sort order.

Specified by:
getComparator in interface Collection<E extends Enum<E>>
Returns:
The comparator used to order elements in the collection, or null if the sort order is undefined.
See Also:
Collection.setComparator(Comparator)

setComparator

public void setComparator(Comparator<E> comparator)
Description copied from interface: Collection
Sets 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:
setComparator in interface Collection<E extends Enum<E>>
Specified by:
setComparator in interface Map<E extends 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 Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E extends Enum<E>>

getMapListeners

public ListenerList<MapListener<E,V>> getMapListeners()
Description copied from interface: Map
Returns the map listener collection.

Specified by:
getMapListeners in interface Map<E extends Enum<E>,V>