@GwtCompatible public abstract class ForwardingMap<K,V> extends ForwardingObjectimplements Map <K ,V>
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(java.util.Map<? extends K, ? extends V>), 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.
Each of the standard methods, where appropriate, use Objects 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.
| Modifier and Type | Class and Description |
|---|---|
protected class |
ForwardingMap
A sensible implementation of
Map in terms of the following methods:
clear(),
containsKey(java.lang.Object),
get(java.lang.Object),
isEmpty(),
remove(java.lang.Object), and
size().
|
protected class |
ForwardingMap
A sensible implementation of
Map in terms of the following methods:
clear(),
containsKey(java.lang.Object),
isEmpty(),
remove(java.lang.Object),
size(), and the
Set method of
entrySet().
|
protected class |
ForwardingMap
A sensible implementation of
Map in terms of the following methods:
clear(),
containsValue(java.lang.Object),
isEmpty(),
size(), and the
Set method of
entrySet().
|
| Modifier | Constructor and Description |
|---|---|
protected |
ForwardingMap()
Constructor for use by subclasses.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
|
boolean |
containsKey(Object
|
boolean |
containsValue(Object
|
protected abstract Map |
delegate()
Returns the backing delegate instance that methods are forwarded to.
|
Set |
entrySet()
|
boolean |
equals(Object
|
V |
get(Object
|
int |
hashCode()
|
boolean |
isEmpty()
|
Set |
keySet()
|
V |
put(K key, V value)
|
void |
putAll(Map
|
V |
remove(Object
|
int |
size()
|
protected void |
standardClear()
|
protected boolean |
standardContainsKey(Object
A sensible, albeit inefficient, definition of
containsKey(java.lang.Object) in terms of the
iterator method of
entrySet().
|
protected boolean |
standardContainsValue(Object
A sensible definition of
containsValue(java.lang.Object) in terms of the
iterator method of
entrySet().
|
protected boolean |
standardEquals(Object
|
protected int |
standardHashCode()
|
protected boolean |
standardIsEmpty()
|
protected void |
standardPutAll(Map
A sensible definition of
putAll(Map) in terms of
put(Object, Object).
|
protected V |
standardRemove(Object
A sensible, albeit inefficient, definition of
remove(java.lang.Object) in terms of the
iterator method of
entrySet().
|
protected String |
standardToString()
|
Collection |
values()
|
toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllprotected abstract Map<K ,V> delegate()
ForwardingObject
ForwardingSet.delegate() . Concrete subclasses override this method to supply the instance being decorated.
public int size()
public boolean isEmpty()
public void clear()
public boolean containsKey(Objectkey)
public boolean containsValue(Objectvalue)
public Collection<V> values()
public boolean equals(Objectobject)
public int hashCode()
protected void standardPutAll(Map<? extends K ,? extends V> map)
putAll(Map) in terms of
put(Object, Object). If you override
put(Object, Object), you may wish to override
putAll(Map) to forward to this implementation.
@Beta protected V standardRemove(Objectkey)
remove(java.lang.Object) in terms of the
iterator method of
entrySet(). If you override
entrySet(), you may wish to override
remove(java.lang.Object) to forward to this implementation.
Alternately, you may wish to override remove(java.lang.Object) with keySet().remove, assuming that approach would not lead to an infinite loop.
protected void standardClear()
clear() in terms of the
iterator method of
entrySet(). In many cases, you may wish to override
clear() to forward to this implementation.
@Beta protected boolean standardContainsKey(Objectkey)
containsKey(java.lang.Object) in terms of the
iterator method of
entrySet(). If you override
entrySet(), you may wish to override
containsKey(java.lang.Object) to forward to this implementation.
protected boolean standardContainsValue(Objectvalue)
containsValue(java.lang.Object) in terms of the
iterator method of
entrySet(). If you override
entrySet(), you may wish to override
containsValue(java.lang.Object) to forward to this implementation.
protected boolean standardIsEmpty()
isEmpty() in terms of the
iterator method of
entrySet(). If you override
entrySet(), you may wish to override
isEmpty() to forward to this implementation.
protected boolean standardEquals(Objectobject)
equals(java.lang.Object) in terms of the
equals method of
entrySet(). If you override
entrySet(), you may wish to override
equals(java.lang.Object) to forward to this implementation.
protected int standardHashCode()
hashCode() in terms of the
iterator method of
entrySet(). If you override
entrySet(), you may wish to override
hashCode() to forward to this implementation.
protected StringstandardToString()
ForwardingObject.toString() in terms of the
iterator method of
entrySet(). If you override
entrySet(), you may wish to override
ForwardingObject.toString() to forward to this implementation.