package com.google.gson;

import a.e.a.d;
import a.e.a.e;
import a.e.a.i;
import a.e.a.j;
import a.e.a.k;
import a.e.a.r;
import a.e.a.s;
import a.e.a.t;
import a.e.a.u;
import a.e.a.w.g;
import a.e.a.x.a;
import a.e.a.y.b;
import a.e.a.y.c;
import com.google.gson.internal.Excluder;
import com.google.gson.internal.bind.ArrayTypeAdapter;
import com.google.gson.internal.bind.CollectionTypeAdapterFactory;
import com.google.gson.internal.bind.DateTypeAdapter;
import com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory;
import com.google.gson.internal.bind.MapTypeAdapterFactory;
import com.google.gson.internal.bind.ObjectTypeAdapter;
import com.google.gson.internal.bind.ReflectiveTypeAdapterFactory;
import com.google.gson.internal.bind.SqlDateTypeAdapter;
import com.google.gson.internal.bind.TimeTypeAdapter;
import com.google.gson.internal.bind.TypeAdapters;
import java.io.EOFException;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicLongArray;

/* JADX INFO: loaded from: classes.dex */
public final class Gson {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final a<?> f5413a = a.get(Object.class);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ThreadLocal<Map<a<?>, FutureTypeAdapter<?>>> f5414b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Map<a<?>, t<?>> f5415c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final g f5416d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final JsonAdapterAnnotationTypeAdapterFactory f5417e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final List<u> f5418f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final boolean f5419g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final boolean f5420h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final boolean f5421i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final boolean f5422j;
    public final boolean k;

    public static class FutureTypeAdapter<T> extends t<T> {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public t<T> f5425a;

        @Override // a.e.a.t
        public T a(a.e.a.y.a aVar) {
            t<T> tVar = this.f5425a;
            if (tVar != null) {
                return tVar.a(aVar);
            }
            throw new IllegalStateException();
        }

        @Override // a.e.a.t
        public void b(c cVar, T t) {
            t<T> tVar = this.f5425a;
            if (tVar == null) {
                throw new IllegalStateException();
            }
            tVar.b(cVar, t);
        }
    }

