package com.google.gson;

import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.google.gson.b.a;
import com.google.gson.c.d;
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 com.google.gson.internal.bind.b;
import com.google.gson.internal.c;
import com.google.gson.internal.j;
import com.google.gson.internal.k;
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;

public final class Gson {
    public static final a<?> LJIIZILJ = a.get(Object.class);
    public final List<v> LIZ;
    public final Excluder LIZIZ;
    public final d LIZJ;
    public final Map<Type, f<?>> LIZLLL;
    public final boolean LJ;
    public final boolean LJFF;
    public final boolean LJI;
    public final boolean LJII;
    public final boolean LJIIIIZZ;
    public final boolean LJIIIZ;
    public final boolean LJIIJ;
    public final String LJIIJJI;
    public final int LJIIL;
    public final int LJIILIIL;
    public final t LJIILJJIL;
    public final List<v> LJIILL;
    public final List<v> LJIILLIIL;
    public final ThreadLocal<Map<a<?>, FutureTypeAdapter<?>>> LJIJ;
    public final Map<a<?>, u<?>> LJIJI;
    public final c LJIJJ;
    public final JsonAdapterAnnotationTypeAdapterFactory LJIJJLI;

    public final <T> u<T> LIZ(a<T> aVar) {
        u<T> uVar = this.LJIJI.get(aVar == null ? LJIIZILJ : aVar);
        if (uVar != null) {
            return uVar;
        }
        Map map = this.LJIJ.get();
        boolean z = false;
        if (map == null) {
            map = new HashMap();
            this.LJIJ.set(map);
            z = true;
        }
        u<T> uVar2 = (u) map.get(aVar);
        if (uVar2 != null) {
            return uVar2;
        }
        try {
            FutureTypeAdapter futureTypeAdapter = new FutureTypeAdapter();
            map.put(aVar, futureTypeAdapter);
            for (v create : this.LIZ) {
                u<T> create2 = create.create(this, aVar);
                if (create2 != null) {
                    if (futureTypeAdapter.LIZ == null) {
                        futureTypeAdapter.LIZ = create2;
                        this.LJIJI.put(aVar, create2);
                        return create2;
                    }
                    throw new AssertionError();
                }
            }
            throw new IllegalArgumentException("GSON (2.8.5) cannot handle ".concat(String.valueOf(aVar)));
        } finally {
            map.remove(aVar);
            if (z) {
                this.LJIJ.remove();
            }
        }
    }

    public final <T> u<T> LIZ(JsonAdapterAnnotationTypeAdapterFactory jsonAdapterAnnotationTypeAdapterFactory, a<T> aVar) {
        if (!this.LIZ.contains(jsonAdapterAnnotationTypeAdapterFactory)) {
            jsonAdapterAnnotationTypeAdapterFactory = this.LJIJJLI;
        }
        boolean z = false;
        Iterator<v> it = this.LIZ.iterator();
        while (it.hasNext()) {
            JsonAdapterAnnotationTypeAdapterFactory jsonAdapterAnnotationTypeAdapterFactory2 = (v) it.next();
            if (z) {
                u<T> create = jsonAdapterAnnotationTypeAdapterFactory2.create(this, aVar);
                if (create != null) {
                    return create;
                }
            } else if (jsonAdapterAnnotationTypeAdapterFactory2 == jsonAdapterAnnotationTypeAdapterFactory) {
                z = true;
            }
        }
        throw new IllegalArgumentException("GSON cannot serialize ".concat(String.valueOf(aVar)));
    }

    public final <T> u<T> LIZ(Class<T> cls) {
        return LIZ(a.get(cls));
    }

    public final j LIZ(Object obj) {
        if (obj == null) {
            return l.LIZ;
        }
        return LIZ(obj, (Type) obj.getClass());
    }

    public final j LIZ(Object obj, Type type) {
        b bVar = new b();
        LIZ(obj, type, (com.google.gson.c.c) bVar);
        return bVar.LIZ();
    }

