Top Description Fields Constructors Methods
org.apache.commons.collections4.multimap

public final Class UnmodifiableMultiValuedMap<K, V>

extends AbstractMultiValuedMapDecorator<K, V>
implements Unmodifiable
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.Unmodifiable
Type Parameters
<K>
the type of key elements
<V>
the type of value elements
Imports
java.util.Collection, .Map, .Map.Entry, .Set, org.apache.commons.collections4.MapIterator, .MultiSet, .MultiValuedMap, .Unmodifiable, org.apache.commons.collections4.collection.UnmodifiableCollection, org.apache.commons.collections4.iterators.UnmodifiableMapIterator, org.apache.commons.collections4.map.UnmodifiableMap, org.apache.commons.collections4.multiset.UnmodifiableMultiSet, org.apache.commons.collections4.set.UnmodifiableSet

Decorates another MultiValuedMap to ensure it can't be altered.

Attempts to modify it will result in an UnsupportedOperationException.

Since
4.1

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
private
UnmodifiableMultiValuedMap(final MultiValuedMap<? extends K, ? extends V>
the MultiValuedMap to decorate, may not be null
map
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public Map<K, Collection<V>>
asMap()

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.asMap.

Implements org.apache.commons.collections4.MultiValuedMap.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.
public void
clear()

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.clear.

Implements org.apache.commons.collections4.MultiValuedMap.clear.

Removes all of the mappings from this map (optional operation).
public Collection<Map.Entry<K, V>>
public Collection<V>
get(final K
the key to retrieve
key
)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.get.

Implements org.apache.commons.collections4.MultiValuedMap.get.

Returns a view collection of the values associated with the specified key.
public MultiSet<K>
public Set<K>
public MapIterator<K, V>
public boolean
put(final K
the key to store against
key
,
final V
the value to add to the collection at the key
value
)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.put.

Implements org.apache.commons.collections4.MultiValuedMap.put.

Adds a key-value mapping to this multi-valued map.
public boolean
putAll(final K
the key to store against
key
,
final Iterable<? extends V>
the values to add to the collection at the key, may not be null
values
)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.putAll.

Implements org.apache.commons.collections4.MultiValuedMap.putAll.

Adds a mapping to the specified key for all values contained in the given Iterable.
public boolean
putAll(final Map<? extends K, ? extends V>
mappings to be stored in this map, may not be null
map
)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.putAll.

Implements org.apache.commons.collections4.MultiValuedMap.putAll.

Copies all mappings from the specified map to this multi-valued map (optional operation).
public boolean
putAll(final MultiValuedMap<? extends K, ? extends V>
mappings to be stored in this map, may not be null
map
)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.putAll.

Implements org.apache.commons.collections4.MultiValuedMap.putAll.

Copies all mappings from the specified map to this multi-valued map (optional operation).
public Collection<V>
remove(final Object
the key to remove values from
key
)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.remove.

Implements org.apache.commons.collections4.MultiValuedMap.remove.

Removes all values associated with the specified key.
public boolean
removeMapping(final Object
the key to remove from
key
,
final Object
the item to remove
item
)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.removeMapping.

Implements org.apache.commons.collections4.MultiValuedMap.removeMapping.

Removes a key-value mapping from the map.
public static <
the type of key elements
K
,
the type of value elements
V
>
UnmodifiableMultiValuedMap<K, V>

Returns:

an unmodifiable MultiValuedMap
unmodifiableMultiValuedMap
(final MultiValuedMap<? extends K, ? extends V>
the map to decorate, may not be null
map
)

Factory method to create an unmodifiable MultiValuedMap.

public Collection<V>
Inherited from org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator:
containsKeycontainsMappingcontainsValuedecoratedequalshashCodeisEmptysizetoString

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.serialVersionUID.

Serialization version

Constructor Detail

UnmodifiableMultiValuedMapback to summary
private UnmodifiableMultiValuedMap(final MultiValuedMap<? extends K, ? extends V> map)

Constructor that wraps (not copies).

Parameters
map:MultiValuedMap<? extends K, ? extends V>

the MultiValuedMap to decorate, may not be null

Annotations
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if the map is null

Method Detail

asMapback to summary
public Map<K, Collection<V>> asMap()

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.asMap.

Implements org.apache.commons.collections4.MultiValuedMap.asMap.

Doc from org.apache.commons.collections4.MultiValuedMap.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.

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.

Returns:Map<K, Collection<V>>

a map view of the mappings in this multi-valued map

Annotations
@Override
clearback to summary
public void clear()

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.clear.

Implements org.apache.commons.collections4.MultiValuedMap.clear.

Doc from org.apache.commons.collections4.MultiValuedMap.clear.

Removes all of the mappings from this map (optional operation).

The map will be empty after this call returns.

Annotations
@Override
entriesback to summary
public Collection<Map.Entry<K, V>> entries()

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.entries.

Implements org.apache.commons.collections4.MultiValuedMap.entries.

Doc from org.apache.commons.collections4.MultiValuedMap.entries.

Returns a 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.

Returns:Collection<Map.Entry<K, V>>

a set view of the mappings contained in this map

Annotations
@Override
getback to summary
public Collection<V> get(final K key)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.get.

Implements org.apache.commons.collections4.MultiValuedMap.get.

Doc from org.apache.commons.collections4.MultiValuedMap.get.

Returns a view collection of the values associated with the specified key.

This method will return an empty collection if containsKey(Object) returns false. Changes to the returned collection will update the underlying MultiValuedMap and vice-versa.

Parameters
key:K

the key to retrieve

Returns:Collection<V>

the Collection of values, implementations should return an empty collection for no mapping

Annotations
@Override
keysback to summary
public MultiSet<K> keys()

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.keys.

Implements org.apache.commons.collections4.MultiValuedMap.keys.

Doc from org.apache.commons.collections4.MultiValuedMap.keys.

Returns a 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.

Returns:MultiSet<K>

a multiset view of the keys contained in this map

Annotations
@Override
keySetback to summary
public Set<K> keySet()

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.keySet.

Implements org.apache.commons.collections4.MultiValuedMap.keySet.

Doc from org.apache.commons.collections4.MultiValuedMap.keySet.

Returns a 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.

Returns:Set<K>

a set view of the keys contained in this map

Annotations
@Override
mapIteratorback to summary
public MapIterator<K, V> mapIterator()

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.mapIterator.

Implements org.apache.commons.collections4.MultiValuedMap.mapIterator.

Doc from org.apache.commons.collections4.MultiValuedMap.mapIterator.

Obtains a 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.

Returns:MapIterator<K, V>

a map iterator

Annotations
@Override
putback to summary
public boolean put(final K key, final V value)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.put.

Implements org.apache.commons.collections4.MultiValuedMap.put.

Doc from org.apache.commons.collections4.MultiValuedMap.put.

Adds a key-value mapping to this multi-valued map.

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.

Parameters
key:K

the key to store against

value:V

the value to add to the collection at the key

Returns:boolean

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

Annotations
@Override
putAllback to summary
public boolean putAll(final K key, final Iterable<? extends V> values)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.putAll.

Implements org.apache.commons.collections4.MultiValuedMap.putAll.

Doc from org.apache.commons.collections4.MultiValuedMap.putAll.

Adds a mapping to the specified key for all values contained in the given Iterable.

Parameters
key:K

the key to store against

values:Iterable<? extends V>

the values to add to the collection at the key, may not be null

Returns:boolean

true if the map changed as a result of this operation

Annotations
@Override
putAllback to summary
public boolean putAll(final Map<? extends K, ? extends V> map)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.putAll.

Implements org.apache.commons.collections4.MultiValuedMap.putAll.

Doc from org.apache.commons.collections4.MultiValuedMap.putAll.

Copies 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 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.

Parameters
map:Map<? extends K, ? extends V>

mappings to be stored in this map, may not be null

Returns:boolean

true if the map changed as a result of this operation

Annotations
@Override
putAllback to summary
public boolean putAll(final MultiValuedMap<? extends K, ? extends V> map)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.putAll.

Implements org.apache.commons.collections4.MultiValuedMap.putAll.

Doc from org.apache.commons.collections4.MultiValuedMap.putAll.

Copies 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 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.

Parameters
map:MultiValuedMap<? extends K, ? extends V>

mappings to be stored in this map, may not be null

Returns:boolean

true if the map changed as a result of this operation

Annotations
@Override
removeback to summary
public Collection<V> remove(final Object key)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.remove.

Implements org.apache.commons.collections4.MultiValuedMap.remove.

Doc from org.apache.commons.collections4.MultiValuedMap.remove.

Removes 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.

Parameters
key:Object

the key to remove values from

Returns:Collection<V>

the values that were removed

Annotations
@Override
removeMappingback to summary
public boolean removeMapping(final Object key, final Object item)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.removeMapping.

Implements org.apache.commons.collections4.MultiValuedMap.removeMapping.

Doc from org.apache.commons.collections4.MultiValuedMap.removeMapping.

Removes 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).

Parameters
key:Object

the key to remove from

item:Object

the item to remove

Returns:boolean

true if the mapping was removed, false otherwise

Annotations
@Override
unmodifiableMultiValuedMapback to summary
public static <K, V> UnmodifiableMultiValuedMap<K, V> unmodifiableMultiValuedMap(final MultiValuedMap<? extends K, ? extends V> map)

Factory method to create an unmodifiable MultiValuedMap.

If the map passed in is already unmodifiable, it is returned.

Parameters
<K>
the type of key elements
<V>
the type of value elements
map:MultiValuedMap<? extends K, ? extends V>

the map to decorate, may not be null

Returns:UnmodifiableMultiValuedMap<K, V>

an unmodifiable MultiValuedMap

Annotations
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if map is null
valuesback to summary
public Collection<V> values()

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator.values.

Implements org.apache.commons.collections4.MultiValuedMap.values.

Doc from org.apache.commons.collections4.MultiValuedMap.values.

Gets a Collection view of all values contained in this multi-valued map.

Implementations typically return a collection containing the combination of values from all keys.

Returns:Collection<V>

a collection view of the values contained in this multi-valued map

Annotations
@Override