Class AbstractMultiValuedMapDecorator<K,V>
- java.lang.Object
-
- org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator<K,V>
-
- Type Parameters:
K- the type of key elementsV- the type of value elements
- All Implemented Interfaces:
java.io.Serializable,MultiValuedMap<K,V>
- Direct Known Subclasses:
TransformedMultiValuedMap,UnmodifiableMultiValuedMap
public abstract class AbstractMultiValuedMapDecorator<K,V> extends java.lang.Object implements MultiValuedMap<K,V>, java.io.Serializable
Decorates anotherMultiValuedMapto provide additional behaviour.Each method call made on this
MultiValuedMapis forwarded to the decoratedMultiValuedMap. This class is used as a framework to build to extensions such as synchronized and unmodifiable behaviour.- Since:
- 4.1
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<K,java.util.Collection<V>>asMap()Returns a view of this multi-valued map as aMapfrom each distinct key to the non-empty collection of that key's associated values.voidclear()Removes all of the mappings from this map (optional operation).booleancontainsKey(java.lang.Object key)Returnstrueif this map contains a mapping for the specified key.booleancontainsMapping(java.lang.Object key, java.lang.Object value)Checks whether the map contains a mapping for the specified key and value.booleancontainsValue(java.lang.Object value)Checks whether the map contains at least one mapping for the specified value.java.util.Collection<java.util.Map.Entry<K,V>>entries()Returns aCollectionview of the mappings contained in this multi-valued map.booleanequals(java.lang.Object object)java.util.Collection<V>get(K key)Returns a view collection of the values associated with the specified key.inthashCode()booleanisEmpty()Returnstrueif this map contains no key-value mappings.MultiSet<K>keys()Returns aMultiSetview of the keys contained in this multi-valued map.java.util.Set<K>keySet()Returns aSetview of the keys contained in this multi-valued map.MapIterator<K,V>mapIterator()Obtains aMapIteratorover this multi-valued map.booleanput(K key, V value)Adds a key-value mapping to this multi-valued map.booleanputAll(java.util.Map<? extends K,? extends V> map)Copies all mappings from the specified map to this multi-valued map (optional operation).booleanputAll(K key, java.lang.Iterable<? extends V> values)Adds a mapping to the specified key for all values contained in the given Iterable.booleanputAll(MultiValuedMap<? extends K,? extends V> map)Copies all mappings from the specified map to this multi-valued map (optional operation).java.util.Collection<V>remove(java.lang.Object key)Removes all values associated with the specified key.booleanremoveMapping(java.lang.Object key, java.lang.Object item)Removes a key-value mapping from the map.intsize()Gets the total size of the map.java.lang.StringtoString()java.util.Collection<V>values()Gets aCollectionview of all values contained in this multi-valued map.
-
-
-
Method Detail
-
size
public int size()
Description copied from interface:MultiValuedMapGets the total size of the map.Implementations would return the total size of the map which is the count of the values from all keys.
- Specified by:
sizein interfaceMultiValuedMap<K,V>- Returns:
- the total size of the map
-
isEmpty
public boolean isEmpty()
Description copied from interface:MultiValuedMapReturnstrueif this map contains no key-value mappings.- Specified by:
isEmptyin interfaceMultiValuedMap<K,V>- Returns:
trueif this map contains no key-value mappings
-
containsKey
public boolean containsKey(java.lang.Object key)
Description copied from interface:MultiValuedMapReturnstrueif this map contains a mapping for the specified key. More formally, returnstrueif and only if this map contains a mapping for a keyksuch that(key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)- Specified by:
containsKeyin interfaceMultiValuedMap<K,V>- Parameters:
key- key whose presence in this map is to be tested- Returns:
- true if this map contains a mapping for the specified key
-
containsValue
public boolean containsValue(java.lang.Object value)
Description copied from interface:MultiValuedMapChecks whether the map contains at least one mapping for the specified value.- Specified by:
containsValuein interfaceMultiValuedMap<K,V>- Parameters:
value- the value to search for- Returns:
- true if the map contains the value
-
containsMapping
public boolean containsMapping(java.lang.Object key, java.lang.Object value)Description copied from interface:MultiValuedMapChecks whether the map contains a mapping for the specified key and value.- Specified by:
containsMappingin interfaceMultiValuedMap<K,V>- Parameters:
key- the key to search forvalue- the value to search for- Returns:
- true if the map contains the value
-
get
public java.util.Collection<V> get(K key)
Description copied from interface:MultiValuedMapReturns a view collection of the values associated with the specified key.This method will return an empty collection if
MultiValuedMap.containsKey(Object)returnsfalse. Changes to the returned collection will update the underlyingMultiValuedMapand vice-versa.- Specified by:
getin interfaceMultiValuedMap<K,V>- Parameters:
key- the key to retrieve- Returns:
- the
Collectionof values, implementations should return an empty collection for no mapping
-
remove
public java.util.Collection<V> remove(java.lang.Object key)
Description copied from interface:MultiValuedMapRemoves all values associated with the specified key.The returned collection may be modifiable, but updates will not be propagated to this multi-valued map. In case no mapping was stored for the specified key, an empty, unmodifiable collection will be returned.
- Specified by:
removein interfaceMultiValuedMap<K,V>- Parameters:
key- the key to remove values from- Returns:
- the values that were removed
-
removeMapping
public boolean removeMapping(java.lang.Object key, java.lang.Object item)Description copied from interface:MultiValuedMapRemoves a key-value mapping from the 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 an empty collection from a subsequent
get(Object).- Specified by:
removeMappingin interfaceMultiValuedMap<K,V>- Parameters:
key- the key to remove fromitem- the item to remove- Returns:
- true if the mapping was removed, false otherwise
-
clear
public void clear()
Description copied from interface:MultiValuedMapRemoves all of the mappings from this map (optional operation).The map will be empty after this call returns.
- Specified by:
clearin interfaceMultiValuedMap<K,V>
-
put
public boolean put(K key, V value)
Description copied from interface:MultiValuedMapAdds a key-value mapping to this multi-valued map.Unlike a normal
Mapthe previous value is not replaced. Instead the new value is added to the collection stored against the key. Depending on the collection type used, duplicate key-value mappings may be allowed.The method will return
trueif the size of the multi-valued map has been increased because of this operation.- Specified by:
putin interfaceMultiValuedMap<K,V>- Parameters:
key- the key to store againstvalue- the value to add to the collection at the key- Returns:
- true if the map changed as a result of this put operation, or false if the map already contained the key-value mapping and the collection type does not allow duplicate values, e.g. when using a Set
-
keySet
public java.util.Set<K> keySet()
Description copied from interface:MultiValuedMapReturns aSetview of the keys contained in this multi-valued map.The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.
If the map is modified while an iteration over the set is in progress (except through the iterator's own
removeoperation), the result of the iteration is undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.- Specified by:
keySetin interfaceMultiValuedMap<K,V>- Returns:
- a set view of the keys contained in this map
-
entries
public java.util.Collection<java.util.Map.Entry<K,V>> entries()
Description copied from interface:MultiValuedMapReturns aCollectionview of the mappings contained in this multi-valued map.The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa.
- Specified by:
entriesin interfaceMultiValuedMap<K,V>- Returns:
- a set view of the mappings contained in this map
-
keys
public MultiSet<K> keys()
Description copied from interface:MultiValuedMapReturns aMultiSetview of the keys contained in this multi-valued map.The
MultiSet.getCount(Object)method of the returned multiset will give the same result a callingget(Object).size()for the same key.This multiset is backed by the map, so any changes in the map are reflected in the multiset.
- Specified by:
keysin interfaceMultiValuedMap<K,V>- Returns:
- a multiset view of the keys contained in this map
-
values
public java.util.Collection<V> values()
Description copied from interface:MultiValuedMapGets aCollectionview of all values contained in this multi-valued map.Implementations typically return a collection containing the combination of values from all keys.
- Specified by:
valuesin interfaceMultiValuedMap<K,V>- Returns:
- a collection view of the values contained in this multi-valued map
-
asMap
public java.util.Map<K,java.util.Collection<V>> asMap()
Description copied from interface:MultiValuedMapReturns a view of this multi-valued map as aMapfrom each distinct key to the non-empty collection of that key's associated values.Note that
this.asMap().get(k)is equivalent tothis.get(k)only whenkis a key contained in the multi-valued map; otherwise it returnsnullas opposed to an empty collection.Changes to the returned map or the collections that serve as its values will update the underlying multi-valued map, and vice versa. The map does not support
putorputAll, nor do its entries supportsetValue.- Specified by:
asMapin interfaceMultiValuedMap<K,V>- Returns:
- a map view of the mappings in this multi-valued map
-
putAll
public boolean putAll(K key, java.lang.Iterable<? extends V> values)
Description copied from interface:MultiValuedMapAdds a mapping to the specified key for all values contained in the given Iterable.- Specified by:
putAllin interfaceMultiValuedMap<K,V>- Parameters:
key- the key to store againstvalues- the values to add to the collection at the key, may not be null- Returns:
- true if the map changed as a result of this operation
-
putAll
public boolean putAll(java.util.Map<? extends K,? extends V> map)
Description copied from interface:MultiValuedMapCopies all mappings from the specified map to this multi-valued map (optional operation).The effect of this call is equivalent to that of calling
put(k, v)on this map once for each mapping from keykto valuevin the specified map.The behavior of this operation is undefined if the specified map is modified while the operation is in progress.
- Specified by:
putAllin interfaceMultiValuedMap<K,V>- Parameters:
map- mappings to be stored in this map, may not be null- Returns:
- true if the map changed as a result of this operation
-
putAll
public boolean putAll(MultiValuedMap<? extends K,? extends V> map)
Description copied from interface:MultiValuedMapCopies all mappings from the specified map to this multi-valued map (optional operation).The effect of this call is equivalent to that of calling
put(k, v)on this map once for each mapping from keykto valuevin the specified map.The behavior of this operation is undefined if the specified map is modified while the operation is in progress.
- Specified by:
putAllin interfaceMultiValuedMap<K,V>- Parameters:
map- mappings to be stored in this map, may not be null- Returns:
- true if the map changed as a result of this operation
-
mapIterator
public MapIterator<K,V> mapIterator()
Description copied from interface:MultiValuedMapObtains aMapIteratorover this multi-valued map.A map iterator is an efficient way of iterating over maps. There is no need to access the entries collection or use
Map.Entryobjects.- Specified by:
mapIteratorin interfaceMultiValuedMap<K,V>- Returns:
- a map iterator
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-