package com.google.gson.internal.bind;

import com.bytedance.covode.number.Covode;
import com.google.gson.c.b;
import com.google.gson.g;
import com.google.gson.j;
import com.google.gson.l;
import com.google.gson.m;
import com.google.gson.p;
import java.io.Reader;
import java.util.Iterator;
import java.util.Map;

public final class a extends com.google.gson.c.a {
    public static final Reader LIZJ = new Reader() {
        static {
            Covode.recordClassIndex(45469);
        }

        public final void close() {
            throw new AssertionError();
        }

        public final int read(char[] cArr, int i, int i2) {
            throw new AssertionError();
        }
    };
    public static final Object LIZLLL = new Object();
    public Object[] LJ = new Object[32];
    public int LJFF;
    public String[] LJI = new String[32];
    public int[] LJII = new int[32];

    private Object LJIJ() {
        Object[] objArr = this.LJ;
        int i = this.LJFF - 1;
        this.LJFF = i;
        Object obj = objArr[i];
        objArr[i] = null;
        return obj;
    }

    public final boolean LJ() {
        b LJFF2 = LJFF();
        if (LJFF2 == b.END_OBJECT || LJFF2 == b.END_ARRAY) {
            return false;
        }
        return true;
    }

    public final Object LJI() {
        return this.LJ[this.LJFF - 1];
    }

    public final void close() {
        this.LJ = new Object[]{LIZLLL};
        this.LJFF = 1;
    }

    public final String toString() {
        return getClass().getSimpleName();
    }

    static {
        Covode.recordClassIndex(45468);
    }

    private String LJIJI() {
        return " at path " + LJIILL();
    }

    public final void LIZ() {
        LIZ(b.BEGIN_ARRAY);
        LIZ((Object) ((g) LJI()).iterator());
        this.LJII[this.LJFF - 1] = 0;
    }

    public final void LIZIZ() {
        LIZ(b.END_ARRAY);
        LJIJ();
        LJIJ();
        int i = this.LJFF;
        if (i > 0) {
            int[] iArr = this.LJII;
            int i2 = i - 1;
            iArr[i2] = iArr[i2] + 1;
        }
    }

    public final void LIZJ() {
        LIZ(b.BEGIN_OBJECT);
        LIZ((Object) ((m) LJI()).LIZ.entrySet().iterator());
    }

    public final void LIZLLL() {
        LIZ(b.END_OBJECT);
        LJIJ();
        LJIJ();
        int i = this.LJFF;
        if (i > 0) {
            int[] iArr = this.LJII;
            int i2 = i - 1;
            iArr[i2] = iArr[i2] + 1;
        }
    }

    public final boolean LJIIIZ() {
        LIZ(b.BOOLEAN);
        boolean LJIIJ = ((j) LJIJ()).LJIIJ();
        int i = this.LJFF;
        if (i > 0) {
            int[] iArr = this.LJII;
            int i2 = i - 1;
            iArr[i2] = iArr[i2] + 1;
        }
        return LJIIJ;
    }

    public final void LJIIJ() {
        LIZ(b.NULL);
        LJIJ();
        int i = this.LJFF;
        if (i > 0) {
            int[] iArr = this.LJII;
            int i2 = i - 1;
            iArr[i2] = iArr[i2] + 1;
        }
    }

    public final String LJII() {
        LIZ(b.NAME);
        Map.Entry entry = (Map.Entry) ((Iterator) LJI()).next();
        String str = (String) entry.getKey();
        this.LJI[this.LJFF - 1] = str;
        LIZ(entry.getValue());
        return str;
    }

    public final void LJIILJJIL() {
        if (LJFF() == b.NAME) {
            LJII();
            this.LJI[this.LJFF - 2] = "null";
        } else {
            LJIJ();
            int i = this.LJFF;
            if (i > 0) {
                this.LJI[i - 1] = "null";
            }
        }
        int i2 = this.LJFF;
        if (i2 > 0) {
            int[] iArr = this.LJII;
            int i3 = i2 - 1;
            iArr[i3] = iArr[i3] + 1;
        }
    }

    public final String LJIIIIZZ() {
        b LJFF2 = LJFF();
        if (LJFF2 == b.STRING || LJFF2 == b.NUMBER) {
            String LIZJ2 = ((j) LJIJ()).LIZJ();
            int i = this.LJFF;
            if (i > 0) {
                int[] iArr = this.LJII;
                int i2 = i - 1;
                iArr[i2] = iArr[i2] + 1;
            }
            return LIZJ2;
        }
        throw new IllegalStateException("Expected " + b.STRING + " but was " + LJFF2 + LJIJI());
    }

