package com.google.android.gms.internal.pal;

import java.io.IOException;
import java.io.Serializable;
import java.io.Writer;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/* JADX INFO: loaded from: classes2.dex */
public final class b extends q9 {

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final /* synthetic */ int f20697j;

    public /* synthetic */ b(int i10) {
        this.f20697j = i10;
    }

    public static void K0(g gVar, me meVar) throws IOException {
        Writer writer = gVar.f20915a;
        if (meVar == null || (meVar instanceof ne)) {
            if (gVar.f20920f != null) {
                gVar.p();
            }
            gVar.k();
            writer.write("null");
            return;
        }
        if (!(meVar instanceof pe)) {
            if (meVar instanceof le) {
                gVar.p();
                gVar.k();
                int i10 = gVar.f20917c;
                int[] iArr = gVar.f20916b;
                if (i10 == iArr.length) {
                    gVar.f20916b = Arrays.copyOf(iArr, i10 + i10);
                }
                int[] iArr2 = gVar.f20916b;
                int i11 = gVar.f20917c;
                gVar.f20917c = i11 + 1;
                iArr2[i11] = 1;
                writer.write(91);
                Iterator it = ((le) meVar).f21064a.iterator();
                while (it.hasNext()) {
                    K0(gVar, (me) it.next());
                }
                gVar.g(1, 2, ']');
                return;
            }
            if (!(meVar instanceof oe)) {
                Class<?> cls = meVar.getClass();
                cls.toString();
                throw new IllegalArgumentException("Couldn't write ".concat(String.valueOf(cls)));
            }
            gVar.p();
            gVar.k();
            int i12 = gVar.f20917c;
            int[] iArr3 = gVar.f20916b;
            if (i12 == iArr3.length) {
                gVar.f20916b = Arrays.copyOf(iArr3, i12 + i12);
            }
            int[] iArr4 = gVar.f20916b;
            int i13 = gVar.f20917c;
            gVar.f20917c = i13 + 1;
            iArr4[i13] = 3;
            writer.write(123);
            qe qeVar = new qe((re) meVar.g().f21120a.entrySet());
            while (qeVar.hasNext()) {
                Map.Entry entry = (Map.Entry) qeVar.next();
                String str = (String) entry.getKey();
                if (str == null) {
                    throw new NullPointerException("name == null");
                }
                if (gVar.f20920f != null) {
                    throw new IllegalStateException();
                }
                if (gVar.f20917c == 0) {
                    throw new IllegalStateException("JsonWriter is closed.");
                }
                gVar.f20920f = str;
                K0(gVar, (me) entry.getValue());
            }
            gVar.g(3, 5, '}');
            return;
        }
        pe peVar = (pe) meVar;
        Serializable serializable = peVar.f21142a;
        if (!(serializable instanceof Number)) {
            boolean z10 = serializable instanceof Boolean;
            if (z10) {
                boolean zBooleanValue = z10 ? ((Boolean) serializable).booleanValue() : Boolean.parseBoolean(peVar.f());
                gVar.p();
                gVar.k();
                writer.write(true != zBooleanValue ? "false" : "true");
                return;
            }
            String strF = peVar.f();
            if (strF != null) {
                gVar.p();
                gVar.k();
                gVar.m(strF);
                return;
            } else {
                if (gVar.f20920f != null) {
                    gVar.p();
                }
                gVar.k();
                writer.write("null");
                return;
            }
        }
        Number numberH = peVar.h();
        gVar.p();
        String string = numberH.toString();
        if (!string.equals("-Infinity") && !string.equals("Infinity") && !string.equals("NaN")) {
            Class<?> cls2 = numberH.getClass();
            if (cls2 != Integer.class && cls2 != Long.class && cls2 != Double.class && cls2 != Float.class && cls2 != Byte.class && cls2 != Short.class && cls2 != BigDecimal.class && cls2 != BigInteger.class && cls2 != AtomicInteger.class && cls2 != AtomicLong.class && !g.f20913g.matcher(string).matches()) {
                throw new IllegalArgumentException("String created by " + cls2 + " is not a valid JSON number: " + string);
            }
        } else if (!gVar.f20919e) {
            throw new IllegalArgumentException("Numeric values must be finite, but was ".concat(string));
        }
        gVar.k();
        writer.append((CharSequence) string);
    }

    public static final me L0(f fVar, int i10) {
        int i11 = i10 - 1;
        if (i11 == 5) {
            return new pe(fVar.k());
        }
        if (i11 == 6) {
            return new pe(new zzzj(fVar.k()));
        }
        boolean z10 = true;
        if (i11 != 7) {
            if (i11 != 8) {
                throw new IllegalStateException("Unexpected token: ".concat(q9.m(i10)));
            }
            int iE = fVar.f20786g;
            if (iE == 0) {
                iE = fVar.e();
            }
            if (iE != 7) {
                throw new IllegalStateException("Expected null but was " + ((Object) q9.m(fVar.m())) + fVar.g());
            }
            fVar.f20786g = 0;
            int[] iArr = fVar.f20792m;
            int i12 = fVar.f20790k - 1;
            iArr[i12] = iArr[i12] + 1;
            return ne.f21105a;
        }
        int iE2 = fVar.f20786g;
        if (iE2 == 0) {
            iE2 = fVar.e();
        }
        if (iE2 == 5) {
            fVar.f20786g = 0;
            int[] iArr2 = fVar.f20792m;
            int i13 = fVar.f20790k - 1;
            iArr2[i13] = iArr2[i13] + 1;
        } else {
            if (iE2 != 6) {
                throw new IllegalStateException("Expected a boolean but was " + ((Object) q9.m(fVar.m())) + fVar.g());
            }
            fVar.f20786g = 0;
            int[] iArr3 = fVar.f20792m;
            int i14 = fVar.f20790k - 1;
            iArr3[i14] = iArr3[i14] + 1;
            z10 = false;
        }
        return new pe(Boolean.valueOf(z10));
    }

