Top Description Constructors Methods
com.google.common.collect

public abstract Class ForwardingMapEntry<K extends @Nullable Object, V extends @Nullable Object>

extends ForwardingObject
implements Map.Entry<K extends @Nullable Object, V extends @Nullable Object>
Class Inheritance
All Implemented Interfaces
java.util.Map.Entry
Known Direct Subclasses
com.google.common.reflect.MutableTypeToInstanceMap.UnmodifiableEntry, com.google.common.collect.AbstractBiMap.BiMapEntry
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, com.google.common.base.Objects, java.util.Map, .Map.Entry, javax.annotation.CheckForNull, org.checkerframework.checker.nullness.qual.Nullable

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 ForwardingMapEntry forward indiscriminately to the methods of the delegate. For example, overriding getValue alone will not change the behavior of equals, which can lead to unexpected behavior. In this case, you should override equals as well, either providing your own implementation, or delegating to the provided standardEquals method.

Each of the standard methods, where appropriate, use Objects#equal 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 a SortedMap whose comparator is not consistent with equals.

The standard methods are not guaranteed to be thread-safe, even when all of the methods that they depend on are thread-safe.

Authors
Mike Bostock, Louis Wasserman
Since
2.0

Constructor Summary

AccessConstructor and Description
protected
ForwardingMapEntry()

Constructor for use by subclasses.

Method Summary

Modifier and TypeMethod and Description
protected abstract Map.Entry<K, V>
delegate()

Implements abstract com.google.common.collect.ForwardingObject.delegate.

Returns the backing delegate instance that methods are forwarded to.
public boolean
equals(Object
object to be compared for equality with this map entry
object
)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Compares the specified object with this entry for equality.
public K
getKey()

Implements java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.
public V
getValue()

Implements java.util.Map.Entry.getValue.

Returns the value corresponding to this entry.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry.
public V
setValue(V
new value to be stored in this entry
value
)

Implements java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation).
protected boolean
standardEquals(Object object)

A sensible definition of equals(Object) in terms of getKey() and getValue().

protected int
standardHashCode()

A sensible definition of hashCode() in terms of getKey() and getValue().

protected String
standardToString()

A sensible definition of toString in terms of getKey and getValue.

Inherited from com.google.common.collect.ForwardingObject:
toString

Constructor Detail

ForwardingMapEntryback to summary
protected ForwardingMapEntry()

Constructor for use by subclasses.

Method Detail

delegateback to summary
protected abstract Map.Entry<K, V> delegate()

Implements abstract com.google.common.collect.ForwardingObject.delegate.

Doc from com.google.common.collect.ForwardingObject.delegate.

Returns 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 as ForwardingSet#delegate. Concrete subclasses override this method to supply the instance being decorated.

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Doc from java.util.Map.Entry.equals.

Compares the specified object with this entry for equality. Returns true if the given object is also a map entry and the two entries represent the same mapping. More formally, two entries e1 and e2 represent the same mapping if

    (e1.getKey()==null ?
     e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &&
    (e1.getValue()==null ?
     e2.getValue()==null : e1.getValue().equals(e2.getValue()))
This ensures that the equals method works properly across different implementations of the Map.Entry interface.
Parameters
object:Object

object to be compared for equality with this map entry

Returns:boolean

true if the specified object is equal to this map entry

Annotations
@Override
getKeyback to summary
public K getKey()

Implements java.util.Map.Entry.getKey.

Doc from java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

Returns:K

the key corresponding to this entry

Annotations
@Override
@ParametricNullness
getValueback to summary
public V getValue()

Implements java.util.Map.Entry.getValue.

Doc from java.util.Map.Entry.getValue.

Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined.

Returns:V

the value corresponding to this entry

Annotations
@Override
@ParametricNullness
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Doc from java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry. The hash code of a map entry e is defined to be:

    (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
    (e.getValue()==null ? 0 : e.getValue().hashCode())
This ensures that e1.equals(e2) implies that e1.hashCode()==e2.hashCode() for any two Entries e1 and e2, as required by the general contract of Object.hashCode.
Returns:int

the hash code value for this map entry

Annotations
@Override
setValueback to summary
public V setValue(V value)

Implements java.util.Map.Entry.setValue.

Doc from java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove operation).

Parameters
value:V

new value to be stored in this entry

Returns:V

old value corresponding to the entry

Annotations
@Override
@ParametricNullness
standardEqualsback to summary
protected boolean standardEquals(Object object)

A sensible definition of equals(Object) in terms of getKey() and getValue(). If you override either of these methods, you may wish to override equals(Object) to forward to this implementation.

Since
7.0
standardHashCodeback to summary
protected int standardHashCode()

A sensible definition of hashCode() in terms of getKey() and getValue(). If you override either of these methods, you may wish to override hashCode() to forward to this implementation.

Since
7.0
standardToStringback to summary
protected String standardToString()

A sensible definition of toString in terms of getKey and getValue. If you override either of these methods, you may wish to override equals to forward to this implementation.

Since
7.0