    public final double LJIIJJI() {
        b LJFF2 = LJFF();
        if (LJFF2 == b.NUMBER || LJFF2 == b.STRING) {
            double LIZLLL2 = ((j) LJI()).LIZLLL();
            if (this.LIZ || (!Double.isNaN(LIZLLL2) && !Double.isInfinite(LIZLLL2))) {
                LJIJ();
                int i = this.LJFF;
                if (i > 0) {
                    int[] iArr = this.LJII;
                    int i2 = i - 1;
                    iArr[i2] = iArr[i2] + 1;
                }
                return LIZLLL2;
            }
            throw new NumberFormatException("JSON forbids NaN and infinities: ".concat(String.valueOf(LIZLLL2)));
        }
        throw new IllegalStateException("Expected " + b.NUMBER + " but was " + LJFF2 + LJIJI());
    }

    public final long LJIIL() {
        b LJFF2 = LJFF();
        if (LJFF2 == b.NUMBER || LJFF2 == b.STRING) {
            long LJFF3 = ((j) LJI()).LJFF();
            LJIJ();
            int i = this.LJFF;
            if (i > 0) {
                int[] iArr = this.LJII;
                int i2 = i - 1;
                iArr[i2] = iArr[i2] + 1;
            }
            return LJFF3;
        }
        throw new IllegalStateException("Expected " + b.NUMBER + " but was " + LJFF2 + LJIJI());
    }

    public final int LJIILIIL() {
        b LJFF2 = LJFF();
        if (LJFF2 == b.NUMBER || LJFF2 == b.STRING) {
            int LJI2 = ((j) LJI()).LJI();
            LJIJ();
            int i = this.LJFF;
            if (i > 0) {
                int[] iArr = this.LJII;
                int i2 = i - 1;
                iArr[i2] = iArr[i2] + 1;
            }
            return LJI2;
        }
        throw new IllegalStateException("Expected " + b.NUMBER + " but was " + LJFF2 + LJIJI());
    }

    public final String LJIILL() {
        StringBuilder sb = new StringBuilder("$");
        int i = 0;
        while (i < this.LJFF) {
            Object[] objArr = this.LJ;
            if (objArr[i] instanceof g) {
                i++;
                if (objArr[i] instanceof Iterator) {
                    sb.append('[');
                    sb.append(this.LJII[i]);
                    sb.append(']');
                }
            } else if (objArr[i] instanceof m) {
                i++;
                if (objArr[i] instanceof Iterator) {
                    sb.append('.');
                    String[] strArr = this.LJI;
                    if (strArr[i] != null) {
                        sb.append(strArr[i]);
                    }
                }
            }
            i++;
        }
        return sb.toString();
    }

    public final b LJFF() {
        while (this.LJFF != 0) {
            Object LJI2 = LJI();
            if (LJI2 instanceof Iterator) {
                boolean z = this.LJ[this.LJFF - 2] instanceof m;
                Iterator it = (Iterator) LJI2;
                if (it.hasNext()) {
                    if (z) {
                        return b.NAME;
                    }
                    LIZ(it.next());
                } else if (z) {
                    return b.END_OBJECT;
                } else {
                    return b.END_ARRAY;
                }
            } else if (LJI2 instanceof m) {
                return b.BEGIN_OBJECT;
            } else {
                if (LJI2 instanceof g) {
                    return b.BEGIN_ARRAY;
                }
                if (LJI2 instanceof p) {
                    p pVar = (p) LJI2;
                    if (pVar.LIZ instanceof String) {
                        return b.STRING;
                    }
                    if (pVar.LIZ instanceof Boolean) {
                        return b.BOOLEAN;
                    }
                    if (pVar.LIZ instanceof Number) {
                        return b.NUMBER;
                    }
                    throw new AssertionError();
                } else if (LJI2 instanceof l) {
                    return b.NULL;
                } else {
                    if (LJI2 == LIZLLL) {
                        throw new IllegalStateException("JsonReader is closed");
                    }
                    throw new AssertionError();
                }
            }
        }
        return b.END_DOCUMENT;
    }

    public a(j jVar) {
        super(LIZJ);
        LIZ((Object) jVar);
    }

    public final void LIZ(b bVar) {
        if (LJFF() != bVar) {
            throw new IllegalStateException("Expected " + bVar + " but was " + LJFF() + LJIJI());
        }
    }

    public final void LIZ(Object obj) {
        int i = this.LJFF;
        Object[] objArr = this.LJ;
        if (i == objArr.length) {
            Object[] objArr2 = new Object[(i * 2)];
            int[] iArr = new int[(i * 2)];
            String[] strArr = new String[(i * 2)];
            System.arraycopy(objArr, 0, objArr2, 0, i);
            System.arraycopy(this.LJII, 0, iArr, 0, this.LJFF);
            System.arraycopy(this.LJI, 0, strArr, 0, this.LJFF);
            this.LJ = objArr2;
            this.LJII = iArr;
            this.LJI = strArr;
        }
        Object[] objArr3 = this.LJ;
        int i2 = this.LJFF;
        this.LJFF = i2 + 1;
        objArr3[i2] = obj;
    }
}
