package com.google.common.base; import java.io.Serializable; import java.util.Iterator; /* loaded from: classes2.dex */ public abstract class Converter implements Function { private final boolean handleNullAutomatically; private transient Converter 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 { 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 iterator() { return new Iterator(this) { // from class: com.google.common.base.Converter.1.1 private final Iterator 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 convertAll(Iterable iterable) { Preconditions.checkNotNull(iterable, "fromIterable"); return new AnonymousClass1(this, iterable); } public Converter reverse() { Converter 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 extends Converter implements Serializable { private static final long serialVersionUID = 0; final Converter original; ReverseConverter(Converter 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 reverse() { return this.original; } } public final Converter andThen(Converter converter) { return doAndThen(converter); } Converter doAndThen(Converter 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 extends Converter implements Serializable { private static final long serialVersionUID = 0; final Converter first; final Converter second; ConverterComposition(Converter converter, Converter 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 Converter from(Function function, Function function2) { return new FunctionBasedConverter(function, function2, null); } /* loaded from: classes2.dex */ static final class FunctionBasedConverter extends Converter implements Serializable { private final Function backwardFunction; private final Function forwardFunction; /* synthetic */ FunctionBasedConverter(Function function, Function function2, AnonymousClass1 anonymousClass1) { this(function, function2); } private FunctionBasedConverter(Function function, Function 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 Converter identity() { return IdentityConverter.INSTANCE; } /* loaded from: classes2.dex */ static final class IdentityConverter extends Converter 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 reverse() { return this; } private IdentityConverter() { } @Override // com.google.common.base.Converter final Converter doAndThen(Converter converter) { return (Converter) Preconditions.checkNotNull(converter, "otherConverter"); } public final String toString() { return "Converter.identity()"; } private Object readResolve() { return INSTANCE; } } }