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

public abstract Class AbstractMultiValuedMapDecorator<K, V>

extends Object
implements MultiValuedMap<K, V>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.collections4.MultiValuedMap
Known Direct Subclasses
org.apache.commons.collections4.multimap.TransformedMultiValuedMap, org.apache.commons.collections4.multimap.UnmodifiableMultiValuedMap
Type Parameters
<K>
the type of key elements
<V>
the type of value elements
Imports
java.io.Serializable, java.util.Collection, .Map, .Map.Entry, .Set, org.apache.commons.collections4.MapIterator, .MultiSet, .MultiValuedMap

Decorates another MultiValuedMap to provide additional behaviour.

Each method call made on this MultiValuedMap is forwarded to the decorated MultiValuedMap. This class is used as a framework to build to extensions such as synchronized and unmodifiable behaviour.

Since
4.1

Field Summary

Modifier and TypeField and Description
private final MultiValuedMap<K, V>
map

MultiValuedMap to decorate

private static final long
serialVersionUID

Serialization version

Constructor Summary

AccessConstructor and Description
protected
AbstractMultiValuedMapDecorator(final MultiValuedMap<K, V>
the map to decorate, must not be null
map
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public Map<K, Collection<V>>
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()

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

Removes all of the mappings from this map (optional operation).
public boolean
containsKey(final Object
key whose presence in this map is to be tested
key
)

Implements org.apache.commons.collections4.MultiValuedMap.containsKey.

Returns true if this map contains a mapping for the specified key.
public boolean
containsMapping(final Object
the key to search for
key
,
final Object
the value to search for
value
)

Implements org.apache.commons.collections4.MultiValuedMap.containsMapping.

Checks whether the map contains a mapping for the specified key and value.
public boolean
containsValue(final Object
the value to search for
value
)

Implements org.apache.commons.collections4.MultiValuedMap.containsValue.

Checks whether the map contains at least one mapping for the specified value.
protected MultiValuedMap<K, V>

Returns:

the map to decorate
decorated
()

The decorated multi-valued map.

public Collection<Map.Entry<K, V>>
entries()

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

Returns a Collection view of the mappings contained in this multi-valued map.
public boolean
equals(final Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Collection<V>
get(final K
the key to retrieve
key
)

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

Returns a view collection of the values associated with the specified key.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean
isEmpty()

Implements org.apache.commons.collections4.MultiValuedMap.isEmpty.

Returns true if this map contains no key-value mappings.
public MultiSet<K>
keys()

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

Returns a MultiSet view of the keys contained in this multi-valued map.
public Set<K>
keySet()

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

Returns a Set view of the keys contained in this multi-valued map.
public MapIterator<K, V>
mapIterator()

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

Obtains a MapIterator over this multi-valued map.
public boolean
put(final K
the key to store against
key
,
final V
the value to add to the collection at the key
value
)

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
)

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
)

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
)

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
)

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
)

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

Removes a key-value mapping from the map.
public int
size()

Implements org.apache.commons.collections4.MultiValuedMap.size.

Gets the total size of the map.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public Collection<V>
values()

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

Gets a Collection view of all values contained in this multi-valued map.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

mapback to summary
private final MultiValuedMap<K, V> map

MultiValuedMap to decorate

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version

Constructor Detail

AbstractMultiValuedMapDecoratorback to summary
protected AbstractMultiValuedMapDecorator(final MultiValuedMap<K, V> map)

Constructor that wraps (not copies).

Parameters
map:MultiValuedMap<K, V>

the map to decorate, must not be null

Exceptions
NullPointerException:
if the map is null

Method Detail

asMapback to summary
public Map<K, Collection<V>> 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()

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
containsKeyback to summary
public boolean containsKey(final Object key)

Implements org.apache.commons.collections4.MultiValuedMap.containsKey.

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

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that (key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)

Parameters
key:Object

key whose presence in this map is to be tested

Returns:boolean

true if this map contains a mapping for the specified key

Annotations
@Override
containsMappingback to summary
public boolean containsMapping(final Object key, final Object value)

Implements org.apache.commons.collections4.MultiValuedMap.containsMapping.

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

Checks whether the map contains a mapping for the specified key and value.

Parameters
key:Object

the key to search for

value:Object

the value to search for

Returns:boolean

true if the map contains the value

Annotations
@Override
containsValueback to summary
public boolean containsValue(final Object value)

Implements org.apache.commons.collections4.MultiValuedMap.containsValue.

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

Checks whether the map contains at least one mapping for the specified value.

Parameters
value:Object

the value to search for

Returns:boolean

true if the map contains the value

Annotations
@Override
decoratedback to summary
protected MultiValuedMap<K, V> decorated()

The decorated multi-valued map.

Returns:MultiValuedMap<K, V>

the map to decorate

entriesback to summary
public Collection<Map.Entry<K, V>> 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
equalsback to summary
public boolean equals(final Object object)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
object:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

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

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
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Implements org.apache.commons.collections4.MultiValuedMap.isEmpty.

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

Returns true if this map contains no key-value mappings.

Returns:boolean

true if this map contains no key-value mappings

Annotations
@Override
keysback to summary
public MultiSet<K> 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()

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()

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)

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)

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)

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)

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)

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)

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
sizeback to summary
public int size()

Implements org.apache.commons.collections4.MultiValuedMap.size.

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

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

Returns:int

the total size of the map

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
valuesback to summary
public Collection<V> 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