diff options
Diffstat (limited to 'guava/src/com/google/common/base/Equivalence.java')
-rw-r--r-- | guava/src/com/google/common/base/Equivalence.java | 74 |
1 files changed, 6 insertions, 68 deletions
diff --git a/guava/src/com/google/common/base/Equivalence.java b/guava/src/com/google/common/base/Equivalence.java index 339bec0..f6e89bd 100644 --- a/guava/src/com/google/common/base/Equivalence.java +++ b/guava/src/com/google/common/base/Equivalence.java @@ -27,8 +27,8 @@ import javax.annotation.Nullable; /** * A strategy for determining whether two instances are considered equivalent. Examples of - * equivalences are the {@linkplain #identity() identity equivalence} and {@linkplain #equals equals - * equivalence}. + * equivalences are the {@link Equivalences#identity() identity equivalence} and {@link + * Equivalences#equals equals equivalence}. * * @author Bob Lee * @author Ben Yu @@ -36,6 +36,7 @@ import javax.annotation.Nullable; * @since 10.0 (<a href="http://code.google.com/p/guava-libraries/wiki/Compatibility" * >mostly source-compatible</a> since 4.0) */ +@Beta @GwtCompatible public abstract class Equivalence<T> { /** @@ -122,7 +123,7 @@ public abstract class Equivalence<T> { * * <p>For example: <pre> {@code * - * Equivalence<Person> SAME_AGE = Equivalence.equals().onResultOf(GET_PERSON_AGE); + * Equivalence<Person> SAME_AGE = Equivalences.equals().onResultOf(GET_PERSON_AGE); * }</pre> * * <p>{@code function} will never be invoked with a null value. @@ -130,7 +131,7 @@ public abstract class Equivalence<T> { * <p>Note that {@code function} must be consistent according to {@code this} equivalence * relation. That is, invoking {@link Function#apply} multiple times for a given value must return * equivalent results. - * For example, {@code Equivalence.identity().onResultOf(Functions.toStringFunction())} is broken + * For example, {@code Equivalences.identity().onResultOf(Functions.toStringFunction())} is broken * because it's not guaranteed that {@link Object#toString}) always returns the same string * instance. * @@ -171,6 +172,7 @@ public abstract class Equivalence<T> { * * @since 10.0 */ + @Beta public static final class Wrapper<T> implements Serializable { private final Equivalence<? super T> equivalence; @Nullable private final T reference; @@ -251,7 +253,6 @@ public abstract class Equivalence<T> { * * @since 10.0 */ - @Beta public final Predicate<T> equivalentTo(@Nullable T target) { return new EquivalentToPredicate<T>(this, target); } @@ -292,67 +293,4 @@ public abstract class Equivalence<T> { private static final long serialVersionUID = 0; } - - /** - * Returns an equivalence that delegates to {@link Object#equals} and {@link Object#hashCode}. - * {@link Equivalence#equivalent} returns {@code true} if both values are null, or if neither - * value is null and {@link Object#equals} returns {@code true}. {@link Equivalence#hash} returns - * {@code 0} if passed a null value. - * - * @since 13.0 - * @since 8.0 (in Equivalences with null-friendly behavior) - * @since 4.0 (in Equivalences) - */ - public static Equivalence<Object> equals() { - return Equals.INSTANCE; - } - - /** - * Returns an equivalence that uses {@code ==} to compare values and {@link - * System#identityHashCode(Object)} to compute the hash code. {@link Equivalence#equivalent} - * returns {@code true} if {@code a == b}, including in the case that a and b are both null. - * - * @since 13.0 - * @since 4.0 (in Equivalences) - */ - public static Equivalence<Object> identity() { - return Identity.INSTANCE; - } - - static final class Equals extends Equivalence<Object> - implements Serializable { - - static final Equals INSTANCE = new Equals(); - - @Override protected boolean doEquivalent(Object a, Object b) { - return a.equals(b); - } - @Override public int doHash(Object o) { - return o.hashCode(); - } - - private Object readResolve() { - return INSTANCE; - } - private static final long serialVersionUID = 1; - } - - static final class Identity extends Equivalence<Object> - implements Serializable { - - static final Identity INSTANCE = new Identity(); - - @Override protected boolean doEquivalent(Object a, Object b) { - return false; - } - - @Override protected int doHash(Object o) { - return System.identityHashCode(o); - } - - private Object readResolve() { - return INSTANCE; - } - private static final long serialVersionUID = 1; - } } |