public interface MultiMap
extends java.util.Map
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.
For example:
MultiMap mhm = new MultiHashMap(); mhm.put(key, "A"); mhm.put(key, "B"); mhm.put(key, "C"); Collection coll = (Collection) mhm.get(key);
coll
will be a collection containing "A", "B", "C".
NOTE: Additional methods were added to this interface in Commons Collections 3.1.
These were added solely for documentation purposes and do not change the interface
as they were defined in the superinterface Map
anyway.
Modifier and Type | Method and Description |
---|---|
boolean |
containsValue(java.lang.Object value)
Checks whether the map contains the value specified.
|
java.lang.Object |
get(java.lang.Object key)
Gets the collection of values associated with 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.
|
java.lang.Object |
remove(java.lang.Object key)
Removes all values 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()
Gets the number of keys in this map.
|
java.util.Collection |
values()
Gets a collection containing all the values in the map.
|
java.lang.Object remove(java.lang.Object key, java.lang.Object item)
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, implementations typically
return null
from a subsequant get(Object)
, however
they may choose to return an empty collection.
remove
in interface java.util.Map
key
- the key to remove fromitem
- the item to removejava.lang.UnsupportedOperationException
- if the map is unmodifiablejava.lang.ClassCastException
- if the key or value is of an invalid typejava.lang.NullPointerException
- if the key or value is null and null is invalidint size()
Implementations typically return only the count of keys in the map This cannot be mandated due to backwards compatability of this interface.
size
in interface java.util.Map
java.lang.Object get(java.lang.Object key)
The returned value will implement Collection
. Implementations
are free to declare that they return Collection
subclasses
such as List
or Set
.
Implementations typically return null
if no values have
been mapped to the key, however the implementation may choose to
return an empty collection.
Implementations may choose to return a clone of the internal collection.
get
in interface java.util.Map
key
- the key to retrieveCollection
of values, implementations should
return null
for no mapping, but may return an empty collectionjava.lang.ClassCastException
- if the key is of an invalid typejava.lang.NullPointerException
- if the key is null and null keys are invalidboolean containsValue(java.lang.Object value)
Implementations typically check all collections against all keys for the value. This cannot be mandated due to backwards compatability of this interface.
containsValue
in interface java.util.Map
value
- the value to search forjava.lang.ClassCastException
- if the value is of an invalid typejava.lang.NullPointerException
- if the value is null and null value are invalidjava.lang.Object put(java.lang.Object key, java.lang.Object value)
Unlike a normal Map
the previous value is not replaced.
Instead the new value is added to the collection stored against the key.
The collection may be a List
, Set
or other
collection dependent on implementation.
put
in interface java.util.Map
key
- the key to store againstvalue
- the value to add to the collection at the keyjava.lang.UnsupportedOperationException
- if the map is unmodifiablejava.lang.ClassCastException
- if the key or value is of an invalid typejava.lang.NullPointerException
- if the key or value is null and null is invalidjava.lang.IllegalArgumentException
- if the key or value is invalidjava.lang.Object remove(java.lang.Object key)
Implementations typically return null
from a subsequant
get(Object)
, however they may choose to return an empty collection.
remove
in interface java.util.Map
key
- the key to remove values fromCollection
of values removed, implementations should
return null
for no mapping found, but may return an empty collectionjava.lang.UnsupportedOperationException
- if the map is unmodifiablejava.lang.ClassCastException
- if the key is of an invalid typejava.lang.NullPointerException
- if the key is null and null keys are invalidjava.util.Collection values()
Inplementations typically return a collection containing the combination of values from all keys. This cannot be mandated due to backwards compatability of this interface.
values
in interface java.util.Map
Copyright © 2010 - 2020 Adobe. All Rights Reserved