Map 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.
Map map = PredicatedSet.decorate(new HashMap(), NotNullPredicate.INSTANCE, null);
Note that PredicatedMap 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.. This class may throw
exceptions when accessed by concurrent threads without synchronization.
This class is Serializable from Commons Collections 3.1.
| Modifier and Type | Field and Description |
|---|---|
| protected final Predicate | keyPredicate
The key predicate to use |
| private static final long | serialVersionUID
Serialization version |
| protected final Predicate | valuePredicate
The value predicate to use |
| Access | Constructor and Description |
|---|---|
| protected | PredicatedMap(final Map<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). |
| Modifier and Type | Method and Description |
|---|---|
| protected V | Returns: the value itselfthe value to validate value)Implements abstract org. setValue.
|
| protected boolean | Returns: true if a value predicate is in useOverrides org. |
| public static < the key type K, the value type V> PredicatedMap | Returns: a new predicated mapthe 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) map. |
| public V | put(final K
key with which the specified value is to be associated key, final V value to be associated with the specified key value)Overrides org. Implements java. |
| public void | putAll(final Map<? extends K, ? extends V>
mappings to be stored in this map mapToCopy)Overrides org. Implements java. |
| private void | |
| protected void | validate(final K
the key to validate key, final V the value to validate value)Validates a key value pair. |
| private void |
| keyPredicate | back to summary |
|---|---|
| protected final Predicate<? super K> keyPredicate The key predicate to use | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version | |
| valuePredicate | back to summary |
|---|---|
| protected final Predicate<? super V> valuePredicate The value predicate to use | |
| PredicatedMap | back to summary |
|---|---|
| protected PredicatedMap(final Map<K, V> map, final Predicate<? super K> keyPredicate, final Predicate<? super V> valuePredicate) Constructor that wraps (not copies).
| |
| checkSetValue | back to summary |
|---|---|
| protected V checkSetValue(final V value) Implements abstract org. Override to validate an object set into the map via
| |
| isSetValueChecking | back to summary |
|---|---|
| protected boolean isSetValueChecking() Overrides org. Override to only return true when there is a value transformer.
| |
| predicatedMap | back to summary |
|---|---|
| public static <K, V> PredicatedMap Factory method to create a predicated (validating) map. If there are any elements already in the list being decorated, they are validated.
| |
| put | back to summary |
|---|---|
| public V put(final K key, final V value) Overrides org. Implements java. Doc from java. Associates the specified value with the specified key in this map
(optional operation). If the map previously contained a mapping for
the key, the old value is replaced by the specified value. (A map
| |
| putAll | back to summary |
|---|---|
| public void putAll(final Map<? extends K, ? extends V> mapToCopy) Overrides org. Implements java. Doc from java. Copies all of the mappings from the specified map to this map
(optional operation). The effect of this call is equivalent to that
of calling | |
| readObject | back to summary |
|---|---|
| private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException Read the map in using a custom routine.
| |
| validate | back to summary |
|---|---|
| protected void validate(final K key, final V value) Validates a key value pair.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(final ObjectOutputStream out) throws IOException Write the map out using a custom routine.
| |