|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.HashMap
annas.graph.MultiHashMap<K,V>
public class MultiHashMap<K,V>
A MultiMap is a Map with slightly different semantics. Putting a value into the map will add the value to a Collection at that key. Getting a value will return a Collection, holding all the values put to that key. This implementation uses an ArrayList as the collection. The internal storage list is made available without cloning via the get(Object) and entrySet() methods. The implementation returns null when there are no values mapped to a key.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Constructor Summary | |
---|---|
MultiHashMap()
Constructor. |
|
MultiHashMap(int initialCapacity)
Constructor. |
|
MultiHashMap(int initialCapacity,
float loadFactor)
Constructor. |
Method Summary | |
---|---|
void |
clear()
Clear the map. |
java.lang.Object |
clone()
Clones the map creating an independent copy. |
boolean |
containsValue(java.lang.Object value)
Checks whether the map contains the value specified. |
boolean |
containsValue(java.lang.Object key,
java.lang.Object value)
Checks whether the collection at the specified key contains the value. |
java.util.Collection |
getCollection(java.lang.Object key)
Gets the collection mapped to the specified key. |
java.util.Iterator |
iterator(java.lang.Object key)
Gets an iterator for the collection mapped to the specified key. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Adds the value to the collection associated with the specified key. |
boolean |
putAll(java.lang.Object key,
java.util.Collection values)
Adds a collection of values to the collection associated with the specified key. |
java.lang.Object |
remove(java.lang.Object key,
java.lang.Object item)
Removes a specific value from map. |
int |
size(java.lang.Object key)
Gets the size of the collection mapped to the specified key. |
int |
totalSize()
Gets the total size of the map by counting all the values. |
java.util.Collection<V> |
values()
Gets a collection containing all the values in the map. |
Methods inherited from class java.util.HashMap |
---|
containsKey, entrySet, get, isEmpty, keySet, putAll, remove, size |
Methods inherited from class java.util.AbstractMap |
---|
equals, hashCode, toString |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals, hashCode |
Constructor Detail |
---|
public MultiHashMap()
public MultiHashMap(int initialCapacity)
initialCapacity
- the initial map capacitypublic MultiHashMap(int initialCapacity, float loadFactor)
initialCapacity
- the initial map capacityloadFactor
- the amount 0.0-1.0 at which to resize the mapMethod Detail |
---|
public void clear()
clear
in interface java.util.Map
clear
in class java.util.HashMap
public java.lang.Object clone()
clone
in class java.util.HashMap
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
containsValue
in class java.util.HashMap
value
- the value to search for
public boolean containsValue(java.lang.Object key, java.lang.Object value)
value
- the value to search for
public java.util.Collection getCollection(java.lang.Object key)
key
- the key to retrieve
public java.util.Iterator iterator(java.lang.Object key)
key
- the key to get an iterator for
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
put
in class java.util.HashMap
key
- the key to store againstvalue
- the value to add to the collection at the key
public boolean putAll(java.lang.Object key, java.util.Collection values)
key
- the key to store againstvalues
- the values to add to the collection at the key, null ignored
public java.lang.Object remove(java.lang.Object key, java.lang.Object item)
key
- the key to remove fromitem
- the value to remove
public int size(java.lang.Object key)
key
- the key to get size for
public int totalSize()
public java.util.Collection<V> values()
values
in interface java.util.Map
values
in class java.util.HashMap
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |