Class Equivalence<T>
java.lang.Object
org.glassfish.jersey.internal.guava.Equivalence<T>
A strategy for determining whether two instances are considered equivalent. Examples of
equivalences are the identity equivalence and equals
equivalence.
- Since:
- 10.0 (mostly source-compatible since 4.0)
- Author:
- Bob Lee, Ben Yu, Gregory Kick
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
doEquivalent
(T a, T b) Returnstrue
ifa
andb
are considered equivalent.protected abstract int
Returns a hash code for non-null objectt
.static Equivalence<Object>
equals()
Returns an equivalence that delegates toObject.equals(java.lang.Object)
andObject.hashCode()
.final boolean
equivalent
(T a, T b) Returnstrue
if the given objects are considered equivalent.final int
Returns a hash code fort
.static Equivalence<Object>
identity()
Returns an equivalence that uses==
to compare values andSystem.identityHashCode(Object)
to compute the hash code.
-
Constructor Details
-
Equivalence
public Equivalence()
-
-
Method Details
-
equals
Returns an equivalence that delegates toObject.equals(java.lang.Object)
andObject.hashCode()
.equivalent(T, T)
returnstrue
if both values are null, or if neither value is null andObject.equals(java.lang.Object)
returnstrue
.hash(T)
returns0
if passed a null value.- Since:
- 4.0 (in Equivalences)
-
identity
Returns an equivalence that uses==
to compare values andSystem.identityHashCode(Object)
to compute the hash code.equivalent(T, T)
returnstrue
ifa == b
, including in the case that a and b are both null.- Since:
- 4.0 (in Equivalences)
-
equivalent
Returnstrue
if the given objects are considered equivalent.The
equivalent
method implements an equivalence relation on object references:- It is reflexive: for any reference
x
, including null,equivalent(x, x)
returnstrue
. - It is symmetric: for any references
x
andy
,equivalent(x, y) == equivalent(y, x)
. - It is transitive: for any references
x
,y
, andz
, ifequivalent(x, y)
returnstrue
andequivalent(y, z)
returnstrue
, thenequivalent(x, z)
returnstrue
. - It is consistent: for any references
x
andy
, multiple invocations ofequivalent(x, y)
consistently returntrue
or consistently returnfalse
(provided that neitherx
nory
is modified).
- It is reflexive: for any reference
-
doEquivalent
Returnstrue
ifa
andb
are considered equivalent.Called by
equivalent(T, T)
.a
andb
are not the same object and are not nulls.- Since:
- 10.0 (previously, subclasses would override equivalent())
-
hash
Returns a hash code fort
.The
hash
has the following properties:- It is consistent: for any reference
x
, multiple invocations ofhash(x
} consistently return the same value providedx
remains unchanged according to the definition of the equivalence. The hash need not remain consistent from one execution of an application to another execution of the same application. - It is distributable across equivalence: for any references
x
andy
, ifequivalent(x, y)
, thenhash(x) == hash(y)
. It is not necessary that the hash be distributable across inequivalence. Ifequivalence(x, y)
is false,hash(x) == hash(y)
may still be true. hash(null)
is0
.
- It is consistent: for any reference
-
doHash
- Since:
- 10.0 (previously, subclasses would override hash())
-