K
- the type of the keys in this mapV
- the type of the values in this mapMultiValuedMap
instead@Deprecated public interface MultiMap<K,V> extends IterableMap<K,Object>
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 MultiValueMap(); 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(Object value)
Deprecated.
Checks whether the map contains the value specified.
|
Object |
get(Object key)
Deprecated.
Gets the collection of values associated with the specified key.
|
Object |
put(K key,
Object value)
Deprecated.
Adds the value to the collection associated with the specified key.
|
Object |
remove(Object key)
Deprecated.
Removes all values associated with the specified key.
|
boolean |
removeMapping(K key,
V item)
Deprecated.
Removes a specific value from map.
|
int |
size()
Deprecated.
Gets the number of keys in this map.
|
Collection<Object> |
values()
Deprecated.
Gets a collection containing all the values in the map.
|
clear, compute, computeIfAbsent, computeIfPresent, containsKey, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll
mapIterator
containsKey, entrySet, isEmpty, keySet
boolean removeMapping(K key, V 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 subsequent get(Object)
, however
they may choose to return an empty collection.
key
- the key to remove fromitem
- the item to removetrue
if the mapping was removed, false
otherwiseUnsupportedOperationException
- if the map is unmodifiableClassCastException
- if the key or value is of an invalid typeNullPointerException
- 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 compatibility of this interface.
Object get(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 Get<K,Object>
get
in interface Map<K,Object>
key
- the key to retrieveCollection
of values, implementations should
return null
for no mapping, but may return an empty collectionClassCastException
- if the key is of an invalid typeNullPointerException
- if the key is null and null keys are invalidMap.get(Object)
boolean containsValue(Object value)
Implementations typically check all collections against all keys for the value. This cannot be mandated due to backwards compatibility of this interface.
containsValue
in interface Get<K,Object>
containsValue
in interface Map<K,Object>
value
- the value to search forClassCastException
- if the value is of an invalid typeNullPointerException
- if the value is null and null value are invalidMap.containsValue(Object)
Object put(K key, 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 Map<K,Object>
put
in interface Put<K,Object>
key
- the key to store againstvalue
- the value to add to the collection at the keyUnsupportedOperationException
- if the map is unmodifiableClassCastException
- if the key or value is of an invalid typeNullPointerException
- if the key or value is null and null is invalidIllegalArgumentException
- if the key or value is invalidMap.put(Object, Object)
Object remove(Object key)
Implementations typically return null
from a subsequent
get(Object)
, however they may choose to return an empty collection.
remove
in interface Get<K,Object>
remove
in interface Map<K,Object>
key
- the key to remove values fromCollection
of values removed, implementations should
return null
for no mapping found, but may return an empty collectionUnsupportedOperationException
- if the map is unmodifiableClassCastException
- if the key is of an invalid typeNullPointerException
- if the key is null and null keys are invalidMap.remove(Object)
Collection<Object> values()
Implementations typically return a collection containing the combination of values from all keys. This cannot be mandated due to backwards compatibility of this interface.
Copyright © 2001–2019 The Apache Software Foundation. All rights reserved.