Class AbstractMultiValuedMap<K,V> 
- Type Parameters:
- K- the type of the keys in this map
- V- the type of the values in this map
- All Implemented Interfaces:
- MultiValuedMap<K,- V> 
- Direct Known Subclasses:
- AbstractListValuedMap,- AbstractSetValuedMap
MultiValuedMap interface to simplify
 the creation of subclass implementations.
 Subclasses specify a Map implementation to use as the internal storage.
- Since:
- 4.1
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedConstructor needed for subclass serialization.protectedAbstractMultiValuedMap(Map<K, ? extends Collection<V>> map) Constructor that wraps (not copies).
- 
Method SummaryModifier and TypeMethodDescriptionMap<K, Collection<V>> asMap()Returns a view of this multivalued 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(Object key) Returnstrueif this map contains a mapping for the specified key.booleancontainsMapping(Object key, Object value) Checks whether the map contains a mapping for the specified key and value.booleancontainsValue(Object value) Checks whether the map contains at least one mapping for the specified value.protected abstract Collection<V> Creates a new Collection typed for a given subclass.protected voidReads the map in using a custom routine.protected voidWrites the map out using a custom routine.entries()Returns aCollectionview of the mappings contained in this multivalued map.booleanGets the collection of values associated with the specified key.protected Map<K, ? extends Collection<V>> getMap()Gets the map being wrapped.inthashCode()booleanisEmpty()Returnstrueif this map contains no key-value mappings.keys()Returns aMultiSetview of the key mapping contained in this map.keySet()Returns aSetview of the keys contained in this multivalued map.Obtains aMapIteratorover this multivalued map.booleanAdds the value to the collection associated with the specified key.booleanCopies all of the mappings from the specified map to this map.booleanAdds Iterable values to the collection associated with the specified key.booleanputAll(MultiValuedMap<? extends K, ? extends V> map) Copies all of the mappings from the specified MultiValuedMap to this map.Removes all values associated with the specified key.booleanremoveMapping(Object key, Object value) Removes a specific key/value mapping from the multivalued map.protected voidsetMap(Map<K, ? extends Collection<V>> map) Sets the map being wrapped.intsize()Gets the total size of the map.toString()values()Gets a collection containing all the values in the map.
- 
Constructor Details- 
AbstractMultiValuedMapprotected AbstractMultiValuedMap()Constructor needed for subclass serialization.
- 
AbstractMultiValuedMapConstructor that wraps (not copies).- Parameters:
- map- the map to wrap, must not be null
- Throws:
- NullPointerException- if the map is null
 
 
- 
- 
Method Details- 
asMapDescription copied from interface:MultiValuedMapReturns a view of this multivalued 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 multivalued 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 multivalued map, and vice versa. The map does not support putorputAll, nor do its entries supportsetValue.- Specified by:
- asMapin interface- MultiValuedMap<K,- V> 
- Returns:
- a map view of the mappings in this multivalued map
 
- 
clearDescription 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 interface- MultiValuedMap<K,- V> 
 
- 
containsKeyDescription 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 interface- MultiValuedMap<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
 
- 
containsMappingDescription copied from interface:MultiValuedMapChecks whether the map contains a mapping for the specified key and value.- Specified by:
- containsMappingin interface- MultiValuedMap<K,- V> 
- Parameters:
- key- the key to search for
- value- the value to search for
- Returns:
- true if the map contains the value
 
- 
containsValueDescription copied from interface:MultiValuedMapChecks whether the map contains at least one mapping for the specified value.- Specified by:
- containsValuein interface- MultiValuedMap<K,- V> 
- Parameters:
- value- the value to search for
- Returns:
- true if the map contains the value
 
- 
createCollectionCreates a new Collection typed for a given subclass.- Returns:
- a new Collection typed for a given subclass.
 
- 
doReadObjectReads the map in using a custom routine.- Parameters:
- in- the input stream
- Throws:
- IOException- any of the usual I/O related exceptions
- ClassNotFoundException- if the stream contains an object which class cannot be loaded
- ClassCastException- if the stream does not contain the correct objects
 
