Package com.google.common.base
Class Equivalence.Wrapper<T extends @Nullable Object>
- 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 @Nullable Object> extends Object implements Serializable
Wraps an object so thatequals(Object)
andhashCode()
delegate to anEquivalence
.For example, given an
Equivalence
forstrings
namedequiv
that tests equivalence using their lengths:equiv.wrap("a").equals(equiv.wrap("b")) // true equiv.wrap("a").equals(equiv.wrap("hello")) // false
Note 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 boolean
equals(Object obj)
Returnstrue
ifEquivalence.equivalent(Object, Object)
applied to the wrapped references istrue
and both wrappers use thesame
equivalence.T
get()
Returns the (possibly null) reference wrapped by this instance.int
hashCode()
Returns the result ofEquivalence.hash(Object)
applied to the wrapped reference.String
toString()
Returns a string representation for this equivalence wrapper.
-
-
-
Method Detail
-
equals
public boolean equals(@CheckForNull Object obj)
Returnstrue
ifEquivalence.equivalent(Object, Object)
applied to the wrapped references istrue
and both wrappers use thesame
equivalence.
-
hashCode
public int hashCode()
Returns the result ofEquivalence.hash(Object)
applied to the wrapped reference.
-
-