Interface MultiMap<K,V> 
- Type Parameters:
- K- the type of the keys in this map
- V- the type of the values in this map
- All Superinterfaces:
- Get<K,,- Object> - IterableGet<K,,- Object> - IterableMap<K,,- Object> - Map<K,,- Object> - Put<K,- Object> 
- All Known Implementing Classes:
- MultiValueMap
 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.
 
- Since:
- 2.0
- 
Nested Class Summary
- 
Method SummaryModifier and TypeMethodDescriptionbooleancontainsValue(Object value) Deprecated.Checks whether the map contains the value specified.Deprecated.Gets the collection of values associated with the specified key.Deprecated.Adds the value to the collection associated with the specified key.Deprecated.Removes all values associated with the specified key.booleanremoveMapping(K key, V item) Deprecated.Removes a specific value from map.intsize()Deprecated.Gets the number of keys in this map.values()Deprecated.Gets a collection containing all the values in the map.Methods inherited from interface org.apache.commons.collections4.GetcontainsKey, entrySet, isEmpty, keySetMethods inherited from interface org.apache.commons.collections4.IterableGetmapIteratorMethods inherited from interface java.util.Mapclear, compute, computeIfAbsent, computeIfPresent, containsKey, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll
- 
Method Details- 
containsValueDeprecated.Checks whether the map contains the value specified.Implementations typically check all collections against all keys for the value. This cannot be mandated due to backwards compatibility of this interface. - Specified by:
- containsValuein interface- Get<K,- V> 
- Specified by:
- containsValuein interface- Map<K,- V> 
- Parameters:
- value- the value to search for
- Returns:
- true if the map contains the value
- Throws:
- ClassCastException- if the value is of an invalid type
- NullPointerException- if the value is null and null value are invalid
- See Also:
 
- 
getDeprecated.Gets the collection of values associated with the specified key.The returned value will implement Collection. Implementations are free to declare that they returnCollectionsubclasses such asListorSet.Implementations typically return nullif 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. - Specified by:
- getin interface- Get<K,- V> 
- Specified by:
- getin interface- Map<K,- V> 
- Parameters:
- key- the key to retrieve
- Returns:
- the Collectionof values, implementations should returnnullfor no mapping, but may return an empty collection
- Throws:
- ClassCastException- if the key is of an invalid type
- NullPointerException- if the key is null and null keys are invalid
- See Also:
 
- 
putDeprecated.Adds the value to the collection associated with the specified key.Unlike a normal Mapthe previous value is not replaced. Instead, the new value is added to the collection stored against the key. The collection may be aList,Setor other collection dependent on implementation.- Specified by:
- putin interface- Map<K,- V> 
- Specified by:
- putin interface- Put<K,- V> 
- Parameters:
- key- the key to store against
- value- the value to add to the collection at the key
- Returns:
- typically the value added if the map changed and null if the map did not change
- Throws:
- UnsupportedOperationException- if the map is unmodifiable
- ClassCastException- if the key or value is of an invalid type
- NullPointerException- if the key or value is null and null is invalid
- IllegalArgumentException- if the key or value is invalid
- See Also:
 
- 
removeDeprecated.Removes all values associated with the specified key.Implementations typically return nullfrom a subsequentget(Object), however they may choose to return an empty collection.- Specified by:
- removein interface- Get<K,- V> 
- Specified by:
- removein interface- Map<K,- V> 
- Parameters:
- key- the key to remove values from
- Returns:
- the Collectionof values removed, implementations should returnnullfor no mapping found, but may return an empty collection
- Throws:
- UnsupportedOperationException- if the map is unmodifiable
- ClassCastException- if the key is of an invalid type
- NullPointerException- if the key is null and null keys are invalid
- See Also:
 
- 
removeMappingDeprecated.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, implementations typically return nullfrom a subsequentget(Object), however they may choose to return an empty collection.- Parameters:
- key- the key to remove from
- item- the item to remove
- Returns:
- trueif the mapping was removed,- falseotherwise
- Throws:
- UnsupportedOperationException- if the map is unmodifiable
- ClassCastException- if the key or value is of an invalid type
- NullPointerException- if the key or value is null and null is invalid
- Since:
- 4.0 (signature in previous releases: V remove(K, V))
 
- 
sizeint size()Deprecated.Gets the number of keys in this map.Implementations typically return only the count of keys in the map This cannot be mandated due to backwards compatibility of this interface. 
- 
valuesDeprecated.Gets a collection containing all the values in the map.Implementations typically return a collection containing the combination of values from all keys. This cannot be mandated due to backwards compatibility of this interface. 
 
- 
MultiValuedMapinstead