- 
doWriteObjectWrites the map out using a custom routine.- Parameters:
- out- the output stream
- Throws:
- IOException- any of the usual I/O related exceptions
 
- 
entriesDescription copied from interface:MultiValuedMapReturns aCollectionview of the mappings contained in this multivalued map.The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. - Specified by:
- entriesin interface- MultiValuedMap<K,- V> 
- Returns:
- a set view of the mappings contained in this map
 
- 
equals
- 
getGets the collection of values associated with the specified key. This would return an empty collection in case the mapping is not present- Specified by:
- getin interface- MultiValuedMap<K,- V> 
- Parameters:
- key- the key to retrieve
- Returns:
- the Collectionof values, will return an emptyCollectionfor no mapping
 
- 
getMapGets the map being wrapped.- Returns:
- the wrapped map
 
- 
hashCode
- 
isEmptyDescription copied from interface:MultiValuedMapReturnstrueif this map contains no key-value mappings.- Specified by:
- isEmptyin interface- MultiValuedMap<K,- V> 
- Returns:
- trueif this map contains no key-value mappings
 
- 
keysReturns aMultiSetview of the key mapping contained in this map.Returns a MultiSet of keys with its values count as the count of the MultiSet. This multiset is backed by the map, so any changes in the map is reflected here. Any method which modifies this multiset like add,remove,Iterator.remove()etc throwsUnsupportedOperationException.- Specified by:
- keysin interface- MultiValuedMap<K,- V> 
- Returns:
- a bag view of the key mapping contained in this map
 
- 
keySetDescription copied from interface:MultiValuedMapReturns aSetview of the keys contained in this multivalued 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 interface- MultiValuedMap<K,- V> 
- Returns:
- a set view of the keys contained in this map
 
- 
mapIteratorDescription copied from interface:MultiValuedMapObtains aMapIteratorover this multivalued 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 interface- MultiValuedMap<K,- V> 
- Returns:
- a map iterator
 
- 
putAdds 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.- Specified by:
- putin interface- MultiValuedMap<K,- V> 
- Parameters:
- key- the key to store against
- value- the value to add to the collection at the key
- Returns:
- the value added if the map changed and null if the map did not change
 
- 
putAllAdds Iterable values to the collection associated with the specified key.- Specified by:
- putAllin interface- MultiValuedMap<K,- V> 
- Parameters:
- key- the key to store against
- values- the values to add to the collection at the key, may not be null
- Returns:
- true if this map changed
- Throws:
- NullPointerException- if values is null
 
- 
putAllCopies all of the mappings from the specified map to this map. The effect of this call is equivalent to that of callingput(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 interface- MultiValuedMap<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
- Throws:
- NullPointerException- if map is null
 
- 
putAllCopies all of the mappings from the specified MultiValuedMap to this map. The effect of this call is equivalent to that of callingput(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 interface- MultiValuedMap<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
- Throws:
- NullPointerException- if map is null
 
- 
removeRemoves all values associated with the specified key.A subsequent get(Object)would return an empty collection.- Specified by:
- removein interface- MultiValuedMap<K,- V> 
- Parameters:
- key- the key to remove values from
- Returns:
- the Collectionof values removed, will return an empty, unmodifiable collection for no mapping found
 
- 
removeMappingRemoves a specific key/value mapping from the multivalued map.The value 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, an empty collection would be returned from a subsequent get(Object).- Specified by:
- removeMappingin interface- MultiValuedMap<K,- V> 
- Parameters:
- key- the key to remove from
- value- the value to remove
- Returns:
- true if the mapping was removed, false otherwise
 
- 
setMapSets the map being wrapped.NOTE: this method should only be used during deserialization - Parameters:
- map- the map to wrap
 
- 
sizeGets 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. This implementation does not cache the total size of the multivalued map, but rather calculates it by iterating over the entries of the underlying map. - Specified by:
- sizein interface- MultiValuedMap<K,- V> 
- Returns:
- the total size of the map
 
- 
toString
- 
valuesGets a collection containing all the values in the map.Returns a collection containing all the values from all keys. - Specified by:
- valuesin interface- MultiValuedMap<K,- V> 
- Returns:
- a collection view of the values contained in this map
 
 
-