what-the-bank/sources/com/google/common/base/FunctionalEquivalence.java

53 lines
2.0 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.base;
import java.io.Serializable;
/* loaded from: classes2.dex */
final class FunctionalEquivalence<F, T> extends Equivalence<F> implements Serializable {
private static final long serialVersionUID = 0;
private final Function<F, ? extends T> function;
private final Equivalence<T> resultEquivalence;
/* JADX INFO: Access modifiers changed from: package-private */
public FunctionalEquivalence(Function<F, ? extends T> function, Equivalence<T> equivalence) {
this.function = (Function) Preconditions.checkNotNull(function);
this.resultEquivalence = (Equivalence) Preconditions.checkNotNull(equivalence);
}
@Override // com.google.common.base.Equivalence
protected final boolean doEquivalent(F f, F f2) {
return this.resultEquivalence.equivalent(this.function.apply(f), this.function.apply(f2));
}
@Override // com.google.common.base.Equivalence
protected final int doHash(F f) {
return this.resultEquivalence.hash(this.function.apply(f));
}
public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof FunctionalEquivalence)) {
return false;
}
FunctionalEquivalence functionalEquivalence = (FunctionalEquivalence) obj;
return this.function.equals(functionalEquivalence.function) && this.resultEquivalence.equals(functionalEquivalence.resultEquivalence);
}
public final int hashCode() {
return Objects.hashCode(this.function, this.resultEquivalence);
}
public final String toString() {
String valueOf = String.valueOf(this.resultEquivalence);
String valueOf2 = String.valueOf(this.function);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 13 + String.valueOf(valueOf2).length());
sb.append(valueOf);
sb.append(".onResultOf(");
sb.append(valueOf2);
sb.append(")");
return sb.toString();
}
}