package k.a.q.y;

import java.util.Arrays;
import k.a.n.k;

/* JADX INFO: compiled from: JsonPath.kt */
/* JADX INFO: loaded from: classes.dex */
public final class s {
    private Object[] a = new Object[8];
    private int[] b;
    private int c;

    /* JADX INFO: compiled from: JsonPath.kt */
    private static final class a {
        public static final a a = new a();

        private a() {
        }
    }

    public s() {
        int[] iArr = new int[8];
        for (int i2 = 0; i2 < 8; i2++) {
            iArr[i2] = -1;
        }
        this.b = iArr;
        this.c = -1;
    }

    private final void e() {
        int i2 = this.c * 2;
        Object[] objArrCopyOf = Arrays.copyOf(this.a, i2);
        j.p0.d.r.e(objArrCopyOf, "copyOf(this, newSize)");
        this.a = objArrCopyOf;
        int[] iArrCopyOf = Arrays.copyOf(this.b, i2);
        j.p0.d.r.e(iArrCopyOf, "copyOf(this, newSize)");
        this.b = iArrCopyOf;
    }

    public final String a() {
        StringBuilder sb = new StringBuilder();
        sb.append("$");
        int i2 = this.c + 1;
        for (int i3 = 0; i3 < i2; i3++) {
            Object obj = this.a[i3];
            if (obj instanceof k.a.n.f) {
                k.a.n.f fVar = (k.a.n.f) obj;
                if (!j.p0.d.r.a(fVar.c(), k.b.a)) {
                    int i4 = this.b[i3];
                    if (i4 >= 0) {
                        sb.append(".");
                        sb.append(fVar.e(i4));
                    }
                } else if (this.b[i3] != -1) {
                    sb.append("[");
                    sb.append(this.b[i3]);
                    sb.append("]");
                }
            } else if (obj != a.a) {
                sb.append("[");
                sb.append("'");
                sb.append(obj);
                sb.append("'");
                sb.append("]");
            }
        }
        String string = sb.toString();
        j.p0.d.r.e(string, "StringBuilder().apply(builderAction).toString()");
        return string;
    }

    public final void b() {
        int i2 = this.c;
        int[] iArr = this.b;
        if (iArr[i2] == -2) {
            iArr[i2] = -1;
            this.c = i2 - 1;
        }
        int i3 = this.c;
        if (i3 != -1) {
            this.c = i3 - 1;
        }
    }

    public final void c(k.a.n.f fVar) {
        j.p0.d.r.f(fVar, "sd");
        int i2 = this.c + 1;
        this.c = i2;
        if (i2 == this.a.length) {
            e();
        }
        this.a[i2] = fVar;
    }

    public final void d() {
        int[] iArr = this.b;
        int i2 = this.c;
        if (iArr[i2] == -2) {
            this.a[i2] = a.a;
        }
    }

    public final void f(Object obj) {
        int[] iArr = this.b;
        int i2 = this.c;
        if (iArr[i2] != -2) {
            int i3 = i2 + 1;
            this.c = i3;
            if (i3 == this.a.length) {
                e();
            }
        }
        Object[] objArr = this.a;
        int i4 = this.c;
        objArr[i4] = obj;
        this.b[i4] = -2;
    }

    public final void g(int i2) {
        this.b[this.c] = i2;
    }

    public String toString() {
        return a();
    }
}
