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

public Class TransformedSortedMap<K, V>

extends TransformedMap<K, V>
implements SortedMap<K, V>
Class Inheritance
All Implemented Interfaces
java.util.SortedMap, java.util.SequencedMap, java.util.Map
Type Parameters
<K>
the type of the keys in this map
<V>
the type of the values in this map
Imports
java.util.Comparator, .Map, .SortedMap, org.apache.commons.collections4.Transformer

Decorates another SortedMap to transform objects that are added.

The Map put methods and Map.Entry setValue method are affected by this class. 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 TransformedSortedMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. The simplest approach is to wrap this map using java.util.Collections#synchronizedSortedMap. This class may throw exceptions when accessed by concurrent threads without synchronization.

This class is Serializable from Commons Collections 3.1.

Since
3.0

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from org.apache.commons.collections4.map.TransformedMap:
keyTransformervalueTransformer

Constructor Summary

AccessConstructor and Description
protected
TransformedSortedMap(final SortedMap<K, V>
the map to decorate, must not be null
map
,
final Transformer<? super K, ? extends K>
the predicate to validate the keys, null means no transformation
keyTransformer
,
final Transformer<? super V, ? extends V>
the predicate to validate to values, null means no transformation
valueTransformer
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public Comparator<? super K>
comparator()

Implements java.util.SortedMap.comparator.

Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.
public K
firstKey()

Implements java.util.SortedMap.firstKey.

Returns the first (lowest) key currently in this map.
protected SortedMap<K, V>

Returns:

the decorated map
getSortedMap
()

Gets the map being decorated.

public SortedMap<K, V>
headMap(final K
high endpoint (exclusive) of the keys in the returned map
toKey
)

Implements java.util.SortedMap.headMap.

Returns a view of the portion of this map whose keys are strictly less than toKey.
public K
lastKey()

Implements java.util.SortedMap.lastKey.

Returns the last (highest) key currently in this map.
public SortedMap<K, V>
subMap(final K
low endpoint (inclusive) of the keys in the returned map
fromKey
,
final K
high endpoint (exclusive) of the keys in the returned map
toKey
)

Implements java.util.SortedMap.subMap.

Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive.
public SortedMap<K, V>
tailMap(final K
low endpoint (inclusive) of the keys in the returned map
fromKey
)

Implements java.util.SortedMap.tailMap.

Returns a view of the portion of this map whose keys are greater than or equal to fromKey.
public static <
the key type
K
,
the value type
V
>
TransformedSortedMap<K, V>

Returns:

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

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

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

Returns:

a new transformed sorted map
transformingSortedMap
(final SortedMap<K, V>
the map to decorate, must not be null
map
,
final Transformer<? super K, ? extends K>
the predicate to validate the keys, null means no transformation
keyTransformer
,
final Transformer<? super V, ? extends V>
the predicate to validate to values, null means no transformation
valueTransformer
)

Factory method to create a transforming sorted map.

Inherited from org.apache.commons.collections4.map.TransformedMap:
checkSetValueisSetValueCheckingputputAlltransformedMaptransformingMaptransformKeytransformMaptransformValue

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.map.TransformedMap.serialVersionUID.

Serialization version

Constructor Detail

TransformedSortedMapback to summary
protected TransformedSortedMap(final SortedMap<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:SortedMap<K, V>

the map to decorate, must not be null

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

the predicate to validate the keys, null means no transformation

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

the predicate to validate to values, null means no transformation

Exceptions
NullPointerException:
if the map is null

Method Detail

comparatorback to summary
public Comparator<? super K> comparator()

Implements java.util.SortedMap.comparator.

Doc from java.util.SortedMap.comparator.

Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.

Returns:Comparator<? super K>

the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys

Annotations
@Override
firstKeyback to summary
public K firstKey()

Implements java.util.SortedMap.firstKey.

Doc from java.util.SortedMap.firstKey.

Returns the first (lowest) key currently in this map.

Returns:K

the first (lowest) key currently in this map

Annotations
@Override
getSortedMapback to summary
protected SortedMap<K, V> getSortedMap()

Gets the map being decorated.

Returns:SortedMap<K, V>

the decorated map

headMapback to summary
public SortedMap<K, V> headMap(final K toKey)

Implements java.util.SortedMap.headMap.

Doc from java.util.SortedMap.headMap.

Returns a view of the portion of this map whose keys are strictly less than toKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

Parameters
toKey:K

high endpoint (exclusive) of the keys in the returned map

Returns:SortedMap<K, V>

a view of the portion of this map whose keys are strictly less than toKey

Annotations
@Override
lastKeyback to summary
public K lastKey()

Implements java.util.SortedMap.lastKey.

Doc from java.util.SortedMap.lastKey.

Returns the last (highest) key currently in this map.

Returns:K

the last (highest) key currently in this map

Annotations
@Override
subMapback to summary
public SortedMap<K, V> subMap(final K fromKey, final K toKey)

Implements java.util.SortedMap.subMap.

Doc from java.util.SortedMap.subMap.

Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive. (If fromKey and toKey are equal, the returned map is empty.) The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

Parameters
fromKey:K

low endpoint (inclusive) of the keys in the returned map

toKey:K

high endpoint (exclusive) of the keys in the returned map

Returns:SortedMap<K, V>

a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive

Annotations
@Override
tailMapback to summary
public SortedMap<K, V> tailMap(final K fromKey)

Implements java.util.SortedMap.tailMap.

Doc from java.util.SortedMap.tailMap.

Returns a view of the portion of this map whose keys are greater than or equal to fromKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

Parameters
fromKey:K

low endpoint (inclusive) of the keys in the returned map

Returns:SortedMap<K, V>

a view of the portion of this map whose keys are greater than or equal to fromKey

Annotations
@Override
transformedSortedMapback to summary
public static <K, V> TransformedSortedMap<K, V> transformedSortedMap(final SortedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer)

Factory method to create a transforming sorted map 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 transformingSortedMap(SortedMap, Transformer, Transformer).

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

the map to decorate, must not be null

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

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

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

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

Returns:TransformedSortedMap<K, V>

a new transformed sorted map

Exceptions
NullPointerException:
if map is null
Since
4.0
transformingSortedMapback to summary
public static <K, V> TransformedSortedMap<K, V> transformingSortedMap(final SortedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer)

Factory method to create a transforming sorted map.

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

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

the map to decorate, must not be null

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

the predicate to validate the keys, null means no transformation

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

the predicate to validate to values, null means no transformation

Returns:TransformedSortedMap<K, V>

a new transformed sorted map

Exceptions
NullPointerException:
if the map is null
Since
4.0