    public static final me M0(f fVar, int i10) {
        int i11 = i10 - 1;
        if (i11 == 0) {
            int iE = fVar.f20786g;
            if (iE == 0) {
                iE = fVar.e();
            }
            if (iE == 3) {
                fVar.L(1);
                fVar.f20792m[fVar.f20790k - 1] = 0;
                fVar.f20786g = 0;
                return new le();
            }
            throw new IllegalStateException("Expected BEGIN_ARRAY but was " + ((Object) q9.m(fVar.m())) + fVar.g());
        }
        if (i11 != 2) {
            return null;
        }
        int iE2 = fVar.f20786g;
        if (iE2 == 0) {
            iE2 = fVar.e();
        }
        if (iE2 == 1) {
            fVar.L(3);
            fVar.f20786g = 0;
            return new oe();
        }
        throw new IllegalStateException("Expected BEGIN_OBJECT but was " + ((Object) q9.m(fVar.m())) + fVar.g());
    }

    public final Object I0(f fVar) {
        String strE;
        switch (this.f20697j) {
            case 2:
                throw null;
            case 3:
            case 9:
            case 13:
            case 15:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
            default:
                throw null;
            case 4:
                throw null;
            case 5:
                throw null;
            case 6:
                throw null;
            case 7:
                throw null;
            case 8:
                throw null;
            case 10:
                throw null;
            case 11:
                throw null;
            case 12:
                int iM = fVar.m();
                me meVarM0 = M0(fVar, iM);
                if (meVarM0 == null) {
                    return L0(fVar, iM);
                }
                ArrayDeque arrayDeque = new ArrayDeque();
                while (true) {
                    int iE = fVar.f20786g;
                    if (iE == 0) {
                        iE = fVar.e();
                    }
                    if (iE == 2 || iE == 4 || iE == 17) {
                        if (meVarM0 instanceof le) {
                            int iE2 = fVar.f20786g;
                            if (iE2 == 0) {
                                iE2 = fVar.e();
                            }
                            if (iE2 != 4) {
                                throw new IllegalStateException("Expected END_ARRAY but was " + ((Object) q9.m(fVar.m())) + fVar.g());
                            }
                            int i10 = fVar.f20790k;
                            fVar.f20790k = i10 - 1;
                            int[] iArr = fVar.f20792m;
                            int i11 = i10 - 2;
                            iArr[i11] = iArr[i11] + 1;
                            fVar.f20786g = 0;
                        } else {
                            int iE3 = fVar.f20786g;
                            if (iE3 == 0) {
                                iE3 = fVar.e();
                            }
                            if (iE3 != 2) {
                                throw new IllegalStateException("Expected END_OBJECT but was " + ((Object) q9.m(fVar.m())) + fVar.g());
                            }
                            int i12 = fVar.f20790k;
                            int i13 = i12 - 1;
                            fVar.f20790k = i13;
                            fVar.f20791l[i13] = null;
                            int[] iArr2 = fVar.f20792m;
                            int i14 = i12 - 2;
                            iArr2[i14] = iArr2[i14] + 1;
                            fVar.f20786g = 0;
                        }
                        if (arrayDeque.isEmpty()) {
                            return meVarM0;
                        }
                        meVarM0 = (me) arrayDeque.removeLast();
                    } else {
                        if (meVarM0 instanceof oe) {
                            int iE4 = fVar.f20786g;
                            if (iE4 == 0) {
                                iE4 = fVar.e();
                            }
                            if (iE4 == 14) {
                                strE = fVar.H();
                            } else if (iE4 == 12) {
                                strE = fVar.E('\'');
                            } else {
                                if (iE4 != 13) {
                                    throw new IllegalStateException("Expected a name but was " + ((Object) q9.m(fVar.m())) + fVar.g());
                                }
                                strE = fVar.E('\"');
                            }
                            fVar.f20786g = 0;
                            fVar.f20791l[fVar.f20790k - 1] = strE;
                        } else {
                            strE = null;
                        }
                        int iM2 = fVar.m();
                        me meVarM02 = M0(fVar, iM2);
                        me meVarL0 = meVarM02 == null ? L0(fVar, iM2) : meVarM02;
                        if (meVarM0 instanceof le) {
                            ((le) meVarM0).f21064a.add(meVarL0);
                        } else {
                            ((oe) meVarM0).f21120a.put(strE, meVarL0);
                        }
                        if (meVarM02 != null) {
                            arrayDeque.addLast(meVarM0);
                            meVarM0 = meVarL0;
                        }
                    }
                }
                break;
            case 14:
                throw null;
            case 16:
                throw null;
            case 17:
                throw null;
            case 18:
                throw null;
            case 25:
                throw null;
        }
    }

    public final /* bridge */ /* synthetic */ void J0(g gVar, Object obj) throws IOException {
        switch (this.f20697j) {
            case 2:
                throw null;
            case 3:
            case 9:
            case 13:
            case 15:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
            default:
                throw null;
            case 4:
                throw null;
            case 5:
                throw null;
            case 6:
                throw null;
            case 7:
                throw null;
            case 8:
                throw null;
            case 10:
                throw null;
            case 11:
                throw null;
            case 12:
                K0(gVar, (me) obj);
                return;
            case 14:
                throw null;
            case 16:
                throw null;
            case 17:
                throw null;
            case 18:
                throw null;
            case 25:
                throw null;
        }
    }
}
