Package eu.bandm.tools.util.nonnull
Class MapProxy<K,V>
java.lang.Object
eu.bandm.tools.util.nonnull.MapProxy<K,V>
- Type Parameters:
K- the type of the keysV- the type of the values
- All Implemented Interfaces:
Serializable,Map<K,V>
- Direct Known Subclasses:
NonNullKeyProxy,NonNullProxy,NonNullValueProxy
Implements a map by delegation to a peer object from the
Java collection library. This class is not directly for a user,
but operated through interfaces.
Is used for nonNull maps, therefore the "put" methods (etc.) are implemented in the subclasses and left here abstract. This class implements more explicit delegations to the peer than minimally required by AbstractMap, for higher efficiency.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classProxy, not directy accessible by the user.(package private) static classProxy, not directy accessible by the user.(package private) static classPutting null as a value (not as a key) must also be prevented on this way: NonNullMap -> entrySet() -> NonNullMapEntrySet -> iterator() -> NonNullMapEntryIterator -> next() -> NonNullMapEntry -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasSorted()Returns a sorted, unmodifiable view IFF the backing peer is a sorted map.voidclear()booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()Will be overridden for value checked maps.booleaninthashCode()booleanisEmpty()keySet()intsize()toString()values()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, put, putAll, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
peer
cf https://stackoverflow.com/questions/6433478/is-there-a-standard-java-list-implementation-that-doesnt-allow-adding-null-to-i
-
-
Constructor Details
-
MapProxy
Not directly accessible by the user.- Parameters:
peer- The object from JDK runtime which makes the real work.- Throws:
NullPointerException- if the argument is null.
-
-
Method Details
-
toString
-
asSorted
Returns a sorted, unmodifiable view IFF the backing peer is a sorted map.- Returns:
- a sorted, unmodifiable view
- Throws:
UnsupportedOperationException- if the backing peer does not offer a sorted view.
-
clear
public void clear() -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
entrySet
Will be overridden for value checked maps. Java API doc says "[Map.entrySet()] does not support the add or addAll operations", so no checks are required on this level. -
equals
-
get
-
hashCode
public int hashCode() -
isEmpty
public boolean isEmpty() -
keySet
-
remove
-
size
public int size() -
values
-