    /* JADX WARNING: type inference failed for: r0v5, types: [java.lang.Throwable, com.google.gson.k] */
    public final void LIZ(Object obj, Type type, com.google.gson.c.c cVar) {
        u<?> LIZ2 = LIZ(a.get(type));
        boolean z = cVar.LIZIZ;
        cVar.LIZIZ = true;
        boolean z2 = cVar.LIZJ;
        cVar.LIZJ = this.LJII;
        boolean z3 = cVar.LIZLLL;
        cVar.LIZLLL = this.LJ;
        try {
            LIZ2.write(cVar, obj);
            cVar.LIZIZ = z;
            cVar.LIZJ = z2;
            cVar.LIZLLL = z3;
        } catch (IOException e) {
            throw new k((Throwable) e);
        } catch (AssertionError e2) {
            throw new AssertionError("AssertionError (GSON 2.8.5): " + e2.getMessage(), e2);
        } catch (Throwable th) {
            cVar.LIZIZ = z;
            cVar.LIZJ = z2;
            cVar.LIZLLL = z3;
            throw th;
        }
    }

    public final String LIZ(j jVar) {
        StringWriter stringWriter = new StringWriter();
        LIZ(jVar, (Appendable) stringWriter);
        return stringWriter.toString();
    }

    public final <T> T LIZ(String str, Class<T> cls) {
        return j.LIZ(cls).cast(LIZ(str, (Type) cls));
    }

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

    public final <T> T LIZ(Reader reader, Class<T> cls) {
        com.google.gson.c.a LIZ2 = LIZ(reader);
        T LIZ3 = LIZ(LIZ2, (Type) cls);
        LIZ((Object) LIZ3, LIZ2);
        return j.LIZ(cls).cast(LIZ3);
    }

    /* JADX WARNING: type inference failed for: r0v1, types: [java.lang.Throwable, com.google.gson.s] */
    /* JADX WARNING: type inference failed for: r0v3, types: [java.lang.Throwable, com.google.gson.s] */
    /* JADX WARNING: type inference failed for: r0v4, types: [java.lang.Throwable, com.google.gson.s] */
    public final <T> T LIZ(com.google.gson.c.a aVar, Type type) {
        boolean z = aVar.LIZ;
        aVar.LIZ = true;
        try {
            aVar.LJFF();
            T read = LIZ(a.get(type)).read(aVar);
            aVar.LIZ = z;
            return read;
        } catch (EOFException e) {
            if (1 != 0) {
                aVar.LIZ = z;
                return null;
            }
            throw new s((Throwable) e);
        } catch (IllegalStateException e2) {
            throw new s((Throwable) e2);
        } catch (IOException e3) {
            throw new s((Throwable) e3);
        } catch (AssertionError e4) {
            throw new AssertionError("AssertionError (GSON 2.8.5): " + e4.getMessage(), e4);
        } catch (Throwable th) {
            aVar.LIZ = z;
            throw th;
        }
    }

    public final <T> T LIZ(j jVar, Class<T> cls) {
        return j.LIZ(cls).cast(LIZ(jVar, (Type) cls));
    }

    public final <T> T LIZ(j jVar, Type type) {
        if (jVar == null) {
            return null;
        }
        return LIZ((com.google.gson.c.a) new com.google.gson.internal.bind.a(jVar), type);
    }

    public final e LIZ() {
        return new e(this);
    }

    static {
        Covode.recordClassIndex(45360);
    }

