K
- the type of the keys in this mapV
- the type of the values in this mappublic class PredicatedSortedMap<K,V> extends PredicatedMap<K,V> implements SortedMap<K,V>
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 Collections.synchronizedSortedMap(java.util.SortedMap<K, V>)
. This class may throw
exceptions when accessed by concurrent threads without synchronization.
This class is Serializable from Commons Collections 3.1.
keyPredicate, valuePredicate
Modifier | Constructor and Description |
---|---|
protected |
PredicatedSortedMap(SortedMap<K,V> map,
Predicate<? super K> keyPredicate,
Predicate<? super V> valuePredicate)
Constructor that wraps (not copies).
|
Modifier and Type | Method and Description |
---|---|
Comparator<? super K> |
comparator() |
Set<Map.Entry<K,V>> |
entrySet() |
K |
firstKey() |
protected SortedMap<K,V> |
getSortedMap()
Gets the map being decorated.
|
SortedMap<K,V> |
headMap(K toKey) |
K |
lastKey() |
static <K,V> PredicatedSortedMap<K,V> |
predicatedSortedMap(SortedMap<K,V> map,
Predicate<? super K> keyPredicate,
Predicate<? super V> valuePredicate)
Factory method to create a predicated (validating) sorted map.
|
SortedMap<K,V> |
subMap(K fromKey,
K toKey) |
SortedMap<K,V> |
tailMap(K fromKey) |
checkSetValue, isSetValueChecking, predicatedMap, put, putAll, validate
clear, containsKey, containsValue, decorated, equals, get, hashCode, isEmpty, keySet, remove, size, toString, values
mapIterator
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size
protected PredicatedSortedMap(SortedMap<K,V> map, Predicate<? super K> keyPredicate, Predicate<? super V> 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 checkNullPointerException
- if the map is nullpublic static <K,V> PredicatedSortedMap<K,V> predicatedSortedMap(SortedMap<K,V> map, Predicate<? super K> keyPredicate, Predicate<? super V> valuePredicate)
If there are any elements already in the list being decorated, they are validated.
K
- the key typeV
- the value typemap
- 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 checkNullPointerException
- if the map is nullprotected SortedMap<K,V> getSortedMap()
public Comparator<? super K> comparator()
comparator
in interface SortedMap<K,V>
public Set<Map.Entry<K,V>> entrySet()
entrySet
in interface Map<K,V>
entrySet
in interface Get<K,V>
entrySet
in class AbstractMapDecorator<K,V>
Map.entrySet()
Copyright © 2001–2019 The Apache Software Foundation. All rights reserved.