package g.e.b.g0.f0;

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public final class g extends g.e.b.i0.c {

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public static final Writer f4048x = new a();

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public static final g.e.b.u f4049y = new g.e.b.u("closed");
    public String A;
    public g.e.b.o B;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final List<g.e.b.o> f4050z;

    public class a extends Writer {
        @Override // java.io.Writer, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
            throw new AssertionError();
        }

        @Override // java.io.Writer, java.io.Flushable
        public void flush() {
            throw new AssertionError();
        }

        @Override // java.io.Writer
        public void write(char[] cArr, int i2, int i3) {
            throw new AssertionError();
        }
    }

    public g() {
        super(f4048x);
        this.f4050z = new ArrayList();
        this.B = g.e.b.q.a;
    }

    @Override // g.e.b.i0.c
    public g.e.b.i0.c A(Number number) {
        if (number == null) {
            F(g.e.b.q.a);
            return this;
        }
        if (!this.f4202t) {
            double dDoubleValue = number.doubleValue();
            if (Double.isNaN(dDoubleValue) || Double.isInfinite(dDoubleValue)) {
                throw new IllegalArgumentException("JSON forbids NaN and infinities: " + number);
            }
        }
        F(new g.e.b.u(number));
        return this;
    }

    @Override // g.e.b.i0.c
    public g.e.b.i0.c B(String str) {
        if (str == null) {
            F(g.e.b.q.a);
            return this;
        }
        F(new g.e.b.u(str));
        return this;
    }

    @Override // g.e.b.i0.c
    public g.e.b.i0.c C(boolean z2) {
        F(new g.e.b.u(Boolean.valueOf(z2)));
        return this;
    }

    public final g.e.b.o E() {
        return this.f4050z.get(r0.size() - 1);
    }

    public final void F(g.e.b.o oVar) {
        if (this.A != null) {
            if (!(oVar instanceof g.e.b.q) || this.f4205w) {
                g.e.b.r rVar = (g.e.b.r) E();
                rVar.a.put(this.A, oVar);
            }
            this.A = null;
            return;
        }
        if (this.f4050z.isEmpty()) {
            this.B = oVar;
            return;
        }
        g.e.b.o oVarE = E();
        if (!(oVarE instanceof g.e.b.l)) {
            throw new IllegalStateException();
        }
        ((g.e.b.l) oVarE).f4220f.add(oVar);
    }

    @Override // g.e.b.i0.c
    public g.e.b.i0.c c() {
        g.e.b.l lVar = new g.e.b.l();
        F(lVar);
        this.f4050z.add(lVar);
        return this;
    }

    @Override // g.e.b.i0.c, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        if (!this.f4050z.isEmpty()) {
            throw new IOException("Incomplete document");
        }
        this.f4050z.add(f4049y);
    }

    @Override // g.e.b.i0.c
    public g.e.b.i0.c d() {
        g.e.b.r rVar = new g.e.b.r();
        F(rVar);
        this.f4050z.add(rVar);
        return this;
    }

    @Override // g.e.b.i0.c, java.io.Flushable
    public void flush() {
    }

    @Override // g.e.b.i0.c
    public g.e.b.i0.c g() {
        if (this.f4050z.isEmpty() || this.A != null) {
            throw new IllegalStateException();
        }
        if (!(E() instanceof g.e.b.l)) {
            throw new IllegalStateException();
        }
        this.f4050z.remove(r0.size() - 1);
        return this;
    }

    @Override // g.e.b.i0.c
    public g.e.b.i0.c h() {
        if (this.f4050z.isEmpty() || this.A != null) {
            throw new IllegalStateException();
        }
        if (!(E() instanceof g.e.b.r)) {
            throw new IllegalStateException();
        }
        this.f4050z.remove(r0.size() - 1);
        return this;
    }

    @Override // g.e.b.i0.c
    public g.e.b.i0.c j(String str) {
        Objects.requireNonNull(str, "name == null");
        if (this.f4050z.isEmpty() || this.A != null) {
            throw new IllegalStateException();
        }
        if (!(E() instanceof g.e.b.r)) {
            throw new IllegalStateException();
        }
        this.A = str;
        return this;
    }

    @Override // g.e.b.i0.c
    public g.e.b.i0.c m() {
        F(g.e.b.q.a);
        return this;
    }

    @Override // g.e.b.i0.c
    public g.e.b.i0.c x(long j2) {
        F(new g.e.b.u(Long.valueOf(j2)));
        return this;
    }

    @Override // g.e.b.i0.c
    public g.e.b.i0.c z(Boolean bool) {
        if (bool == null) {
            F(g.e.b.q.a);
            return this;
        }
        F(new g.e.b.u(bool));
        return this;
    }
}
