Package com.google.common.base
Class Equivalence<T>
java.lang.Object
com.google.common.base.Equivalence<T>
Deprecated.
The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023
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)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDeprecated.The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023 -
Method Summary
Modifier and TypeMethodDescriptionstatic Equivalence<Object> equals()Deprecated.Returns an equivalence that delegates toObject.equals(java.lang.Object)andObject.hashCode().final booleanequivalent(T a, T b) Deprecated.Returnstrueif the given objects are considered equivalent.equivalentTo(T target) Deprecated.Returns a predicate that evaluates to true if and only if the input is equivalent totargetaccording to this equivalence relation.final intDeprecated.Returns a hash code fort.static Equivalence<Object> identity()Deprecated.Returns an equivalence that uses==to compare values andSystem.identityHashCode(Object)to compute the hash code.final <F> Equivalence<F> onResultOf(Function<F, ? extends T> function) Deprecated.Returns a new equivalence relation forFwhich evaluates equivalence by first applyingfunctionto the argument, then evaluating usingthis.final <S extends T>
Equivalence<Iterable<S>> pairwise()Deprecated.Returns an equivalence over iterables based on the equivalence of their elements.final <S extends T>
Equivalence.Wrapper<S> wrap(S reference) Deprecated.Returns a wrapper ofreferencethat implementsObject.equals()such thatwrap(this, a).equals(wrap(this, b))if and only ifthis.equivalent(a, b).
-
Method Details
-
equivalent
Deprecated.Returnstrueif the given objects are considered equivalent.The
equivalentmethod 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
xandy,equivalent(x, y) == equivalent(y, x). - It is transitive: for any references
x,y, andz, ifequivalent(x, y)returnstrueandequivalent(y, z)returnstrue, thenequivalent(x, z)returnstrue. - It is consistent: for any references
xandy, multiple invocations ofequivalent(x, y)consistently returntrueor consistently returnfalse(provided that neitherxnoryis modified).
- It is reflexive: for any reference
-
hash
Deprecated.Returns a hash code fort.The
hashhas the following properties:- It is consistent: for any reference
x, multiple invocations ofhash(x} consistently return the same value providedxremains 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 accross equivalence: for any references
xandy, ifequivalent(x, y), thenhash(x) == hash(y). It is not necessary that the hash be distributable accorss inequivalence. Ifequivalence(x, y)is false,hash(x) == hash(y)may still be true. hash(null)is0.
- It is consistent: for any reference
-
onResultOf
Deprecated.Returns a new equivalence relation forFwhich evaluates equivalence by first applyingfunctionto the argument, then evaluating usingthis. That is, for any pair of non-null objectsxandy,equivalence.onResultOf(function).equivalent(a, b)is true if and only ifequivalence.equivalent(function.apply(a), function.apply(b))is true.For example:
Equivalence<Person> SAME_AGE = Equivalence.equals().onResultOf(GET_PERSON_AGE);functionwill never be invoked with a null value.Note that
functionmust be consistent according tothisequivalence relation. That is, invokingFunction.apply(F)multiple times for a given value must return equivalent results. For example,Equivalence.identity().onResultOf(Functions.toStringFunction())is broken because it's not guaranteed thatObject.toString()) always returns the same string instance.- Since:
- 10.0
-
wrap
Deprecated.Returns a wrapper ofreferencethat implementsObject.equals()such thatwrap(this, a).equals(wrap(this, b))if and only ifthis.equivalent(a, b).- Since:
- 10.0
-
pairwise
Deprecated.Returns an equivalence over iterables based on the equivalence of their elements. More specifically, two iterables are considered equivalent if they both contain the same number of elements, and each pair of corresponding elements is equivalent according tothis. Null iterables are equivalent to one another.Note that this method performs a similar function for equivalences as
Ordering.lexicographical()does for orderings.- Since:
- 10.0
-
equivalentTo
Deprecated.Returns a predicate that evaluates to true if and only if the input is equivalent totargetaccording to this equivalence relation.- Since:
- 10.0
-
equals
Deprecated.Returns an equivalence that delegates toObject.equals(java.lang.Object)andObject.hashCode().equivalent(T, T)returnstrueif both values are null, or if neither value is null andObject.equals(java.lang.Object)returnstrue.hash(T)returns0if passed a null value.- Since:
- 13.0, 8.0 (in Equivalences with null-friendly behavior), 4.0 (in Equivalences)
-
identity
Deprecated.Returns an equivalence that uses==to compare values andSystem.identityHashCode(Object)to compute the hash code.equivalent(T, T)returnstrueifa == b, including in the case that a and b are both null.- Since:
- 13.0, 4.0 (in Equivalences)
-