public class PredicatedSortedMap extends PredicatedMap implements SortedMap
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 = PredicatedSortedSet.decorate(new TreeMap(), NotNullPredicate.INSTANCE, 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 Collections.synchronizedSortedMap(java.util.SortedMap)
. This class may throw
exceptions when accessed by concurrent threads without synchronization.
This class is Serializable from Commons Collections 3.1.
keyPredicate, valuePredicate
map
Modifier | Constructor and Description |
---|---|
protected |
PredicatedSortedMap(SortedMap map,
Predicate keyPredicate,
Predicate valuePredicate)
Constructor that wraps (not copies).
|
Modifier and Type | Method and Description |
---|---|
Comparator |
comparator() |
static SortedMap |
decorate(SortedMap map,
Predicate keyPredicate,
Predicate valuePredicate)
Factory method to create a predicated (validating) sorted map.
|
Set |
entrySet() |
Object |
firstKey() |
protected SortedMap |
getSortedMap()
Gets the map being decorated.
|
SortedMap |
headMap(Object toKey) |
Object |
lastKey() |
SortedMap |
subMap(Object fromKey,
Object toKey) |
SortedMap |
tailMap(Object fromKey) |
checkSetValue, decorate, isSetValueChecking, put, putAll, validate
clear, containsKey, containsValue, equals, get, getMap, hashCode, isEmpty, keySet, remove, size, toString, values
protected PredicatedSortedMap(SortedMap map, Predicate keyPredicate, Predicate valuePredicate)
map
- the map to decorate, must not be nullkeyPredicate
- the predicate to validate the keys, null means no checkvaluePredicate
- the predicate to validate to values, null means no checkIllegalArgumentException
- if the map is nullpublic static SortedMap decorate(SortedMap map, Predicate keyPredicate, Predicate valuePredicate)
If there are any elements already in the list being decorated, they are validated.
map
- the map to decorate, must not be nullkeyPredicate
- the predicate to validate the keys, null means no checkvaluePredicate
- the predicate to validate to values, null means no checkIllegalArgumentException
- if the map is nullprotected SortedMap getSortedMap()
public Comparator comparator()
comparator
in interface SortedMap
public Set entrySet()
entrySet
in interface Map
entrySet
in class AbstractMapDecorator
Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.