K
- the type of key elementsV
- the type of value elementspublic final class UnmodifiableMultiValuedMap<K,V> extends AbstractMultiValuedMapDecorator<K,V> implements Unmodifiable
MultiValuedMap
to ensure it can't be altered.
Attempts to modify it will result in an UnsupportedOperationException.
Modifier and Type | Method and Description |
---|---|
Map<K,Collection<V>> |
asMap()
Returns a view of this multi-valued map as a
Map from each distinct
key to the non-empty collection of that key's associated values. |
void |
clear()
Removes all of the mappings from this map (optional operation).
|
Collection<Map.Entry<K,V>> |
entries()
Returns a
Collection view of the mappings contained in this multi-valued map. |
Collection<V> |
get(K key)
Returns a view collection of the values associated with the specified key.
|
MultiSet<K> |
keys()
Returns a
MultiSet view of the keys contained in this multi-valued map. |
Set<K> |
keySet()
Returns a
Set view of the keys contained in this multi-valued map. |
MapIterator<K,V> |
mapIterator()
Obtains a
MapIterator over this multi-valued map. |
boolean |
put(K key,
V value)
Adds a key-value mapping to this multi-valued map.
|
boolean |
putAll(K key,
Iterable<? extends V> values)
Adds a mapping to the specified key for all values contained in the given Iterable.
|
boolean |
putAll(Map<? extends K,? extends V> map)
Copies all mappings from the specified map to this multi-valued map
(optional operation).
|
boolean |
putAll(MultiValuedMap<? extends K,? extends V> map)
Copies all mappings from the specified map to this multi-valued map
(optional operation).
|
Collection<V> |
remove(Object key)
Removes all values associated with the specified key.
|
boolean |
removeMapping(Object key,
Object item)
Removes a key-value mapping from the map.
|
static <K,V> UnmodifiableMultiValuedMap<K,V> |
unmodifiableMultiValuedMap(MultiValuedMap<? extends K,? extends V> map)
Factory method to create an unmodifiable MultiValuedMap.
|
Collection<V> |
values()
Gets a
Collection view of all values contained in this multi-valued map. |
containsKey, containsMapping, containsValue, decorated, equals, hashCode, isEmpty, size, toString
public static <K,V> UnmodifiableMultiValuedMap<K,V> unmodifiableMultiValuedMap(MultiValuedMap<? extends K,? extends V> map)
If the map passed in is already unmodifiable, it is returned.
K
- the type of key elementsV
- the type of value elementsmap
- the map to decorate, may not be nullNullPointerException
- if map is nullpublic Collection<V> remove(Object key)
MultiValuedMap
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.
remove
in interface MultiValuedMap<K,V>
remove
in class AbstractMultiValuedMapDecorator<K,V>
key
- the key to remove values frompublic boolean removeMapping(Object key, Object item)
MultiValuedMap
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)
.
removeMapping
in interface MultiValuedMap<K,V>
removeMapping
in class AbstractMultiValuedMapDecorator<K,V>
key
- the key to remove fromitem
- the item to removepublic void clear()
MultiValuedMap
The map will be empty after this call returns.
clear
in interface MultiValuedMap<K,V>
clear
in class AbstractMultiValuedMapDecorator<K,V>
public Collection<V> get(K key)
MultiValuedMap
This method will return an empty collection if MultiValuedMap.containsKey(Object)
returns false
. Changes to the returned collection will update the underlying
MultiValuedMap
and vice-versa.
get
in interface MultiValuedMap<K,V>
get
in class AbstractMultiValuedMapDecorator<K,V>
key
- the key to retrieveCollection
of values, implementations should
return an empty collection for no mappingpublic boolean put(K key, V value)
MultiValuedMap
Unlike a normal Map
the 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 true
if the size of the multi-valued map
has been increased because of this operation.
put
in interface MultiValuedMap<K,V>
put
in class AbstractMultiValuedMapDecorator<K,V>
key
- the key to store againstvalue
- the value to add to the collection at the keypublic Set<K> keySet()
MultiValuedMap
Set
view 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 remove
operation),
the result of the iteration is undefined. The set supports element
removal, which removes the corresponding mapping from the map, via the
Iterator.remove
, Set.remove
, removeAll
,
retainAll
, and clear
operations. It does not support
the add
or addAll
operations.
keySet
in interface MultiValuedMap<K,V>
keySet
in class AbstractMultiValuedMapDecorator<K,V>
public Collection<Map.Entry<K,V>> entries()
MultiValuedMap
Collection
view 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.
entries
in interface MultiValuedMap<K,V>
entries
in class AbstractMultiValuedMapDecorator<K,V>
public MultiSet<K> keys()
MultiValuedMap
MultiSet
view of the keys contained in this multi-valued map.
The MultiSet.getCount(Object)
method of the returned multiset will give
the same result a calling get(Object).size()
for the same key.
This multiset is backed by the map, so any changes in the map are reflected in the multiset.
keys
in interface MultiValuedMap<K,V>
keys
in class AbstractMultiValuedMapDecorator<K,V>
public Collection<V> values()
MultiValuedMap
Collection
view of all values contained in this multi-valued map.
Implementations typically return a collection containing the combination of values from all keys.
values
in interface MultiValuedMap<K,V>
values
in class AbstractMultiValuedMapDecorator<K,V>
public Map<K,Collection<V>> asMap()
MultiValuedMap
Map
from each distinct
key to the non-empty collection of that key's associated values.
Note that this.asMap().get(k)
is equivalent to this.get(k)
only when k
is a key contained in the multi-valued map; otherwise it
returns null
as 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 put
or putAll
, nor do its entries support
setValue
.
asMap
in interface MultiValuedMap<K,V>
asMap
in class AbstractMultiValuedMapDecorator<K,V>
public MapIterator<K,V> mapIterator()
MultiValuedMap
MapIterator
over 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.Entry
objects.
mapIterator
in interface MultiValuedMap<K,V>
mapIterator
in class AbstractMultiValuedMapDecorator<K,V>
public boolean putAll(K key, Iterable<? extends V> values)
MultiValuedMap
putAll
in interface MultiValuedMap<K,V>
putAll
in class AbstractMultiValuedMapDecorator<K,V>
key
- the key to store againstvalues
- the values to add to the collection at the key, may not be nullpublic boolean putAll(Map<? extends K,? extends V> map)
MultiValuedMap
The effect of this call is equivalent to that of calling
put(k, v)
on this map once for each mapping
from key k
to value v
in the specified map.
The behavior of this operation is undefined if the specified map is modified while the operation is in progress.
putAll
in interface MultiValuedMap<K,V>
putAll
in class AbstractMultiValuedMapDecorator<K,V>
map
- mappings to be stored in this map, may not be nullpublic boolean putAll(MultiValuedMap<? extends K,? extends V> map)
MultiValuedMap
The effect of this call is equivalent to that of calling
put(k, v)
on this map once for each
mapping from key k
to value v
in the specified map.
The behavior of this operation is undefined if the specified map is modified while the operation is in progress.
putAll
in interface MultiValuedMap<K,V>
putAll
in class AbstractMultiValuedMapDecorator<K,V>
map
- mappings to be stored in this map, may not be nullCopyright © 2001–2019 The Apache Software Foundation. All rights reserved.