|
||||||||||
| 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
org.apache.commons.collections.MultiHashMap<K,V>
public class MultiHashMap<K,V>
MultiHashMap is the default implementation of the
MultiMap interface.
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.
For example:
MultiMap mhm = new MultiHashMap(); mhm.put(key, "A"); mhm.put(key, "B"); mhm.put(key, "C"); List list = (List) mhm.get(key);
list will be a list containing "A", "B", "C".
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
Map.Entry<K,V> |
| Constructor Summary | |
|---|---|
MultiHashMap()
Constructor. |
|
MultiHashMap(int initialCapacity)
Constructor. |
|
MultiHashMap(int initialCapacity,
float loadFactor)
Constructor. |
|
MultiHashMap(Map<K,V> mapToCopy)
Constructor that copies the input map creating an independent copy. |
|
| Method Summary | |
|---|---|
void |
clear()
Clear the map. |
Object |
clone()
Clones the map creating an independent copy. |
boolean |
containsValue(Object value)
Checks whether the map contains the value specified. |
boolean |
containsValue(Object key,
Object value)
Checks whether the collection at the specified key contains the value. |
protected Collection<V> |
createCollection(Collection<V> coll)
Creates a new instance of the map value Collection container. |
Collection<V> |
getCollection(K key)
Gets the collection mapped to the specified key. |
Iterator<V> |
iterator(K key)
Gets an iterator for the collection mapped to the specified key. |
V |
put(Object key,
Object value)
Adds the value to the collection associated with the specified key. |
boolean |
putAll(K key,
Collection<V> values)
Adds a collection of values to the collection associated with the specified key. |
V |
remove(K key,
V item)
Removes a specific value from map. |
int |
size(K 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. |
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 |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.apache.commons.collections.MultiMap |
|---|
get, remove, size |
| Methods inherited from interface java.util.Map |
|---|
containsKey, entrySet, equals, hashCode, isEmpty, keySet, putAll |
| Constructor Detail |
|---|
public MultiHashMap()
public MultiHashMap(int initialCapacity)
initialCapacity - the initial map capacity
public MultiHashMap(int initialCapacity,
float loadFactor)
initialCapacity - the initial map capacityloadFactor - the amount 0.0-1.0 at which to resize the mappublic MultiHashMap(Map<K,V> mapToCopy)
mapToCopy - a Map to copy| Method Detail |
|---|
public int totalSize()
public Collection<V> getCollection(K key)
get(key).
key - the key to retrieve
public int size(K key)
key - the key to get size for
public Iterator<V> iterator(K key)
key - the key to get an iterator for
public V put(Object key,
Object value)
Map the previous value is not replaced.
Instead the new value is added to the collection stored against the key.
put in interface Mapput in interface MultiMap<K,V>put in class HashMapkey - the key to store againstvalue - the value to add to the collection at the key
public boolean putAll(K key,
Collection<V> values)
key - the key to store againstvalues - the values to add to the collection at the key, null ignored
public boolean containsValue(Object value)
containsValue in interface MapcontainsValue in interface MultiMap<K,V>containsValue in class HashMapvalue - the value to search for
public boolean containsValue(Object key,
Object value)
value - the value to search for
public V remove(K key,
V item)
null will be returned
from a subsequant get(key).
remove in interface MultiMap<K,V>key - the key to remove fromitem - the value to remove
public void clear()
clear in interface Mapclear in class HashMappublic Collection<V> values()
values in interface Mapvalues in interface MultiMap<K,V>values in class HashMappublic Object clone()
clone in class HashMapprotected Collection<V> createCollection(Collection<V> coll)
coll - the collection to copy, may be null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||