    public Gson() {
        this(Excluder.f5427b, a.e.a.c.IDENTITY, Collections.emptyMap(), false, false, false, true, false, false, false, s.DEFAULT, null, 2, 2, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    }

    public Gson(Excluder excluder, d dVar, Map<Type, e<?>> map, boolean z, boolean z2, boolean z3, boolean z4, boolean z5, boolean z6, boolean z7, s sVar, String str, int i2, int i3, List<u> list, List<u> list2, List<u> list3) {
        this.f5414b = new ThreadLocal<>();
        this.f5415c = new ConcurrentHashMap();
        this.f5416d = new g(map);
        this.f5419g = z;
        this.f5420h = z3;
        this.f5421i = z4;
        this.f5422j = z5;
        this.k = z6;
        ArrayList arrayList = new ArrayList();
        arrayList.add(TypeAdapters.Y);
        arrayList.add(ObjectTypeAdapter.f5455a);
        arrayList.add(excluder);
        arrayList.addAll(list3);
        arrayList.add(TypeAdapters.D);
        arrayList.add(TypeAdapters.m);
        arrayList.add(TypeAdapters.f5487g);
        arrayList.add(TypeAdapters.f5489i);
        arrayList.add(TypeAdapters.k);
        final t<Number> tVar = sVar == s.DEFAULT ? TypeAdapters.t : new t<Number>() { // from class: com.google.gson.Gson.3
            @Override // a.e.a.t
            public Number a(a.e.a.y.a aVar) throws IOException {
                if (aVar.Z() != b.NULL) {
                    return Long.valueOf(aVar.S());
                }
                aVar.V();
                return null;
            }

            @Override // a.e.a.t
            public void b(c cVar, Number number) throws IOException {
                Number number2 = number;
                if (number2 == null) {
                    cVar.M();
                } else {
                    cVar.U(number2.toString());
                }
            }
        };
        arrayList.add(new TypeAdapters.AnonymousClass33(Long.TYPE, Long.class, tVar));
        arrayList.add(new TypeAdapters.AnonymousClass33(Double.TYPE, Double.class, z7 ? TypeAdapters.v : new t<Number>(this) { // from class: com.google.gson.Gson.1
            @Override // a.e.a.t
            public Number a(a.e.a.y.a aVar) throws IOException {
                if (aVar.Z() != b.NULL) {
                    return Double.valueOf(aVar.Q());
                }
                aVar.V();
                return null;
            }

            @Override // a.e.a.t
            public void b(c cVar, Number number) throws IOException {
                Number number2 = number;
                if (number2 == null) {
                    cVar.M();
                } else {
                    Gson.a(number2.doubleValue());
                    cVar.T(number2);
                }
            }
        }));
        arrayList.add(new TypeAdapters.AnonymousClass33(Float.TYPE, Float.class, z7 ? TypeAdapters.u : new t<Number>(this) { // from class: com.google.gson.Gson.2
            @Override // a.e.a.t
            public Number a(a.e.a.y.a aVar) throws IOException {
                if (aVar.Z() != b.NULL) {
                    return Float.valueOf((float) aVar.Q());
                }
                aVar.V();
                return null;
            }

            @Override // a.e.a.t
            public void b(c cVar, Number number) throws IOException {
                Number number2 = number;
                if (number2 == null) {
                    cVar.M();
                } else {
                    Gson.a(number2.floatValue());
                    cVar.T(number2);
                }
            }
        }));
        arrayList.add(TypeAdapters.x);
        arrayList.add(TypeAdapters.o);
        arrayList.add(TypeAdapters.q);
        arrayList.add(new TypeAdapters.AnonymousClass32(AtomicLong.class, new TypeAdapter$1(new t<AtomicLong>() { // from class: com.google.gson.Gson.4
            @Override // a.e.a.t
            public AtomicLong a(a.e.a.y.a aVar) {
                return new AtomicLong(((Number) tVar.a(aVar)).longValue());
            }

            @Override // a.e.a.t
            public void b(c cVar, AtomicLong atomicLong) {
                tVar.b(cVar, Long.valueOf(atomicLong.get()));
            }
        })));
        arrayList.add(new TypeAdapters.AnonymousClass32(AtomicLongArray.class, new TypeAdapter$1(new t<AtomicLongArray>() { // from class: com.google.gson.Gson.5
            @Override // a.e.a.t
            public AtomicLongArray a(a.e.a.y.a aVar) throws IOException {
                ArrayList arrayList2 = new ArrayList();
                aVar.a();
                while (aVar.M()) {
                    arrayList2.add(Long.valueOf(((Number) tVar.a(aVar)).longValue()));
                }
                aVar.B();
                int size = arrayList2.size();
                AtomicLongArray atomicLongArray = new AtomicLongArray(size);
                for (int i4 = 0; i4 < size; i4++) {
                    atomicLongArray.set(i4, ((Long) arrayList2.get(i4)).longValue());
                }
                return atomicLongArray;
            }

            @Override // a.e.a.t
            public void b(c cVar, AtomicLongArray atomicLongArray) throws IOException {
                AtomicLongArray atomicLongArray2 = atomicLongArray;
                cVar.i();
                int length = atomicLongArray2.length();
                for (int i4 = 0; i4 < length; i4++) {
                    tVar.b(cVar, Long.valueOf(atomicLongArray2.get(i4)));
                }
                cVar.B();
            }
        })));
        arrayList.add(TypeAdapters.s);
        arrayList.add(TypeAdapters.z);
        arrayList.add(TypeAdapters.F);
        arrayList.add(TypeAdapters.H);
        arrayList.add(new TypeAdapters.AnonymousClass32(BigDecimal.class, TypeAdapters.B));
        arrayList.add(new TypeAdapters.AnonymousClass32(BigInteger.class, TypeAdapters.C));
        arrayList.add(TypeAdapters.J);
        arrayList.add(TypeAdapters.L);
        arrayList.add(TypeAdapters.P);
        arrayList.add(TypeAdapters.R);
        arrayList.add(TypeAdapters.W);
        arrayList.add(TypeAdapters.N);
        arrayList.add(TypeAdapters.f5484d);
        arrayList.add(DateTypeAdapter.f5446a);
        arrayList.add(TypeAdapters.U);
        arrayList.add(TimeTypeAdapter.f5469a);
        arrayList.add(SqlDateTypeAdapter.f5467a);
        arrayList.add(TypeAdapters.S);
        arrayList.add(ArrayTypeAdapter.f5440a);
        arrayList.add(TypeAdapters.f5482b);
        arrayList.add(new CollectionTypeAdapterFactory(this.f5416d));
        arrayList.add(new MapTypeAdapterFactory(this.f5416d, z2));
        JsonAdapterAnnotationTypeAdapterFactory jsonAdapterAnnotationTypeAdapterFactory = new JsonAdapterAnnotationTypeAdapterFactory(this.f5416d);
        this.f5417e = jsonAdapterAnnotationTypeAdapterFactory;
        arrayList.add(jsonAdapterAnnotationTypeAdapterFactory);
        arrayList.add(TypeAdapters.Z);
        arrayList.add(new ReflectiveTypeAdapterFactory(this.f5416d, dVar, excluder, jsonAdapterAnnotationTypeAdapterFactory));
        this.f5418f = Collections.unmodifiableList(arrayList);
    }

    public static void a(double d2) {
        if (Double.isNaN(d2) || Double.isInfinite(d2)) {
            throw new IllegalArgumentException(d2 + " is not a valid double value as per JSON specification. To override this behavior, use GsonBuilder.serializeSpecialFloatingPointValues() method.");
        }
    }

    public <T> T b(a.e.a.y.a aVar, Type type) {
        boolean z = aVar.f4499c;
        boolean z2 = true;
        aVar.f4499c = true;
        try {
            try {
                try {
                    aVar.Z();
                    z2 = false;
                    T tA = f(a.get(type)).a(aVar);
                    aVar.f4499c = z;
                    return tA;
                } catch (IOException e2) {
                    throw new r(e2);
                } catch (AssertionError e3) {
                    AssertionError assertionError = new AssertionError("AssertionError (GSON 2.8.7): " + e3.getMessage());
                    assertionError.initCause(e3);
                    throw assertionError;
                }
            } catch (EOFException e4) {
                if (!z2) {
                    throw new r(e4);
                }
                aVar.f4499c = z;
                return null;
            } catch (IllegalStateException e5) {
                throw new r(e5);
            }
        } catch (Throwable th) {
            aVar.f4499c = z;
            throw th;
        }
    }

    public <T> T c(Reader reader, Type type) {
        a.e.a.y.a aVar = new a.e.a.y.a(reader);
        aVar.f4499c = this.k;
        T t = (T) b(aVar, type);
        if (t != null) {
            try {
                if (aVar.Z() != b.END_DOCUMENT) {
                    throw new j("JSON document was not fully consumed.");
                }
            } catch (a.e.a.y.d e2) {
                throw new r(e2);
            } catch (IOException e3) {
                throw new j(e3);
            }
        }
        return t;
    }

    public <T> T d(String str, Class<T> cls) {
        Object objE = e(str, cls);
        if (cls == Integer.TYPE) {
            cls = (Class<T>) Integer.class;
        } else if (cls == Float.TYPE) {
            cls = (Class<T>) Float.class;
        } else if (cls == Byte.TYPE) {
            cls = (Class<T>) Byte.class;
        } else if (cls == Double.TYPE) {
            cls = (Class<T>) Double.class;
        } else if (cls == Long.TYPE) {
            cls = (Class<T>) Long.class;
        } else if (cls == Character.TYPE) {
            cls = (Class<T>) Character.class;
        } else if (cls == Boolean.TYPE) {
            cls = (Class<T>) Boolean.class;
        } else if (cls == Short.TYPE) {
            cls = (Class<T>) Short.class;
        } else if (cls == Void.TYPE) {
            cls = (Class<T>) Void.class;
        }
        return cls.cast(objE);
    }

    public <T> T e(String str, Type type) {
        if (str == null) {
            return null;
        }
        return (T) c(new StringReader(str), type);
    }

    public <T> t<T> f(a<T> aVar) {
        t<T> tVar = (t) this.f5415c.get(aVar == null ? f5413a : aVar);
        if (tVar != null) {
            return tVar;
        }
        Map<a<?>, FutureTypeAdapter<?>> map = this.f5414b.get();
        boolean z = false;
        if (map == null) {
            map = new HashMap<>();
            this.f5414b.set(map);
            z = true;
        }
        FutureTypeAdapter<?> futureTypeAdapter = map.get(aVar);
        if (futureTypeAdapter != null) {
            return futureTypeAdapter;
        }
        try {
            FutureTypeAdapter<?> futureTypeAdapter2 = new FutureTypeAdapter<>();
            map.put(aVar, futureTypeAdapter2);
            Iterator<u> it = this.f5418f.iterator();
            while (it.hasNext()) {
                t<T> tVarB = it.next().b(this, aVar);
                if (tVarB != null) {
                    if (futureTypeAdapter2.f5425a != null) {
                        throw new AssertionError();
                    }
                    futureTypeAdapter2.f5425a = tVarB;
                    this.f5415c.put(aVar, tVarB);
                    return tVarB;
                }
            }
            throw new IllegalArgumentException("GSON (2.8.7) cannot handle " + aVar);
        } finally {
            map.remove(aVar);
            if (z) {
                this.f5414b.remove();
            }
        }
    }

    public <T> t<T> g(u uVar, a<T> aVar) {
        if (!this.f5418f.contains(uVar)) {
            uVar = this.f5417e;
        }
        boolean z = false;
        for (u uVar2 : this.f5418f) {
            if (z) {
                t<T> tVarB = uVar2.b(this, aVar);
                if (tVarB != null) {
                    return tVarB;
                }
            } else if (uVar2 == uVar) {
                z = true;
            }
        }
        throw new IllegalArgumentException("GSON cannot serialize " + aVar);
    }

    public c h(Writer writer) throws IOException {
        if (this.f5420h) {
            writer.write(")]}'\n");
        }
        c cVar = new c(writer);
        if (this.f5422j) {
            cVar.f4512g = "  ";
            cVar.f4513h = ": ";
        }
        cVar.l = this.f5419g;
        return cVar;
    }

    public String i(Object obj) {
        if (obj == null) {
            i iVar = k.f4436a;
            StringWriter stringWriter = new StringWriter();
            try {
                j(iVar, h(stringWriter));
                return stringWriter.toString();
            } catch (IOException e2) {
                throw new j(e2);
            }
        }
        Type type = obj.getClass();
        StringWriter stringWriter2 = new StringWriter();
        try {
            k(obj, type, h(stringWriter2));
            return stringWriter2.toString();
        } catch (IOException e3) {
            throw new j(e3);
        }
    }

    public void j(i iVar, c cVar) {
        boolean z = cVar.f4514i;
        cVar.f4514i = true;
        boolean z2 = cVar.f4515j;
        cVar.f4515j = this.f5421i;
        boolean z3 = cVar.l;
        cVar.l = this.f5419g;
        try {
            try {
                TypeAdapters.X.b(cVar, iVar);
            } catch (IOException e2) {
                throw new j(e2);
            } catch (AssertionError e3) {
                AssertionError assertionError = new AssertionError("AssertionError (GSON 2.8.7): " + e3.getMessage());
                assertionError.initCause(e3);
                throw assertionError;
            }
        } finally {
            cVar.f4514i = z;
            cVar.f4515j = z2;
            cVar.l = z3;
        }
    }

    public void k(Object obj, Type type, c cVar) {
        t tVarF = f(a.get(type));
        boolean z = cVar.f4514i;
        cVar.f4514i = true;
        boolean z2 = cVar.f4515j;
        cVar.f4515j = this.f5421i;
        boolean z3 = cVar.l;
        cVar.l = this.f5419g;
        try {
            try {
                try {
                    tVarF.b(cVar, obj);
                } catch (IOException e2) {
                    throw new j(e2);
                }
            } catch (AssertionError e3) {
                AssertionError assertionError = new AssertionError("AssertionError (GSON 2.8.7): " + e3.getMessage());
                assertionError.initCause(e3);
                throw assertionError;
            }
        } finally {
            cVar.f4514i = z;
            cVar.f4515j = z2;
            cVar.l = z3;
        }
    }

    public String toString() {
        return "{serializeNulls:" + this.f5419g + ",factories:" + this.f5418f + ",instanceCreators:" + this.f5416d + "}";
    }
}
