- All Implemented Interfaces:
Map<K,V>
- Direct Known Subclasses:
EnumBiMap, EnumHashBiMap, ForwardingConcurrentMap, ForwardingNavigableMap.StandardDescendingMap, ForwardingSortedMap, ImmutableClassToInstanceMap, ImmutableTypeToInstanceMap, MutableClassToInstanceMap, MutableTypeToInstanceMap
Warning: The methods of ForwardingMap forward indiscriminately to the
methods of the delegate. For example, overriding put(K, V) alone will not change the
behavior of putAll(Map), which can lead to unexpected behavior. In this case, you should
override putAll as well, either providing your own implementation, or delegating to the
provided standardPutAll method.
default method warning: This class does not forward calls to
default methods. Instead, it inherits their default implementations. When those implementations
invoke methods, they invoke methods on the ForwardingMap.
Each of the standard methods, where appropriate, use Objects.equals(Object, Object) to test
equality for both keys and values. This may not be the desired behavior for map implementations
that use non-standard notions of key equality, such as a SortedMap whose comparator is
not consistent with equals.
The standard methods and the collection views they return are not guaranteed to be
thread-safe, even when all of the methods that they depend on are thread-safe.
- Since:
- 2.0
- Author:
- Kevin Bourrillion, Jared Levy, Louis Wasserman
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA sensible implementation ofMap.entrySet()in terms of the following methods:clear(),containsKey(Object),get(Object),isEmpty(),remove(Object), andsize().protected classA sensible implementation ofMap.keySet()in terms of the following methods:clear(),containsKey(Object),isEmpty(),remove(Object),size(), and theSet.iterator()method ofentrySet().protected classA sensible implementation ofMap.values()in terms of the following methods:clear(),containsValue(Object),isEmpty(),size(), and theSet.iterator()method ofentrySet(). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(@Nullable Object key) booleancontainsValue(@Nullable Object value) delegate()Returns the backing delegate instance that methods are forwarded to.entrySet()booleaninthashCode()booleanisEmpty()keySet()voidintsize()protected voidprotected booleanA sensible, albeit inefficient, definition ofcontainsKey(Object)in terms of theiteratormethod ofentrySet().protected booleanstandardContainsValue(@Nullable Object value) protected booleanstandardEquals(@Nullable Object object) protected intprotected booleanprotected voidstandardPutAll(Map<? extends K, ? extends V> map) A sensible definition ofputAll(Map)in terms ofput(Object, Object).A sensible, albeit inefficient, definition ofremove(Object)in terms of theiteratormethod ofentrySet().protected Stringvalues()Methods inherited from class ForwardingObject
toStringMethods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
ForwardingMap
protected ForwardingMap()Constructor for use by subclasses.
-
-
Method Details
-
delegate
Description copied from class:ForwardingObjectReturns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such asForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegatein classForwardingObject
-
size
-
isEmpty
-
remove
-
clear
-
containsKey
-
containsValue
-
get
-
put
-
putAll
-
keySet
-
values
-
entrySet
-
equals
-
hashCode
-
standardPutAll
A sensible definition ofputAll(Map)in terms ofput(Object, Object). If you overrideput(Object, Object), you may wish to overrideputAll(Map)to forward to this implementation.- Since:
- 7.0
-
standardRemove
A sensible, albeit inefficient, definition ofremove(Object)in terms of theiteratormethod ofentrySet(). If you overrideentrySet(), you may wish to overrideremove(Object)to forward to this implementation.Alternately, you may wish to override
remove(Object)withkeySet().remove, assuming that approach would not lead to an infinite loop.- Since:
- 7.0
-
standardClear
protected void standardClear()A sensible definition ofclear()in terms of theiteratormethod ofentrySet(). In many cases, you may wish to overrideclear()to forward to this implementation.- Since:
- 7.0
-
standardContainsKey
A sensible, albeit inefficient, definition ofcontainsKey(Object)in terms of theiteratormethod ofentrySet(). If you overrideentrySet(), you may wish to overridecontainsKey(Object)to forward to this implementation.- Since:
- 7.0
-
standardContainsValue
A sensible definition ofcontainsValue(Object)in terms of theiteratormethod ofentrySet(). If you overrideentrySet(), you may wish to overridecontainsValue(Object)to forward to this implementation.- Since:
- 7.0
-
standardIsEmpty
protected boolean standardIsEmpty()A sensible definition ofisEmpty()in terms of theiteratormethod ofentrySet(). If you overrideentrySet(), you may wish to overrideisEmpty()to forward to this implementation.- Since:
- 7.0
-
standardEquals
A sensible definition ofequals(Object)in terms of theequalsmethod ofentrySet(). If you overrideentrySet(), you may wish to overrideequals(Object)to forward to this implementation.- Since:
- 7.0
-
standardHashCode
protected int standardHashCode()A sensible definition ofhashCode()in terms of theiteratormethod ofentrySet(). If you overrideentrySet(), you may wish to overridehashCode()to forward to this implementation.- Since:
- 7.0
-
standardToString
A sensible definition ofForwardingObject.toString()in terms of theiteratormethod ofentrySet(). If you overrideentrySet(), you may wish to overrideForwardingObject.toString()to forward to this implementation.- Since:
- 7.0
-