Class Equivalence<T>
java.lang.Object
org.docx4j.com.google.common.base.Equivalence<T>
- All Implemented Interfaces:
BiPredicate<T,T>
A strategy for determining whether two instances are considered equivalent, and for computing
hash codes in a manner consistent with that equivalence. Two examples of equivalences are the
identity equivalence and the "equals" equivalence.
- Since:
- 10.0 (mostly source-compatible since 4.0)
- Author:
- Bob Lee, Ben Yu, Gregory Kick
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classWraps an object so thatEquivalence.Wrapper.equals(Object)andEquivalence.Wrapper.hashCode()delegate to anEquivalence. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleandoEquivalent(T a, T b) Implemented by the user to determine whetheraandbare considered equivalent, subject to the requirements specified inequivalent(T, T).protected abstract intImplemented by the user to return a hash code fort, subject to the requirements specified inhash(T).static Equivalence<Object>equals()Returns an equivalence that delegates toObject.equals(java.lang.Object)andObject.hashCode().final booleanequivalent(@Nullable T a, @Nullable T b) Returnstrueif the given objects are considered equivalent.equivalentTo(@Nullable T target) Returns a predicate that evaluates to true if and only if the input is equivalent totargetaccording to this equivalence relation.final intReturns a hash code fort.static Equivalence<Object>identity()Returns an equivalence that uses==to compare values andSystem.identityHashCode(Object)to compute the hash code.final booleanDeprecated.final <S extends T>
Equivalence.Wrapper<S>wrap(@Nullable S reference) Returns a wrapper ofreferencethat implementsObject.equals()such thatwrap(a).equals(wrap(b))if and only ifequivalent(a, b).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.BiPredicate
and, negate, or
-
Constructor Details
-
Equivalence
protected Equivalence()Constructor for use by subclasses.
-
-
Method Details
-
equivalent
Returnstrueif the given objects are considered equivalent.This method describes an equivalence relation on object references, meaning that for all references
x,y, andz(any of which may be null):equivalent(x, x)is true (reflexive property)equivalent(x, y)andequivalent(y, x)each return the same result (symmetric property)- If
equivalent(x, y)andequivalent(y, z)are both true, thenequivalent(x, z)is also true (transitive property)
Note that all calls to
equivalent(x, y)are expected to return the same result as long as neitherxnoryis modified. -
test
Deprecated.Provided only to satisfy theBiPredicateinterface; useequivalent(T, T)instead.- Specified by:
testin interfaceBiPredicate<T,T> - Since:
- 21.0
-
doEquivalent
Implemented by the user to determine whetheraandbare considered equivalent, subject to the requirements specified inequivalent(T, T).This method should not be called except by
equivalent(T, T). Whenequivalent(T, T)calls this method,aandbare guaranteed to be distinct, non-null instances.- Since:
- 10.0 (previously, subclasses would override equivalent())
-
hash
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 across equivalence: for any references
xandy, 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
Implemented by the user to return a hash code fort, subject to the requirements specified inhash(T).This method should not be called except by
hash(T). Whenhash(T)calls this method,tis guaranteed to be non-null.- Since:
- 10.0 (previously, subclasses would override hash())
-
wrap
Returns a wrapper ofreferencethat implementsObject.equals()such thatwrap(a).equals(wrap(b))if and only ifequivalent(a, b).- Since:
- 10.0
-
equivalentTo
Returns a predicate that evaluates to true if and only if the input is equivalent totargetaccording to this equivalence relation.- Since:
- 10.0
-
equals
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
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)
-
BiPredicateinterface; useequivalent(T, T)instead.