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

328 lines
11 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.base;
import java.io.Serializable;
import java.util.Iterator;
/* loaded from: classes2.dex */
public abstract class Converter<A, B> implements Function<A, B> {
private final boolean handleNullAutomatically;
private transient Converter<B, A> reverse;
protected abstract A doBackward(B b);
protected abstract B doForward(A a);
public Converter() {
this(true);
}
Converter(boolean z) {
this.handleNullAutomatically = z;
}
public final B convert(A a) {
return correctedDoForward(a);
}
B correctedDoForward(A a) {
if (!this.handleNullAutomatically) {
return doForward(a);
}
if (a == null) {
return null;
}
return (B) Preconditions.checkNotNull(doForward(a));
}
A correctedDoBackward(B b) {
if (!this.handleNullAutomatically) {
return doBackward(b);
}
if (b == null) {
return null;
}
return (A) Preconditions.checkNotNull(doBackward(b));
}
/* renamed from: com.google.common.base.Converter$1, reason: invalid class name */
/* loaded from: classes2.dex */
class AnonymousClass1 implements Iterable<B> {
final Converter this$0;
final Iterable val$fromIterable;
AnonymousClass1(Converter converter, Iterable iterable) {
this.this$0 = converter;
this.val$fromIterable = iterable;
}
@Override // java.lang.Iterable
public Iterator<B> iterator() {
return new Iterator<B>(this) { // from class: com.google.common.base.Converter.1.1
private final Iterator<? extends A> fromIterator;
final AnonymousClass1 this$1;
{
this.this$1 = this;
this.fromIterator = this.val$fromIterable.iterator();
}
@Override // java.util.Iterator
public boolean hasNext() {
return this.fromIterator.hasNext();
}
@Override // java.util.Iterator
public B next() {
return (B) this.this$1.this$0.convert(this.fromIterator.next());
}
@Override // java.util.Iterator
public void remove() {
this.fromIterator.remove();
}
};
}
}
public Iterable<B> convertAll(Iterable<? extends A> iterable) {
Preconditions.checkNotNull(iterable, "fromIterable");
return new AnonymousClass1(this, iterable);
}
public Converter<B, A> reverse() {
Converter<B, A> converter = this.reverse;
if (converter != null) {
return converter;
}
ReverseConverter reverseConverter = new ReverseConverter(this);
this.reverse = reverseConverter;
return reverseConverter;
}
/* loaded from: classes2.dex */
static final class ReverseConverter<A, B> extends Converter<B, A> implements Serializable {
private static final long serialVersionUID = 0;
final Converter<A, B> original;
ReverseConverter(Converter<A, B> converter) {
this.original = converter;
}
@Override // com.google.common.base.Converter
protected final A doForward(B b) {
throw new AssertionError();
}
@Override // com.google.common.base.Converter
protected final B doBackward(A a) {
throw new AssertionError();
}
@Override // com.google.common.base.Converter
final A correctedDoForward(B b) {
return this.original.correctedDoBackward(b);
}
@Override // com.google.common.base.Converter
final B correctedDoBackward(A a) {
return this.original.correctedDoForward(a);
}
@Override // com.google.common.base.Converter, com.google.common.base.Function
public final boolean equals(Object obj) {
if (obj instanceof ReverseConverter) {
return this.original.equals(((ReverseConverter) obj).original);
}
return false;
}
public final int hashCode() {
return ~this.original.hashCode();
}
public final String toString() {
String valueOf = String.valueOf(this.original);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 10);
sb.append(valueOf);
sb.append(".reverse()");
return sb.toString();
}
@Override // com.google.common.base.Converter
public final Converter<A, B> reverse() {
return this.original;
}
}
public final <C> Converter<A, C> andThen(Converter<B, C> converter) {
return doAndThen(converter);
}
<C> Converter<A, C> doAndThen(Converter<B, C> converter) {
return new ConverterComposition(this, (Converter) Preconditions.checkNotNull(converter));
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class ConverterComposition<A, B, C> extends Converter<A, C> implements Serializable {
private static final long serialVersionUID = 0;
final Converter<A, B> first;
final Converter<B, C> second;
ConverterComposition(Converter<A, B> converter, Converter<B, C> converter2) {
this.first = converter;
this.second = converter2;
}
@Override // com.google.common.base.Converter
protected final C doForward(A a) {
throw new AssertionError();
}
@Override // com.google.common.base.Converter
protected final A doBackward(C c) {
throw new AssertionError();
}
@Override // com.google.common.base.Converter
final C correctedDoForward(A a) {
return (C) this.second.correctedDoForward(this.first.correctedDoForward(a));
}
@Override // com.google.common.base.Converter
final A correctedDoBackward(C c) {
return (A) this.first.correctedDoBackward(this.second.correctedDoBackward(c));
}
@Override // com.google.common.base.Converter, com.google.common.base.Function
public final boolean equals(Object obj) {
if (!(obj instanceof ConverterComposition)) {
return false;
}
ConverterComposition converterComposition = (ConverterComposition) obj;
return this.first.equals(converterComposition.first) && this.second.equals(converterComposition.second);
}
public final int hashCode() {
return (this.first.hashCode() * 31) + this.second.hashCode();
}
public final String toString() {
String valueOf = String.valueOf(this.first);
String valueOf2 = String.valueOf(this.second);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 10 + String.valueOf(valueOf2).length());
sb.append(valueOf);
sb.append(".andThen(");
sb.append(valueOf2);
sb.append(")");
return sb.toString();
}
}
@Override // com.google.common.base.Function
@Deprecated
public final B apply(A a) {
return convert(a);
}
@Override // com.google.common.base.Function
public boolean equals(Object obj) {
return super.equals(obj);
}
public static <A, B> Converter<A, B> from(Function<? super A, ? extends B> function, Function<? super B, ? extends A> function2) {
return new FunctionBasedConverter(function, function2, null);
}
/* loaded from: classes2.dex */
static final class FunctionBasedConverter<A, B> extends Converter<A, B> implements Serializable {
private final Function<? super B, ? extends A> backwardFunction;
private final Function<? super A, ? extends B> forwardFunction;
/* synthetic */ FunctionBasedConverter(Function function, Function function2, AnonymousClass1 anonymousClass1) {
this(function, function2);
}
private FunctionBasedConverter(Function<? super A, ? extends B> function, Function<? super B, ? extends A> function2) {
this.forwardFunction = (Function) Preconditions.checkNotNull(function);
this.backwardFunction = (Function) Preconditions.checkNotNull(function2);
}
@Override // com.google.common.base.Converter
protected final B doForward(A a) {
return this.forwardFunction.apply(a);
}
@Override // com.google.common.base.Converter
protected final A doBackward(B b) {
return this.backwardFunction.apply(b);
}
@Override // com.google.common.base.Converter, com.google.common.base.Function
public final boolean equals(Object obj) {
if (!(obj instanceof FunctionBasedConverter)) {
return false;
}
FunctionBasedConverter functionBasedConverter = (FunctionBasedConverter) obj;
return this.forwardFunction.equals(functionBasedConverter.forwardFunction) && this.backwardFunction.equals(functionBasedConverter.backwardFunction);
}
public final int hashCode() {
return (this.forwardFunction.hashCode() * 31) + this.backwardFunction.hashCode();
}
public final String toString() {
String valueOf = String.valueOf(this.forwardFunction);
String valueOf2 = String.valueOf(this.backwardFunction);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 18 + String.valueOf(valueOf2).length());
sb.append("Converter.from(");
sb.append(valueOf);
sb.append(", ");
sb.append(valueOf2);
sb.append(")");
return sb.toString();
}
}
public static <T> Converter<T, T> identity() {
return IdentityConverter.INSTANCE;
}
/* loaded from: classes2.dex */
static final class IdentityConverter<T> extends Converter<T, T> implements Serializable {
static final IdentityConverter<?> INSTANCE = new IdentityConverter<>();
private static final long serialVersionUID = 0;
@Override // com.google.common.base.Converter
protected final T doBackward(T t) {
return t;
}
@Override // com.google.common.base.Converter
protected final T doForward(T t) {
return t;
}
@Override // com.google.common.base.Converter
public final IdentityConverter<T> reverse() {
return this;
}
private IdentityConverter() {
}
@Override // com.google.common.base.Converter
final <S> Converter<T, S> doAndThen(Converter<T, S> converter) {
return (Converter) Preconditions.checkNotNull(converter, "otherConverter");
}
public final String toString() {
return "Converter.identity()";
}
private Object readResolve() {
return INSTANCE;
}
}
}