java.lang.Object | ||
↳ | org.apache.commons.collections.map.AbstractMapDecorator | |
↳ | org.apache.commons.collections.map.MultiValueMap |
A MultiValueMap decorates another map, allowing it to have more than one value for a key.
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 is a decorator, allowing any Map implementation to be used as the base.
In addition, this implementation allows the type of collection used
for the values to be controlled. By default, an ArrayList
is used, however a Class
to instantiate may be specified,
or a factory that returns a Collection
instance.
Note that MultiValueMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. This class may throw exceptions when accessed by concurrent threads without synchronization.
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.commons.collections.map.AbstractMapDecorator
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a MultiValueMap based on a
HashMap and
storing the multiple values in an ArrayList . |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a MultiValueMap which decorates the given
map and
creates the value collections using the supplied collectionFactory . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Clear the map.
| |||||||||||
Checks whether the collection at the specified key contains the value.
| |||||||||||
Checks whether the map contains the value specified.
| |||||||||||
Creates a map which decorates the given
map and
maps keys to collections of type collectionClass . | |||||||||||
Creates a map which decorates the given
map and
creates the value collections using the supplied collectionFactory . | |||||||||||
Creates a map which wraps the given map and
maps keys to ArrayLists.
| |||||||||||
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
using the factory.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.commons.collections.map.AbstractMapDecorator
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.util.Map
| |||||||||||
From interface
org.apache.commons.collections.MultiMap
|
Creates a MultiValueMap based on a HashMap
and
storing the multiple values in an ArrayList
.
Creates a MultiValueMap which decorates the given map
and
creates the value collections using the supplied collectionFactory
.
map | the map to decorate |
---|---|
collectionFactory | the collection factory which must return a Collection instance |
Clear 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 |
---|
Creates a map which decorates the given map
and
maps keys to collections of type collectionClass
.
map | the map to wrap |
---|---|
collectionClass | the type of the collection class |
Creates a map which decorates the given map
and
creates the value collections using the supplied collectionFactory
.
map | the map to decorate |
---|---|
collectionFactory | the collection factory (must return a Collection object). |
Creates a map which wraps the given map and maps keys to ArrayLists.
map | the map to wrap |
---|
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.
If you call this method with a normal map, each entry is
added using put(Object,Object)
.
If you call this method with a multi map, each entry is
added using putAll(Object,Collection)
.
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 |
---|---|
value | 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 using the factory.
This method can be overridden to perform your own processing instead of using the factory.
size | the collection size that is about to be added |
---|