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

public Class TransformedMultiValuedMap<K, V>

extends AbstractMultiValuedMapDecorator<K, V>
Class Inheritance
Type Parameters
<K>
the type of the keys in this map
<V>
the type of the values in this map
Imports
java.util.Iterator, .Map, org.apache.commons.collections4.CollectionUtils, .FluentIterable, .MultiValuedMap, .Transformer

Decorates another MultiValuedMap to transform objects that are added.

This class affects the MultiValuedMap put methods. Thus objects must be removed or searched for using their transformed form. For example, if the transformation converts Strings to Integers, you must use the Integer form to remove objects.

Note that TransformedMultiValuedMap is not synchronized and is not thread-safe.

Since
4.1

Field Summary

Modifier and TypeField and Description
private final Transformer<? super K, ? extends K>
keyTransformer

The key transformer

private static final long
private final Transformer<? super V, ? extends V>
valueTransformer

The value transformer

Constructor Summary

AccessConstructor and Description
protected
TransformedMultiValuedMap(final MultiValuedMap<K, V>
the MultiValuedMap to decorate, may not be null
map
,
final Transformer<? super K, ? extends K>
the transformer to use for key conversion, null means no conversion
keyTransformer
,
final Transformer<? super V, ? extends V>
the transformer to use for value conversion, null means no conversion
valueTransformer
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
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 static <
the key type
K
,
the value type
V
>
TransformedMultiValuedMap<K, V>

Returns:

a new transformed MultiValuedMap
transformedMap
(final MultiValuedMap<K, V>
the MultiValuedMap to decorate, may not be null
map
,
final Transformer<? super K, ? extends K>
the transformer to use for key conversion, null means no conversion
keyTransformer
,
final Transformer<? super V, ? extends V>
the transformer to use for value conversion, null means no conversion
valueTransformer
)

Factory method to create a transforming MultiValuedMap that will transform existing contents of the specified map.

public static <
the key type
K
,
the value type
V
>
TransformedMultiValuedMap<K, V>

Returns:

a new transformed MultiValuedMap
transformingMap
(final MultiValuedMap<K, V>
the MultiValuedMap to decorate, may not be null
map
,
final Transformer<? super K, ? extends K>
the transformer to use for key conversion, null means no conversion
keyTransformer
,
final Transformer<? super V, ? extends V>
the transformer to use for value conversion, null means no conversion
valueTransformer
)

Factory method to create a transforming MultiValuedMap.

protected K

Returns:

the transformed object
transformKey
(final K
the object to transform
object
)

Transforms a key.

protected V

Returns:

the transformed object
transformValue
(final V
the object to transform
object
)

Transforms a value.

Inherited from org.apache.commons.collections4.multimap.AbstractMultiValuedMapDecorator:
asMapclearcontainsKeycontainsMappingcontainsValuedecoratedentriesequalsgethashCodeisEmptykeyskeySetmapIteratorremoveremoveMappingsizetoStringvalues

Field Detail

keyTransformerback to summary
private final Transformer<? super K, ? extends K> keyTransformer

The key transformer

serialVersionUIDback to summary
private static final long serialVersionUID

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

Serialization Version

valueTransformerback to summary
private final Transformer<? super V, ? extends V> valueTransformer

The value transformer

Constructor Detail

TransformedMultiValuedMapback to summary
protected TransformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer)

Constructor that wraps (not copies).

If there are any elements already in the collection being decorated, they are NOT transformed.

Parameters
map:MultiValuedMap<K, V>

the MultiValuedMap to decorate, may not be null

keyTransformer:Transformer<? super K, ? extends K>

the transformer to use for key conversion, null means no conversion

valueTransformer:Transformer<? super V, ? extends V>

the transformer to use for value conversion, null means no conversion

Exceptions
NullPointerException:
if map is null

Method Detail

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
transformedMapback to summary
public static <K, V> TransformedMultiValuedMap<K, V> transformedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer)

Factory method to create a transforming MultiValuedMap that will transform existing contents of the specified map.

If there are any elements already in the map being decorated, they will be transformed by this method. Contrast this with transformingMap(MultiValuedMap, Transformer, Transformer).

Parameters
<K>
the key type
<V>
the value type
map:MultiValuedMap<K, V>

the MultiValuedMap to decorate, may not be null

keyTransformer:Transformer<? super K, ? extends K>

the transformer to use for key conversion, null means no conversion

valueTransformer:Transformer<? super V, ? extends V>

the transformer to use for value conversion, null means no conversion

Returns:TransformedMultiValuedMap<K, V>

a new transformed MultiValuedMap

Exceptions
NullPointerException:
if map is null
transformingMapback to summary
public static <K, V> TransformedMultiValuedMap<K, V> transformingMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer)

Factory method to create a transforming MultiValuedMap.

If there are any elements already in the map being decorated, they are NOT transformed. Contrast this with transformedMap(MultiValuedMap, Transformer, Transformer).

Parameters
<K>
the key type
<V>
the value type
map:MultiValuedMap<K, V>

the MultiValuedMap to decorate, may not be null

keyTransformer:Transformer<? super K, ? extends K>

the transformer to use for key conversion, null means no conversion

valueTransformer:Transformer<? super V, ? extends V>

the transformer to use for value conversion, null means no conversion

Returns:TransformedMultiValuedMap<K, V>

a new transformed MultiValuedMap

Exceptions
NullPointerException:
if map is null
transformKeyback to summary
protected K transformKey(final K object)

Transforms a key.

The transformer itself may throw an exception if necessary.

Parameters
object:K

the object to transform

Returns:K

the transformed object

transformValueback to summary
protected V transformValue(final V object)

Transforms a value.

The transformer itself may throw an exception if necessary.

Parameters
object:V

the object to transform

Returns:V

the transformed object