    public Gson() {
        this(Excluder.LIZ, c.IDENTITY, Collections.emptyMap(), false, false, false, true, false, false, false, t.DEFAULT, (String) null, 2, 2, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    }

    public final String toString() {
        return "{serializeNulls:" + this.LJ + ",factories:" + this.LIZ + ",instanceCreators:" + this.LJIJJ + "}";
    }

    public final String LIZIZ(Object obj) {
        if (obj == null) {
            return LIZ((j) l.LIZ);
        }
        return LIZIZ(obj, obj.getClass());
    }

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

    public final com.google.gson.c.a LIZ(Reader reader) {
        com.google.gson.c.a aVar = new com.google.gson.c.a(reader);
        aVar.LIZ = this.LJIIIZ;
        return aVar;
    }

    public final com.google.gson.c.c LIZ(Writer writer) {
        MethodCollector.i(2536);
        if (this.LJI) {
            writer.write(")]}'\n");
        }
        com.google.gson.c.c cVar = new com.google.gson.c.c(writer);
        if (this.LJIIIIZZ) {
            cVar.LIZJ("  ");
        }
        cVar.LIZLLL = this.LJ;
        MethodCollector.o(2536);
        return cVar;
    }

    private <T> T LIZ(Reader reader, Type type) {
        com.google.gson.c.a LIZ2 = LIZ(reader);
        T LIZ3 = LIZ(LIZ2, type);
        LIZ((Object) LIZ3, LIZ2);
        return LIZ3;
    }

    public final String LIZIZ(Object obj, Type type) {
        StringWriter stringWriter = new StringWriter();
        LIZ(obj, type, (Appendable) stringWriter);
        return stringWriter.toString();
    }

    /* JADX WARNING: type inference failed for: r0v0, types: [java.lang.Throwable, com.google.gson.k] */
    private void LIZ(j jVar, Appendable appendable) {
        try {
            LIZ(jVar, LIZ(k.LIZ(appendable)));
        } catch (IOException e) {
            throw new k((Throwable) e);
        }
    }

    /* JADX WARNING: type inference failed for: r0v4, types: [java.lang.Throwable, com.google.gson.k] */
    private void LIZ(j jVar, com.google.gson.c.c cVar) {
        boolean z = cVar.LIZIZ;
        cVar.LIZIZ = true;
        boolean z2 = cVar.LIZJ;
        cVar.LIZJ = this.LJII;
        boolean z3 = cVar.LIZLLL;
        cVar.LIZLLL = this.LJ;
        try {
            k.LIZ(jVar, cVar);
            cVar.LIZIZ = z;
            cVar.LIZJ = z2;
            cVar.LIZLLL = z3;
        } catch (IOException e) {
            throw new k((Throwable) e);
        } catch (AssertionError e2) {
            throw new AssertionError("AssertionError (GSON 2.8.5): " + e2.getMessage(), e2);
        } catch (Throwable th) {
            cVar.LIZIZ = z;
            cVar.LIZJ = z2;
            cVar.LIZLLL = z3;
            throw th;
        }
    }

    /* JADX WARNING: type inference failed for: r0v1, types: [java.lang.Throwable, com.google.gson.s] */
    /* JADX WARNING: type inference failed for: r0v2, types: [java.lang.Throwable, com.google.gson.k] */
    /* JADX WARNING: type inference failed for: r1v4, types: [java.lang.Throwable, com.google.gson.k] */
    public static void LIZ(Object obj, com.google.gson.c.a aVar) {
        if (obj != null) {
            try {
                if (aVar.LJFF() != com.google.gson.c.b.END_DOCUMENT) {
                    throw new k("JSON document was not fully consumed.");
                }
            } catch (d e) {
                throw new s((Throwable) e);
            } catch (IOException e2) {
                throw new k((Throwable) e2);
            }
        }
    }

    /* JADX WARNING: type inference failed for: r0v0, types: [java.lang.Throwable, com.google.gson.k] */
    private void LIZ(Object obj, Type type, Appendable appendable) {
        try {
            LIZ(obj, type, LIZ(k.LIZ(appendable)));
        } catch (IOException e) {
            throw new k((Throwable) e);
        }
    }

    public Gson(Excluder excluder, d dVar, Map<Type, f<?>> map, boolean z, boolean z2, boolean z3, boolean z4, boolean z5, boolean z6, boolean z7, t tVar, String str, int i, int i2, List<v> list, List<v> list2, List<v> list3) {
        final u r5;
        u r0;
        u r02;
        this.LJIJ = new ThreadLocal<>();
        this.LJIJI = new ConcurrentHashMap();
        this.LIZIZ = excluder;
        this.LIZJ = dVar;
        this.LIZLLL = map;
        c cVar = new c(map);
        this.LJIJJ = cVar;
        this.LJ = z;
        this.LJFF = z2;
        this.LJI = z3;
        this.LJII = z4;
        this.LJIIIIZZ = z5;
        this.LJIIIZ = z6;
        boolean z8 = z7;
        this.LJIIJ = z8;
        t tVar2 = tVar;
        this.LJIILJJIL = tVar2;
        this.LJIIJJI = str;
        this.LJIIL = i;
        this.LJIILIIL = i2;
        this.LJIILL = list;
        this.LJIILLIIL = list2;
        ArrayList arrayList = new ArrayList();
        arrayList.add(TypeAdapters.LJJJJLL);
        arrayList.add(ObjectTypeAdapter.LIZ);
        arrayList.add(excluder);
        arrayList.addAll(list3);
        arrayList.add(TypeAdapters.LJJIIJZLJL);
        arrayList.add(TypeAdapters.LJIIL);
        arrayList.add(TypeAdapters.LJI);
        arrayList.add(TypeAdapters.LJIIIIZZ);
        arrayList.add(TypeAdapters.LJIIJ);
        if (tVar2 == t.DEFAULT) {
            r5 = TypeAdapters.LJIJI;
        } else {
            r5 = new u<Number>() {
                static {
                    Covode.recordClassIndex(45363);
                }

                public final /* synthetic */ Object read(com.google.gson.c.a aVar) {
                    if (aVar.LJFF() != com.google.gson.c.b.NULL) {
                        return Long.valueOf(aVar.LJIIL());
                    }
                    aVar.LJIIJ();
                    return null;
                }

                public final /* synthetic */ void write(com.google.gson.c.c cVar, Object obj) {
                    if (obj == null) {
                        cVar.LJFF();
                    } else {
                        cVar.LIZIZ(obj.toString());
                    }
                }
            };
        }
        arrayList.add(TypeAdapters.LIZ(Long.TYPE, Long.class, r5));
        Class cls = Double.TYPE;
        Class<Double> cls2 = Double.class;
        if (z8) {
            r0 = TypeAdapters.LJIJJLI;
        } else {
            r0 = new u<Number>() {
                static {
                    Covode.recordClassIndex(45361);
                }

                public /* synthetic */ Object read(com.google.gson.c.a aVar) {
                    if (aVar.LJFF() != com.google.gson.c.b.NULL) {
                        return Double.valueOf(aVar.LJIIJJI());
                    }
                    aVar.LJIIJ();
                    return null;
                }

                public /* synthetic */ void write(com.google.gson.c.c cVar, Object obj) {
                    Number number = (Number) obj;
                    if (number == null) {
                        cVar.LJFF();
                        return;
                    }
                    Gson.LIZ(number.doubleValue());
                    cVar.LIZ(number);
                }
            };
        }
        arrayList.add(TypeAdapters.LIZ(cls, cls2, r0));
        Class cls3 = Float.TYPE;
        Class<Float> cls4 = Float.class;
        if (z8) {
            r02 = TypeAdapters.LJIJJ;
        } else {
            r02 = new u<Number>() {
                static {
                    Covode.recordClassIndex(45362);
                }

                public /* synthetic */ Object read(com.google.gson.c.a aVar) {
                    if (aVar.LJFF() != com.google.gson.c.b.NULL) {
                        return Float.valueOf((float) aVar.LJIIJJI());
                    }
                    aVar.LJIIJ();
                    return null;
                }

                public /* synthetic */ void write(com.google.gson.c.c cVar, Object obj) {
                    Number number = (Number) obj;
                    if (number == null) {
                        cVar.LJFF();
                        return;
                    }
                    Gson.LIZ((double) number.floatValue());
                    cVar.LIZ(number);
                }
            };
        }
        arrayList.add(TypeAdapters.LIZ(cls3, cls4, r02));
        arrayList.add(TypeAdapters.LJJ);
        arrayList.add(TypeAdapters.LJIILJJIL);
        arrayList.add(TypeAdapters.LJIILLIIL);
        arrayList.add(TypeAdapters.LIZ(AtomicLong.class, new 4(r5).nullSafe()));
        arrayList.add(TypeAdapters.LIZ(AtomicLongArray.class, new u<AtomicLongArray>() {
            static {
                Covode.recordClassIndex(45365);
            }

            public final /* synthetic */ Object read(com.google.gson.c.a aVar) {
                ArrayList arrayList = new ArrayList();
                aVar.LIZ();
                while (aVar.LJ()) {
                    arrayList.add(Long.valueOf(((Number) r5.read(aVar)).longValue()));
                }
                aVar.LIZIZ();
                int size = arrayList.size();
                AtomicLongArray atomicLongArray = new AtomicLongArray(size);
                for (int i = 0; i < size; i++) {
                    atomicLongArray.set(i, ((Long) arrayList.get(i)).longValue());
                }
                return atomicLongArray;
            }

            public final /* synthetic */ void write(com.google.gson.c.c cVar, Object obj) {
                AtomicLongArray atomicLongArray = (AtomicLongArray) obj;
                cVar.LIZIZ();
                int length = atomicLongArray.length();
                for (int i = 0; i < length; i++) {
                    r5.write(cVar, Long.valueOf(atomicLongArray.get(i)));
                }
                cVar.LIZJ();
            }
        }.nullSafe()));
        arrayList.add(TypeAdapters.LJIJ);
        arrayList.add(TypeAdapters.LJJIFFI);
        arrayList.add(TypeAdapters.LJJIIZI);
        arrayList.add(TypeAdapters.LJJIJIIJI);
        arrayList.add(TypeAdapters.LIZ(BigDecimal.class, TypeAdapters.LJJIII));
        arrayList.add(TypeAdapters.LIZ(BigInteger.class, TypeAdapters.LJJIIJ));
        arrayList.add(TypeAdapters.LJJIJIL);
        arrayList.add(TypeAdapters.LJJIJLIJ);
        arrayList.add(TypeAdapters.LJJJI);
        arrayList.add(TypeAdapters.LJJJJ);
        arrayList.add(TypeAdapters.LJJJJL);
        arrayList.add(TypeAdapters.LJJIZ);
        arrayList.add(TypeAdapters.LIZLLL);
        arrayList.add(DateTypeAdapter.LIZ);
        arrayList.add(TypeAdapters.LJJJJJ);
        arrayList.add(TimeTypeAdapter.LIZ);
        arrayList.add(SqlDateTypeAdapter.LIZ);
        arrayList.add(TypeAdapters.LJJJJI);
        arrayList.add(ArrayTypeAdapter.LIZ);
        arrayList.add(TypeAdapters.LIZIZ);
        arrayList.add(new CollectionTypeAdapterFactory(cVar));
        arrayList.add(new MapTypeAdapterFactory(cVar, z2));
        JsonAdapterAnnotationTypeAdapterFactory jsonAdapterAnnotationTypeAdapterFactory = new JsonAdapterAnnotationTypeAdapterFactory(cVar);
        this.LJIJJLI = jsonAdapterAnnotationTypeAdapterFactory;
        arrayList.add(jsonAdapterAnnotationTypeAdapterFactory);
        arrayList.add(TypeAdapters.LJJJJZ);
        arrayList.add(new ReflectiveTypeAdapterFactory(cVar, dVar, excluder, jsonAdapterAnnotationTypeAdapterFactory));
        this.LIZ = Collections.unmodifiableList(arrayList);
    }
}
