Package org.apache.pivot.collections
Class HashMap<K,V>
- java.lang.Object
-
- org.apache.pivot.collections.HashMap<K,V>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<K>,Collection<K>,Dictionary<K,V>,Map<K,V>
- Direct Known Subclasses:
CategorySeries
public class HashMap<K,V> extends java.lang.Object implements Map<K,V>, java.io.Serializable
Implementation of theMapinterface that is backed by a hash table.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Dictionary
Dictionary.Pair<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_CAPACITYstatic floatDEFAULT_LOAD_FACTOR
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all entries in the map.booleancontainsKey(K key)Tests the existence of a key in the dictionary.booleanequals(java.lang.Object o)Vget(K key)Retrieves the value for the given key.intgetCapacity()java.util.Comparator<K>getComparator()Returns the collection's sort order.intgetCount()Returns the number of entries in the map.ListenerList<MapListener<K,V>>getMapListeners()Returns the map listener collection.inthashCode()booleanisEmpty()Tests the emptiness of the collection.java.util.Iterator<K>iterator()Vput(K 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(K key)Removes a key/value pair from the map.voidsetComparator(java.util.Comparator<K> comparator)Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.pivot.collections.Dictionary
containsAny, copy, getBoolean, getBoolean, getColor, getFirst, getFont, getInt, getInt, getString, getString, putAll
-
-
-
-
Field Detail
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITY
- See Also:
- Constant Field Values
-
DEFAULT_LOAD_FACTOR
public static final float DEFAULT_LOAD_FACTOR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HashMap
public HashMap()
-
HashMap
public HashMap(int capacity)
-
HashMap
public HashMap(int capacity, float loadFactor)
-
HashMap
@SafeVarargs public HashMap(Dictionary.Pair<K,V>... entries)
-
HashMap
public HashMap(java.util.Comparator<K> comparator)
-
-
Method Detail
-
get
public V get(K key)
Retrieves the value for the given key.- Specified by:
getin interfaceDictionary<K,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. - Throws:
java.lang.IllegalArgumentException- Ifkeyis null.
-
put
public V put(K key, V value)
Sets the value of the given key, creating a new entry or replacing the existing value, and firing a corresponding event.- Specified by:
putin interfaceDictionary<K,V>- Specified by:
putin interfaceMap<K,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.
- Throws:
java.lang.IllegalArgumentException- Ifkeyis null.- See Also:
MapListener.valueAdded(Map, Object),MapListener.valueUpdated(Map, Object, Object)
-
remove
public V remove(K key)
Removes a key/value pair from the map.- Specified by:
removein interfaceDictionary<K,V>- Specified by:
removein interfaceMap<K,V>- Parameters:
key- The key whose mapping is to be removed.- Returns:
- The value that was removed.
- Throws:
java.lang.IllegalArgumentException- Ifkeyis null.- See Also:
MapListener.valueRemoved(Map, Object, Object)
-
clear
public void clear()
Description copied from interface:MapRemoves all entries in the map.- Specified by:
clearin interfaceCollection<K>- Specified by:
clearin interfaceMap<K,V>- See Also:
MapListener.mapCleared(Map)
-
containsKey
public boolean containsKey(K key)
Tests the existence of a key in the dictionary.- Specified by:
containsKeyin interfaceDictionary<K,V>- Parameters:
key- The key whose presence in the dictionary is to be tested.- Returns:
trueif the key exists in the dictionary;false, otherwise.- Throws:
java.lang.IllegalArgumentException- Ifkeyis null.
-
isEmpty
public boolean isEmpty()
Description copied from interface:CollectionTests the emptiness of the collection.- Specified by:
isEmptyin interfaceCollection<K>- 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.
-
getCapacity
public int getCapacity()
-
getComparator
public java.util.Comparator<K> getComparator()
Description copied from interface:CollectionReturns the collection's sort order.- Specified by:
getComparatorin interfaceCollection<K>- Returns:
- The comparator used to order elements in the collection, or
nullif the sort order is undefined. - See Also:
Collection.setComparator(Comparator)
-
setComparator
public void setComparator(java.util.Comparator<K> 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<K>- Specified by:
setComparatorin interfaceMap<K,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<K> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<K>
-
getMapListeners
public ListenerList<MapListener<K,V>> getMapListeners()
Description copied from interface:MapReturns the map listener collection.- Specified by:
getMapListenersin interfaceMap<K,V>- Returns:
- Current list of listeners on this map.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-