Class AbstractInputCheckedMapDecorator<K,V>
- All Implemented Interfaces:
Map<K,
,V> Get<K,
,V> IterableGet<K,
,V> IterableMap<K,
,V> Put<K,
V>
- Direct Known Subclasses:
PredicatedMap
,TransformedMap
The Map API is very difficult to decorate correctly, and involves implementing lots of different classes. This class exists to provide a simpler API.
Special hook methods are provided that are called when objects are added to the map. By overriding these methods, the input can be validated or manipulated. In addition to the main map methods, the entrySet is also affected, which is the hardest part of writing map implementations.
This class is package-scoped, and may be withdrawn or replaced in future versions of Commons Collections.
- Since:
- 3.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
Implementation of an entry set that checks additions via setValue.private class
Implementation of an entry set iterator that checks additions via setValue.private class
Implementation of a map entry that checks additions via setValue. -
Field Summary
Fields inherited from class org.apache.commons.collections4.map.AbstractMapDecorator
map
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Constructor only used in deserialization, do not use otherwise.protected
Constructor that wraps (not copies). -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract V
checkSetValue
(V value) Hook method called when a value is being set usingsetValue
.entrySet()
protected boolean
Hook method called to determine ifcheckSetValue
has any effect.Methods inherited from class org.apache.commons.collections4.map.AbstractMapDecorator
clear, containsKey, containsValue, decorated, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, toString, values
Methods inherited from class org.apache.commons.collections4.map.AbstractIterableMap
mapIterator
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
AbstractInputCheckedMapDecorator
protected AbstractInputCheckedMapDecorator()Constructor only used in deserialization, do not use otherwise. -
AbstractInputCheckedMapDecorator
Constructor that wraps (not copies).- Parameters:
map
- the map to decorate, must not be null- Throws:
NullPointerException
- if map is null
-
-
Method Details
-
checkSetValue
Hook method called when a value is being set usingsetValue
.An implementation may validate the value and throw an exception or it may transform the value into another object.
This implementation returns the input value.
- Parameters:
value
- the value to check- Returns:
- the input value
- Throws:
UnsupportedOperationException
- if the map may not be changed by setValueIllegalArgumentException
- if the specified value is invalidClassCastException
- if the class of the specified value is invalidNullPointerException
- if the specified value is null and nulls are invalid
-
isSetValueChecking
protected boolean isSetValueChecking()Hook method called to determine ifcheckSetValue
has any effect.An implementation should return false if the
checkSetValue
method has no effect as this optimises the implementation.This implementation returns
true
.- Returns:
- true always
-
entrySet
-