package g.e.b;

import java.io.EOFException;
import java.io.IOException;
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 j {
    public static final g.e.b.h0.a<?> a = new g.e.b.h0.a<>(Object.class);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ThreadLocal<Map<g.e.b.h0.a<?>, a<?>>> f4206b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Map<g.e.b.h0.a<?>, d0<?>> f4207c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final g.e.b.g0.l f4208d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final g.e.b.g0.f0.e f4209e;

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Map<Type, k<?>> f4211g;

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

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

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

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

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final List<e0> f4217m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final List<e0> f4218n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final List<z> f4219o;

    public static class a<T> extends d0<T> {
        public d0<T> a;

        @Override // g.e.b.d0
        public T a(g.e.b.i0.a aVar) {
            d0<T> d0Var = this.a;
            if (d0Var != null) {
                return d0Var.a(aVar);
            }
            throw new IllegalStateException();
        }

        @Override // g.e.b.d0
        public void b(g.e.b.i0.c cVar, T t2) {
            d0<T> d0Var = this.a;
            if (d0Var == null) {
                throw new IllegalStateException();
            }
            d0Var.b(cVar, t2);
        }
    }

    public j() {
        this(g.e.b.g0.s.f4134f, c.f4025f, Collections.emptyMap(), false, false, false, true, false, false, false, true, y.f4221f, null, 2, 2, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), a0.f4020f, a0.f4021m, Collections.emptyList());
    }

    public j(g.e.b.g0.s sVar, d dVar, Map<Type, k<?>> map, boolean z2, boolean z3, boolean z4, boolean z5, boolean z6, boolean z7, boolean z8, boolean z9, y yVar, String str, int i2, int i3, List<e0> list, List<e0> list2, List<e0> list3, b0 b0Var, b0 b0Var2, List<z> list4) {
        this.f4206b = new ThreadLocal<>();
        this.f4207c = new ConcurrentHashMap();
        this.f4211g = map;
        this.f4208d = new g.e.b.g0.l(map, z9, list4);
        this.f4212h = z2;
        this.f4213i = z4;
        this.f4214j = z5;
        this.f4215k = z6;
        this.f4216l = z7;
        this.f4217m = list;
        this.f4218n = list2;
        this.f4219o = list4;
        ArrayList arrayList = new ArrayList();
        arrayList.add(g.e.b.g0.f0.q.W);
        arrayList.add(b0Var == a0.f4020f ? g.e.b.g0.f0.l.a : new g.e.b.g0.f0.k(b0Var));
        arrayList.add(sVar);
        arrayList.addAll(list3);
        arrayList.add(g.e.b.g0.f0.q.C);
        arrayList.add(g.e.b.g0.f0.q.f4094m);
        arrayList.add(g.e.b.g0.f0.q.f4088g);
        arrayList.add(g.e.b.g0.f0.q.f4090i);
        arrayList.add(g.e.b.g0.f0.q.f4092k);
        d0 gVar = yVar == y.f4221f ? g.e.b.g0.f0.q.f4101t : new g();
        arrayList.add(new g.e.b.g0.f0.s(Long.TYPE, Long.class, gVar));
        arrayList.add(new g.e.b.g0.f0.s(Double.TYPE, Double.class, z8 ? g.e.b.g0.f0.q.f4103v : new e(this)));
        arrayList.add(new g.e.b.g0.f0.s(Float.TYPE, Float.class, z8 ? g.e.b.g0.f0.q.f4102u : new f(this)));
        arrayList.add(b0Var2 == a0.f4021m ? g.e.b.g0.f0.j.a : new g.e.b.g0.f0.i(new g.e.b.g0.f0.j(b0Var2)));
        arrayList.add(g.e.b.g0.f0.q.f4096o);
        arrayList.add(g.e.b.g0.f0.q.f4098q);
        arrayList.add(new g.e.b.g0.f0.r(AtomicLong.class, new c0(new h(gVar))));
        arrayList.add(new g.e.b.g0.f0.r(AtomicLongArray.class, new c0(new i(gVar))));
        arrayList.add(g.e.b.g0.f0.q.f4100s);
        arrayList.add(g.e.b.g0.f0.q.f4105x);
        arrayList.add(g.e.b.g0.f0.q.E);
        arrayList.add(g.e.b.g0.f0.q.G);
        arrayList.add(new g.e.b.g0.f0.r(BigDecimal.class, g.e.b.g0.f0.q.f4107z));
        arrayList.add(new g.e.b.g0.f0.r(BigInteger.class, g.e.b.g0.f0.q.A));
        arrayList.add(new g.e.b.g0.f0.r(g.e.b.g0.v.class, g.e.b.g0.f0.q.B));
        arrayList.add(g.e.b.g0.f0.q.I);
        arrayList.add(g.e.b.g0.f0.q.K);
        arrayList.add(g.e.b.g0.f0.q.O);
        arrayList.add(g.e.b.g0.f0.q.Q);
        arrayList.add(g.e.b.g0.f0.q.U);
        arrayList.add(g.e.b.g0.f0.q.M);
        arrayList.add(g.e.b.g0.f0.q.f4085d);
        arrayList.add(g.e.b.g0.f0.c.a);
        arrayList.add(g.e.b.g0.f0.q.S);
        if (g.e.b.g0.g0.d.a) {
            arrayList.add(g.e.b.g0.g0.d.f4127e);
            arrayList.add(g.e.b.g0.g0.d.f4126d);
            arrayList.add(g.e.b.g0.g0.d.f4128f);
        }
        arrayList.add(g.e.b.g0.f0.a.a);
        arrayList.add(g.e.b.g0.f0.q.f4083b);
        arrayList.add(new g.e.b.g0.f0.b(this.f4208d));
        arrayList.add(new g.e.b.g0.f0.h(this.f4208d, z3));
        g.e.b.g0.f0.e eVar = new g.e.b.g0.f0.e(this.f4208d);
        this.f4209e = eVar;
        arrayList.add(eVar);
        arrayList.add(g.e.b.g0.f0.q.X);
        arrayList.add(new g.e.b.g0.f0.n(this.f4208d, dVar, sVar, eVar, list4));
        this.f4210f = 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(String str, Class<T> cls) {
        Object objC = c(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(objC);
    }

    /* JADX WARN: Finally extract failed */
    public <T> T c(String str, Type type) {
        T tA = null;
        if (str == null) {
            return null;
        }
        g.e.b.i0.a aVar = new g.e.b.i0.a(new StringReader(str));
        boolean z2 = this.f4216l;
        aVar.f4169m = z2;
        boolean z3 = true;
        aVar.f4169m = true;
        try {
            try {
                try {
                    aVar.I();
                    z3 = false;
                    tA = d(new g.e.b.h0.a<>(type)).a(aVar);
                } catch (IOException e2) {
                    throw new x(e2);
                } catch (IllegalStateException e3) {
                    throw new x(e3);
                }
            } catch (EOFException e4) {
                if (!z3) {
                    throw new x(e4);
                }
            } catch (AssertionError e5) {
                AssertionError assertionError = new AssertionError("AssertionError (GSON 2.9.1): " + e5.getMessage());
                assertionError.initCause(e5);
                throw assertionError;
            }
            aVar.f4169m = z2;
            if (tA != null) {
                try {
                    if (aVar.I() != g.e.b.i0.b.END_DOCUMENT) {
                        throw new x("JSON document was not fully consumed.");
                    }
                } catch (g.e.b.i0.d e6) {
                    throw new x(e6);
                } catch (IOException e7) {
                    throw new p(e7);
                }
            }
            return tA;
        } catch (Throwable th) {
            aVar.f4169m = z2;
            throw th;
        }
    }

    public <T> d0<T> d(g.e.b.h0.a<T> aVar) {
        d0<T> d0Var = (d0) this.f4207c.get(aVar);
        if (d0Var != null) {
            return d0Var;
        }
        Map<g.e.b.h0.a<?>, a<?>> map = this.f4206b.get();
        boolean z2 = false;
        if (map == null) {
            map = new HashMap<>();
            this.f4206b.set(map);
            z2 = true;
        }
        a<?> aVar2 = map.get(aVar);
        if (aVar2 != null) {
            return aVar2;
        }
        try {
            a<?> aVar3 = new a<>();
            map.put(aVar, aVar3);
            Iterator<e0> it = this.f4210f.iterator();
            while (it.hasNext()) {
                d0<T> d0VarB = it.next().b(this, aVar);
                if (d0VarB != null) {
                    if (aVar3.a != null) {
                        throw new AssertionError();
                    }
                    aVar3.a = d0VarB;
                    this.f4207c.put(aVar, d0VarB);
                    return d0VarB;
                }
            }
            throw new IllegalArgumentException("GSON (2.9.1) cannot handle " + aVar);
        } finally {
            map.remove(aVar);
            if (z2) {
                this.f4206b.remove();
            }
        }
    }

    public <T> d0<T> e(e0 e0Var, g.e.b.h0.a<T> aVar) {
        if (!this.f4210f.contains(e0Var)) {
            e0Var = this.f4209e;
        }
        boolean z2 = false;
        for (e0 e0Var2 : this.f4210f) {
            if (z2) {
                d0<T> d0VarB = e0Var2.b(this, aVar);
                if (d0VarB != null) {
                    return d0VarB;
                }
            } else if (e0Var2 == e0Var) {
                z2 = true;
            }
        }
        throw new IllegalArgumentException("GSON cannot serialize " + aVar);
    }

    public g.e.b.i0.c f(Writer writer) throws IOException {
        if (this.f4213i) {
            writer.write(")]}'\n");
        }
        g.e.b.i0.c cVar = new g.e.b.i0.c(writer);
        if (this.f4215k) {
            cVar.f4200r = "  ";
            cVar.f4201s = ": ";
        }
        cVar.f4203u = this.f4214j;
        cVar.f4202t = this.f4216l;
        cVar.f4205w = this.f4212h;
        return cVar;
    }

    public String g(Object obj) {
        if (obj == null) {
            o oVar = q.a;
            StringWriter stringWriter = new StringWriter();
            try {
                h(oVar, f(stringWriter));
                return stringWriter.toString();
            } catch (IOException e2) {
                throw new p(e2);
            }
        }
        Type type = obj.getClass();
        StringWriter stringWriter2 = new StringWriter();
        try {
            i(obj, type, f(stringWriter2));
            return stringWriter2.toString();
        } catch (IOException e3) {
            throw new p(e3);
        }
    }

    public void h(o oVar, g.e.b.i0.c cVar) {
        boolean z2 = cVar.f4202t;
        cVar.f4202t = true;
        boolean z3 = cVar.f4203u;
        cVar.f4203u = this.f4214j;
        boolean z4 = cVar.f4205w;
        cVar.f4205w = this.f4212h;
        try {
            try {
                g.e.b.g0.f0.q.V.b(cVar, oVar);
            } catch (IOException e2) {
                throw new p(e2);
            } catch (AssertionError e3) {
                AssertionError assertionError = new AssertionError("AssertionError (GSON 2.9.1): " + e3.getMessage());
                assertionError.initCause(e3);
                throw assertionError;
            }
        } finally {
            cVar.f4202t = z2;
            cVar.f4203u = z3;
            cVar.f4205w = z4;
        }
    }

    public void i(Object obj, Type type, g.e.b.i0.c cVar) {
        d0 d0VarD = d(new g.e.b.h0.a(type));
        boolean z2 = cVar.f4202t;
        cVar.f4202t = true;
        boolean z3 = cVar.f4203u;
        cVar.f4203u = this.f4214j;
        boolean z4 = cVar.f4205w;
        cVar.f4205w = this.f4212h;
        try {
            try {
                d0VarD.b(cVar, obj);
            } catch (IOException e2) {
                throw new p(e2);
            } catch (AssertionError e3) {
                AssertionError assertionError = new AssertionError("AssertionError (GSON 2.9.1): " + e3.getMessage());
                assertionError.initCause(e3);
                throw assertionError;
            }
        } finally {
            cVar.f4202t = z2;
            cVar.f4203u = z3;
            cVar.f4205w = z4;
        }
    }

    public String toString() {
        return "{serializeNulls:" + this.f4212h + ",factories:" + this.f4210f + ",instanceCreators:" + this.f4208d + "}";
    }
}
