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

public Class PredicatedSortedMap<K, V>

extends PredicatedMap<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, .SortedMap, org.apache.commons.collections4.Predicate

Decorates another SortedMap to validate that additions match a specified predicate.

This map exists to provide validation for the decorated map. It is normally created to decorate an empty map. If an object cannot be added to the map, an IllegalArgumentException is thrown.

One usage would be to ensure that no null keys are added to the map.

  SortedMap map =
    PredicatedSortedMap.predicatedSortedMap(new TreeMap(),
                                            NotNullPredicate.notNullPredicate(),
                                            null);

Note that PredicatedSortedMap 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.PredicatedMap:
keyPredicatevaluePredicate

Constructor Summary

AccessConstructor and Description
protected
PredicatedSortedMap(final SortedMap<K, V>
the map to decorate, must not be null
map
,
final Predicate<? super K>
the predicate to validate the keys, null means no check
keyPredicate
,
final Predicate<? super V>
the predicate to validate to values, null means no check
valuePredicate
)

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 static <
the key type
K
,
the value type
V
>
PredicatedSortedMap<K, V>

Returns:

a new predicated sorted map
predicatedSortedMap
(final SortedMap<K, V>
the map to decorate, must not be null
map
,
final Predicate<? super K>
the predicate to validate the keys, null means no check
keyPredicate
,
final Predicate<? super V>
the predicate to validate to values, null means no check
valuePredicate
)

Factory method to create a predicated (validating) sorted 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.
Inherited from org.apache.commons.collections4.map.PredicatedMap:
checkSetValueisSetValueCheckingpredicatedMapputputAllvalidate

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

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

Serialization version

Constructor Detail

PredicatedSortedMapback to summary
protected PredicatedSortedMap(final SortedMap<K, V> map, final Predicate<? super K> keyPredicate, final Predicate<? super V> valuePredicate)

Constructor that wraps (not copies).

Parameters
map:SortedMap<K, V>

the map to decorate, must not be null

keyPredicate:Predicate<? super K>

the predicate to validate the keys, null means no check

valuePredicate:Predicate<? super V>

the predicate to validate to values, null means no check

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
predicatedSortedMapback to summary
public static <K, V> PredicatedSortedMap<K, V> predicatedSortedMap(final SortedMap<K, V> map, final Predicate<? super K> keyPredicate, final Predicate<? super V> valuePredicate)

Factory method to create a predicated (validating) sorted map.

If there are any elements already in the list being decorated, they are validated.

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

the map to decorate, must not be null

keyPredicate:Predicate<? super K>

the predicate to validate the keys, null means no check

valuePredicate:Predicate<? super V>

the predicate to validate to values, null means no check

Returns:PredicatedSortedMap<K, V>

a new predicated sorted map

Exceptions
NullPointerException:
if the map is null
Since
4.0
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