Package com.google.common.base
Class Equivalence.Wrapper<T>
- java.lang.Object
-
- com.google.common.base.Equivalence.Wrapper<T>
-
- All Implemented Interfaces:
Serializable
- Enclosing class:
- Equivalence<T>
public static final class Equivalence.Wrapper<T> extends Object implements Serializable
Wraps an object so thatequals(Object)andhashCode()delegate to anEquivalence.For example, given an
Equivalenceforstringsnamedequivthat tests equivalence using their lengths:equiv.wrap("a").equals(equiv.wrap("b")) // true equiv.wrap("a").equals(equiv.wrap("hello")) // falseNote in particular that an equivalence wrapper is never equal to the object it wraps.
equiv.wrap(obj).equals(obj) // always false- Since:
- 10.0
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)ReturnstrueifEquivalence.equivalent(Object, Object)applied to the wrapped references istrueand both wrappers use thesameequivalence.Tget()Returns the (possibly null) reference wrapped by this instance.inthashCode()Returns the result ofEquivalence.hash(Object)applied to the wrapped reference.StringtoString()Returns a string representation for this equivalence wrapper.
-
-
-
Method Detail
-
get
@NullableDecl public T get()
Returns the (possibly null) reference wrapped by this instance.
-
equals
public boolean equals(@NullableDecl Object obj)
ReturnstrueifEquivalence.equivalent(Object, Object)applied to the wrapped references istrueand both wrappers use thesameequivalence.- Overrides:
equalsin classObject- Parameters:
obj- the reference object with which to compare.- Returns:
trueif this object is the same as the obj argument;falseotherwise.- See Also:
Object.hashCode(),HashMap
-
hashCode
public int hashCode()
Returns the result ofEquivalence.hash(Object)applied to the wrapped reference.- Overrides:
hashCodein classObject- Returns:
- a hash code value for this object.
- See Also:
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
-
-