Class ForwardingMapEntry<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingMapEntry<K,V>
-
- All Implemented Interfaces:
java.util.Map.Entry<K,V>
@GwtCompatible public abstract class ForwardingMapEntry<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> extends ForwardingObject implements java.util.Map.Entry<K,V>
A map entry which forwards all its method calls to another map entry. Subclasses should override one or more methods to modify the behavior of the backing map entry as desired per the decorator pattern.Warning: The methods of
ForwardingMapEntryforward indiscriminately to the methods of the delegate. For example, overridinggetValue()alone will not change the behavior ofequals(java.lang.Object), which can lead to unexpected behavior. In this case, you should overrideequalsas well, either providing your own implementation, or delegating to the providedstandardEqualsmethod.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 the entry of aSortedMapwhose comparator is not consistent withequals.The
standardmethods are not guaranteed to be thread-safe, even when all of the methods that they depend on are thread-safe.- Since:
- 2.0
- Author:
- Mike Bostock, Louis Wasserman
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedForwardingMapEntry()Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract java.util.Map.Entry<K,V>delegate()Returns the backing delegate instance that methods are forwarded to.booleanequals(java.lang.Object object)KgetKey()VgetValue()inthashCode()VsetValue(V value)protected booleanstandardEquals(java.lang.Object object)protected intstandardHashCode()protected java.lang.StringstandardToString()-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
-
-
-
Constructor Detail
-
ForwardingMapEntry
protected ForwardingMapEntry()
Constructor for use by subclasses.
-
-
Method Detail
-
delegate
protected abstract java.util.Map.Entry<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
-
equals
public boolean equals(@CheckForNull java.lang.Object object)
-
hashCode
public int hashCode()
-
standardEquals
protected boolean standardEquals(@CheckForNull java.lang.Object object)
A sensible definition ofequals(Object)in terms ofgetKey()andgetValue(). If you override either of these methods, you may wish to overrideequals(Object)to forward to this implementation.- Since:
- 7.0
-
standardHashCode
protected int standardHashCode()
A sensible definition ofhashCode()in terms ofgetKey()andgetValue(). If you override either of these methods, 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 ofgetKey()andgetValue(). If you override either of these methods, you may wish to overrideequals(java.lang.Object)to forward to this implementation.- Since:
- 7.0
-
-