Rabbit-R1/android (non root)/java/sources/com/google/common/base/Equivalence.java
2024-05-21 17:08:36 -04:00

184 lines
5.9 KiB
Java

package com.google.common.base;
import java.io.Serializable;
import javax.annotation.CheckForNull;
@ElementTypesAreNonnullByDefault
/* loaded from: classes2.dex */
public abstract class Equivalence<T> {
protected abstract boolean doEquivalent(T t, T t2);
protected abstract int doHash(T t);
public final boolean equivalent(@CheckForNull T t, @CheckForNull T t2) {
if (t == t2) {
return true;
}
if (t == null || t2 == null) {
return false;
}
return doEquivalent(t, t2);
}
public final int hash(@CheckForNull T t) {
if (t == null) {
return 0;
}
return doHash(t);
}
public final <F> Equivalence<F> onResultOf(Function<? super F, ? extends T> function) {
return new FunctionalEquivalence(function, this);
}
public final <S extends T> Wrapper<S> wrap(@ParametricNullness S s) {
return new Wrapper<>(s);
}
/* loaded from: classes2.dex */
public static final class Wrapper<T> implements Serializable {
private static final long serialVersionUID = 0;
private final Equivalence<? super T> equivalence;
@ParametricNullness
private final T reference;
@ParametricNullness
public T get() {
return this.reference;
}
private Wrapper(Equivalence<? super T> equivalence, @ParametricNullness T t) {
this.equivalence = (Equivalence) Preconditions.checkNotNull(equivalence);
this.reference = t;
}
public boolean equals(@CheckForNull Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Wrapper)) {
return false;
}
Wrapper wrapper = (Wrapper) obj;
if (this.equivalence.equals(wrapper.equivalence)) {
return this.equivalence.equivalent(this.reference, wrapper.reference);
}
return false;
}
public int hashCode() {
return this.equivalence.hash(this.reference);
}
public String toString() {
String valueOf = String.valueOf(this.equivalence);
String valueOf2 = String.valueOf(this.reference);
return new StringBuilder(String.valueOf(valueOf).length() + 7 + String.valueOf(valueOf2).length()).append(valueOf).append(".wrap(").append(valueOf2).append(")").toString();
}
}
public final <S extends T> Equivalence<Iterable<S>> pairwise() {
return new PairwiseEquivalence(this);
}
public final Predicate<T> equivalentTo(@CheckForNull T t) {
return new EquivalentToPredicate(this, t);
}
/* loaded from: classes2.dex */
private static final class EquivalentToPredicate<T> implements Predicate<T>, Serializable {
private static final long serialVersionUID = 0;
private final Equivalence<T> equivalence;
@CheckForNull
private final T target;
EquivalentToPredicate(Equivalence<T> equivalence, @CheckForNull T t) {
this.equivalence = (Equivalence) Preconditions.checkNotNull(equivalence);
this.target = t;
}
@Override // com.google.common.base.Predicate
public boolean apply(@CheckForNull T t) {
return this.equivalence.equivalent(t, this.target);
}
@Override // com.google.common.base.Predicate
public boolean equals(@CheckForNull Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof EquivalentToPredicate)) {
return false;
}
EquivalentToPredicate equivalentToPredicate = (EquivalentToPredicate) obj;
return this.equivalence.equals(equivalentToPredicate.equivalence) && Objects.equal(this.target, equivalentToPredicate.target);
}
public int hashCode() {
return Objects.hashCode(this.equivalence, this.target);
}
public String toString() {
String valueOf = String.valueOf(this.equivalence);
String valueOf2 = String.valueOf(this.target);
return new StringBuilder(String.valueOf(valueOf).length() + 15 + String.valueOf(valueOf2).length()).append(valueOf).append(".equivalentTo(").append(valueOf2).append(")").toString();
}
}
public static Equivalence<Object> equals() {
return Equals.INSTANCE;
}
public static Equivalence<Object> identity() {
return Identity.INSTANCE;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class Equals extends Equivalence<Object> implements Serializable {
static final Equals INSTANCE = new Equals();
private static final long serialVersionUID = 1;
private Object readResolve() {
return INSTANCE;
}
Equals() {
}
@Override // com.google.common.base.Equivalence
protected boolean doEquivalent(Object obj, Object obj2) {
return obj.equals(obj2);
}
@Override // com.google.common.base.Equivalence
protected int doHash(Object obj) {
return obj.hashCode();
}
}
/* loaded from: classes2.dex */
static final class Identity extends Equivalence<Object> implements Serializable {
static final Identity INSTANCE = new Identity();
private static final long serialVersionUID = 1;
private Object readResolve() {
return INSTANCE;
}
@Override // com.google.common.base.Equivalence
protected boolean doEquivalent(Object obj, Object obj2) {
return false;
}
Identity() {
}
@Override // com.google.common.base.Equivalence
protected int doHash(Object obj) {
return System.identityHashCode(obj);
}
}
}