Class ForwardingMap<K,V>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingMap<K,V>
-
- All Implemented Interfaces:
java.util.Map<K,V>
- Direct Known Subclasses:
EnumBiMap,EnumHashBiMap,ForwardingNavigableMap.StandardDescendingMap,ForwardingSortedMap,ImmutableClassToInstanceMap,MutableClassToInstanceMap
@GwtCompatible public abstract class ForwardingMap<K,V> extends ForwardingObject implements java.util.Map<K,V>
A map which forwards all its method calls to another map. Subclasses should override one or more methods to modify the behavior of the backing map as desired per the decorator pattern.Warning: The methods of
ForwardingMapforward indiscriminately to the methods of the delegate. For example, overridingput(K, V)alone will not change the behavior ofputAll(java.util.Map<? extends K, ? extends V>), which can lead to unexpected behavior. In this case, you should overrideputAllas well, either providing your own implementation, or delegating to the providedstandardPutAllmethod.Each of the
standardmethods, where appropriate, useObjects.equal(java.lang.Object, java.lang.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 aSortedMapwhose comparator is not consistent withequals.The
standardmethods 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 (imported from Google Collections Library)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classForwardingMap.StandardEntrySetA sensible implementation ofMap.entrySet()in terms of the following methods:clear(),containsKey(java.lang.Object),get(java.lang.Object),isEmpty(),remove(java.lang.Object), andsize().protected classForwardingMap.StandardKeySetA sensible implementation ofMap.keySet()in terms of the following methods:clear(),containsKey(java.lang.Object),isEmpty(),remove(java.lang.Object),size(), and theSet.iterator()method ofentrySet().protected classForwardingMap.StandardValuesA sensible implementation ofMap.values()in terms of the following methods:clear(),containsValue(java.lang.Object),isEmpty(),size(), and theSet.iterator()method ofentrySet().
-
Constructor Summary
Constructors Modifier Constructor Description protectedForwardingMap()Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)protected abstract java.util.Map<K,V>delegate()Returns the backing delegate instance that methods are forwarded to.java.util.Set<java.util.Map.Entry<K,V>>entrySet()booleanequals(java.lang.Object object)Vget(java.lang.Object key)inthashCode()booleanisEmpty()java.util.Set<K>keySet()Vput(K key, V value)voidputAll(java.util.Map<? extends K,? extends V> map)Vremove(java.lang.Object object)intsize()protected voidstandardClear()protected booleanstandardContainsKey(java.lang.Object key)A sensible, albeit inefficient, definition ofcontainsKey(java.lang.Object)in terms of theiteratormethod ofentrySet().protected booleanstandardContainsValue(java.lang.Object value)A sensible definition ofcontainsValue(java.lang.Object)in terms of theiteratormethod ofentrySet().protected booleanstandardEquals(java.lang.Object object)protected intstandardHashCode()protected booleanstandardIsEmpty()protected voidstandardPutAll(java.util.Map<? extends K,? extends V> map)A sensible definition ofputAll(Map)in terms ofput(Object, Object).protected VstandardRemove(java.lang.Object key)A sensible, albeit inefficient, definition ofremove(java.lang.Object)in terms of theiteratormethod ofentrySet().protected java.lang.StringstandardToString()java.util.Collection<V>values()-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
-
-
-
Method Detail
-
delegate
protected abstract java.util.Map<K,V> 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
-
remove
public V remove(java.lang.Object object)
-
containsKey
public boolean containsKey(@Nullable java.lang.Object key)
-
containsValue
public boolean containsValue(@Nullable java.lang.Object value)
-
values
public java.util.Collection<V> values()
-
equals
public boolean equals(@Nullable java.lang.Object object)
-
hashCode
public int hashCode()
-
standardPutAll
protected void standardPutAll(java.util.Map<? extends K,? extends V> map)
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
@Beta protected V standardRemove(@Nullable java.lang.Object key)
A sensible, albeit inefficient, definition ofremove(java.lang.Object)in terms of theiteratormethod ofentrySet(). If you overrideentrySet(), you may wish to overrideremove(java.lang.Object)to forward to this implementation.Alternately, you may wish to override
remove(java.lang.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
@Beta protected boolean standardContainsKey(@Nullable java.lang.Object key)
A sensible, albeit inefficient, definition ofcontainsKey(java.lang.Object)in terms of theiteratormethod ofentrySet(). If you overrideentrySet(), you may wish to overridecontainsKey(java.lang.Object)to forward to this implementation.- Since:
- 7.0
-
standardContainsValue
protected boolean standardContainsValue(@Nullable java.lang.Object value)
A sensible definition ofcontainsValue(java.lang.Object)in terms of theiteratormethod ofentrySet(). If you overrideentrySet(), you may wish to overridecontainsValue(java.lang.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
protected boolean standardEquals(@Nullable java.lang.Object object)
A sensible definition ofequals(java.lang.Object)in terms of theequalsmethod ofentrySet(). If you overrideentrySet(), you may wish to overrideequals(java.lang.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
protected java.lang.String 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
-
-