package l3;

import i3.AbstractC0638f;
import i3.C0637e;
import i3.C0640h;
import i3.C0641i;
import i3.C0642j;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public final class i extends q3.c {

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public static final h f8919y = new h();

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public static final C0642j f8920z = new C0642j("closed");

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final ArrayList f8921v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public String f8922w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public AbstractC0638f f8923x;

    public i() {
        super(f8919y);
        this.f8921v = new ArrayList();
        this.f8923x = C0640h.f6667k;
    }

    public final AbstractC0638f B() {
        return (AbstractC0638f) this.f8921v.get(r0.size() - 1);
    }

    public final void C(AbstractC0638f abstractC0638f) {
        if (this.f8922w != null) {
            if (!(abstractC0638f instanceof C0640h) || this.f9586r) {
                C0641i c0641i = (C0641i) B();
                String str = this.f8922w;
                c0641i.getClass();
                c0641i.f6668k.put(str, abstractC0638f);
            }
            this.f8922w = null;
            return;
        }
        if (this.f8921v.isEmpty()) {
            this.f8923x = abstractC0638f;
            return;
        }
        AbstractC0638f abstractC0638fB = B();
        if (!(abstractC0638fB instanceof C0637e)) {
            throw new IllegalStateException();
        }
        ((C0637e) abstractC0638fB).f6666k.add(abstractC0638f);
    }

    @Override // q3.c, java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        ArrayList arrayList = this.f8921v;
        if (!arrayList.isEmpty()) {
            throw new IOException("Incomplete document");
        }
        arrayList.add(f8920z);
    }

    @Override // q3.c
    public final void e() {
        C0637e c0637e = new C0637e();
        C(c0637e);
        this.f8921v.add(c0637e);
    }

    @Override // q3.c
    public final void f() {
        C0641i c0641i = new C0641i();
        C(c0641i);
        this.f8921v.add(c0641i);
    }

    @Override // q3.c
    public final void k() {
        ArrayList arrayList = this.f8921v;
        if (arrayList.isEmpty() || this.f8922w != null) {
            throw new IllegalStateException();
        }
        if (!(B() instanceof C0637e)) {
            throw new IllegalStateException();
        }
        arrayList.remove(arrayList.size() - 1);
    }

    @Override // q3.c
    public final void l() {
        ArrayList arrayList = this.f8921v;
        if (arrayList.isEmpty() || this.f8922w != null) {
            throw new IllegalStateException();
        }
        if (!(B() instanceof C0641i)) {
            throw new IllegalStateException();
        }
        arrayList.remove(arrayList.size() - 1);
    }

    @Override // q3.c
    public final void m(String str) {
        Objects.requireNonNull(str, "name == null");
        if (this.f8921v.isEmpty() || this.f8922w != null) {
            throw new IllegalStateException();
        }
        if (!(B() instanceof C0641i)) {
            throw new IllegalStateException();
        }
        this.f8922w = str;
    }

    @Override // q3.c
    public final q3.c o() {
        C(C0640h.f6667k);
        return this;
    }

    @Override // q3.c
    public final void u(double d3) {
        if (this.f9585o || !(Double.isNaN(d3) || Double.isInfinite(d3))) {
            C(new C0642j(Double.valueOf(d3)));
        } else {
            throw new IllegalArgumentException("JSON forbids NaN and infinities: " + d3);
        }
    }

    @Override // q3.c
    public final void v(long j5) {
        C(new C0642j(Long.valueOf(j5)));
    }

    @Override // q3.c
    public final void w(Boolean bool) {
        if (bool == null) {
            C(C0640h.f6667k);
        } else {
            C(new C0642j(bool));
        }
    }

    @Override // q3.c
    public final void x(Number number) {
        if (number == null) {
            C(C0640h.f6667k);
            return;
        }
        if (!this.f9585o) {
            double dDoubleValue = number.doubleValue();
            if (Double.isNaN(dDoubleValue) || Double.isInfinite(dDoubleValue)) {
                throw new IllegalArgumentException("JSON forbids NaN and infinities: " + number);
            }
        }
        C(new C0642j(number));
    }

    @Override // q3.c
    public final void y(String str) {
        if (str == null) {
            C(C0640h.f6667k);
        } else {
            C(new C0642j(str));
        }
    }

    @Override // q3.c
    public final void z(boolean z5) {
        C(new C0642j(Boolean.valueOf(z5)));
    }

    @Override // q3.c, java.io.Flushable
    public final void flush() {
    }
}
