|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractMap | +--java.util.HashMap | +--org.apache.commons.collections.MultiHashMap
MultiHashMap
is the default implementation of the
MultiMap
interface.
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 always return a Collection, holding all the
values put to that key. This implementation uses an ArrayList as the
collection.
For example:
MultiMap mhm = new MultiHashMap(); mhm.put(key, "A"); mhm.put(key, "B"); mhm.put(key, "C"); Collection coll = mhm.get(key);
coll
will be a list containing "A", "B", "C".
Inner classes inherited from class java.util.Map |
Map.Entry |
Constructor Summary | |
MultiHashMap()
Constructor. |
|
MultiHashMap(int initialCapacity)
Constructor. |
|
MultiHashMap(int initialCapacity,
float loadFactor)
Constructor. |
|
MultiHashMap(Map mapToCopy)
Constructor. |
Method Summary | |
void |
clear()
Clear the map. |
Object |
clone()
Clone the map. |
boolean |
containsValue(Object value)
Does the map contain a specific value. |
protected Collection |
createCollection(Collection coll)
Creates a new instance of the map value Collection container. |
Object |
put(Object key,
Object value)
Put a key and value into the map. |
Object |
remove(Object key,
Object item)
Removes a specific value from map. |
Collection |
values()
Gets a view over 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 java.util.Map |
containsKey, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, remove, size |
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 mappublic MultiHashMap(Map mapToCopy)
mapToCopy
- a Map to copyMethod Detail |
public Object put(Object key, Object value)
The value is added to a collection mapped to the key instead of replacing the previous value.
put
in interface Map
put
in class HashMap
key
- the key to setvalue
- the value to set the key tonull
otherwisepublic boolean containsValue(Object value)
This searches the collection mapped to each key, and thus could be slow.
containsValue
in interface Map
containsValue
in class HashMap
value
- the value to search forpublic Object remove(Object key, Object item)
The item is removed from the collection mapped to the specified key.
remove
in interface MultiMap
key
- the key to remove fromitem
- the value to removepublic void clear()
This clears each collection in the map, and so may be slow.
clear
in interface Map
clear
in class HashMap
public Collection values()
The values view includes all the entries in the collections at each map key.
values
in interface Map
values
in class HashMap
public Object clone()
The clone will shallow clone the collections as well as the map.
clone
in class HashMap
protected Collection createCollection(Collection coll)
This method can be overridden to use your own collection type.
coll
- the collection to copy, may be null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |