java.lang.Object | |||
↳ | java.util.AbstractMap<K, V> | ||
↳ | java.util.HashMap<K, V> | ||
↳ | org.apache.commons.collections.MultiHashMap |
This class is deprecated.
Class now available as MultiValueMap in map subpackage.
This version is due to be removed in collections v4.0.
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 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".
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor.
| |||||||||||
Constructor.
| |||||||||||
Constructor.
| |||||||||||
Constructor that copies the input map creating an independent copy.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Clear the map.
| |||||||||||
Clones the map creating an independent copy.
| |||||||||||
Checks whether the collection at the specified key contains the value.
| |||||||||||
Checks whether the map contains the value specified.
| |||||||||||
Gets the collection mapped to the specified key.
| |||||||||||
Gets an iterator for the collection mapped to the specified key.
| |||||||||||
Adds the value to the collection associated with the specified key.
| |||||||||||
Override superclass to ensure that MultiMap instances are
correctly handled.
| |||||||||||
Adds a collection of values to the collection associated with the specified key.
| |||||||||||
Removes a specific value from map.
| |||||||||||
Gets the size of the collection mapped to the specified key.
| |||||||||||
Gets the total size of the map by counting all the values.
| |||||||||||
Gets a collection containing all the values in the map.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new instance of the map value Collection container.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.HashMap
| |||||||||||
From class
java.util.AbstractMap
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.util.Map
| |||||||||||
From interface
org.apache.commons.collections.MultiMap
|
Constructor.
Constructor.
initialCapacity | the initial map capacity |
---|
Constructor.
initialCapacity | the initial map capacity |
---|---|
loadFactor | the amount 0.0-1.0 at which to resize the map |
Constructor that copies the input map creating an independent copy.
This method performs different behaviour depending on whether the map specified is a MultiMap or not. If a MultiMap is specified, each internal collection is also cloned. If the specified map only implements Map, then the values are not cloned.
NOTE: From Commons Collections 3.1 this method correctly copies a MultiMap to form a truly independent new map. NOTE: From Commons Collections 3.2 this method delegates to the newly added putAll(Map) override method.
mapToCopy | a Map to copy |
---|
Clear the map.
This clears each collection in the map, and so may be slow.
Clones the map creating an independent copy.
The clone will shallow clone the collections as well as the map.
Checks whether the collection at the specified key contains the value.
value | the value to search for |
---|
Checks whether the map contains the value specified.
This checks all collections against all keys for the value, and thus could be slow.
value | the value to search for |
---|
Gets the collection mapped to the specified key.
This method is a convenience method to typecast the result of get(key)
.
key | the key to retrieve |
---|
Gets an iterator for the collection mapped to the specified key.
key | the key to get an iterator for |
---|
Adds the value to the collection associated with the specified key.
Unlike a normal Map
the previous value is not replaced.
Instead the new value is added to the collection stored against the key.
key | the key to store against |
---|---|
value | the value to add to the collection at the key |
Override superclass to ensure that MultiMap instances are correctly handled.
NOTE: Prior to version 3.2, putAll(map) did not work properly when passed a MultiMap.
map | the map to copy (either a normal or multi map) |
---|
Adds a collection of values to the collection associated with the specified key.
key | the key to store against |
---|---|
values | the values to add to the collection at the key, null ignored |
Removes a specific value from map.
The item is removed from the collection mapped to the specified key. Other values attached to that key are unaffected.
If the last value for a key is removed, null
will be returned
from a subsequant get(key)
.
key | the key to remove from |
---|---|
item | the value to remove |
Gets the size of the collection mapped to the specified key.
key | the key to get size for |
---|
Gets the total size of the map by counting all the values.
Gets a collection containing all the values in the map.
This returns a collection containing the combination of values from all keys.
Creates a new instance of the map value Collection container.
This method can be overridden to use your own collection type.
coll | the collection to copy, may be null |
---|