Package com.google.common.base
Class Equivalence.Wrapper<T>
- java.lang.Object
-
- com.google.common.base.Equivalence.Wrapper<T>
-
- All Implemented Interfaces:
java.io.Serializable
- Enclosing class:
- Equivalence<T>
public static final class Equivalence.Wrapper<T> extends java.lang.Object implements java.io.SerializableWraps 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
-
-
Field Summary
Fields Modifier and Type Field Description private Equivalence<? super T>equivalenceprivate Treferenceprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description privateWrapper(Equivalence<? super T> equivalence, T reference)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.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.java.lang.StringtoString()Returns a string representation for this equivalence wrapper.
-
-
-
Field Detail
-
equivalence
private final Equivalence<? super T> equivalence
-
reference
private final T reference
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Wrapper
private Wrapper(Equivalence<? super T> equivalence, T reference)
-
-
Method Detail
-
get
public T get()
Returns the (possibly null) reference wrapped by this instance.
-
equals
public boolean equals(java.lang.Object obj)
ReturnstrueifEquivalence.equivalent(Object, Object)applied to the wrapped references istrueand both wrappers use thesameequivalence.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Returns the result ofEquivalence.hash(Object)applied to the wrapped reference.- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Returns a string representation for this equivalence wrapper. The form of this string representation is not specified.- Overrides:
toStringin classjava.lang.Object
-
-