public static final class Equivalence.Wrapper<T>
extends java.lang.Object
implements java.io.Serializable
equals(Object)
and hashCode()
delegate to an
Equivalence
.
For example, given an Equivalence
for strings
named equiv
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
Modifier and Type | Field and Description |
---|---|
private Equivalence<? super T> |
equivalence |
private T |
reference |
private static long |
serialVersionUID |
Modifier | Constructor and Description |
---|---|
private |
Wrapper(Equivalence<? super T> equivalence,
T reference) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Returns
true if Equivalence.equivalent(Object, Object) applied to the wrapped
references is true and both wrappers use the same
equivalence. |
T |
get()
Returns the (possibly null) reference wrapped by this instance.
|
int |
hashCode()
Returns the result of
Equivalence.hash(Object) applied to the wrapped reference. |
java.lang.String |
toString()
Returns a string representation for this equivalence wrapper.
|
private final Equivalence<? super T> equivalence
@Nullable private final T reference
private static final long serialVersionUID
private Wrapper(Equivalence<? super T> equivalence, @Nullable T reference)
@Nullable public T get()
public boolean equals(@Nullable java.lang.Object obj)
true
if Equivalence.equivalent(Object, Object)
applied to the wrapped
references is true
and both wrappers use the same
equivalence.equals
in class java.lang.Object
public int hashCode()
Equivalence.hash(Object)
applied to the wrapped reference.hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object