package com.facetec.sdk; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.List; /* loaded from: classes.dex */ public final class fl extends ga { private eb b; private String d; private final List e; private static final Writer c = new Writer() { // from class: com.facetec.sdk.fl.2 @Override // java.io.Writer public final void write(char[] cArr, int i, int i2) { throw new AssertionError(); } @Override // java.io.Writer, java.io.Flushable public final void flush() throws IOException { throw new AssertionError(); } @Override // java.io.Writer, java.io.Closeable, java.lang.AutoCloseable public final void close() throws IOException { throw new AssertionError(); } }; private static final eh a = new eh("closed"); @Override // com.facetec.sdk.ga, java.io.Flushable public final void flush() throws IOException { } public fl() { super(c); this.e = new ArrayList(); this.b = ea.a; } public final eb c() { if (this.e.isEmpty()) { return this.b; } StringBuilder sb = new StringBuilder("Expected one JSON element but was "); sb.append(this.e); throw new IllegalStateException(sb.toString()); } private eb g() { return this.e.get(r0.size() - 1); } private void b(eb ebVar) { if (this.d != null) { if (!ebVar.h() || f()) { ((ec) g()).b(this.d, ebVar); } this.d = null; return; } if (this.e.isEmpty()) { this.b = ebVar; return; } eb g = g(); if (g instanceof dy) { ((dy) g).d(ebVar); return; } throw new IllegalStateException(); } @Override // com.facetec.sdk.ga public final ga e() throws IOException { dy dyVar = new dy(); b(dyVar); this.e.add(dyVar); return this; } @Override // com.facetec.sdk.ga public final ga b() throws IOException { if (this.e.isEmpty() || this.d != null) { throw new IllegalStateException(); } if (g() instanceof dy) { this.e.remove(r0.size() - 1); return this; } throw new IllegalStateException(); } @Override // com.facetec.sdk.ga public final ga d() throws IOException { ec ecVar = new ec(); b(ecVar); this.e.add(ecVar); return this; } @Override // com.facetec.sdk.ga public final ga a() throws IOException { if (this.e.isEmpty() || this.d != null) { throw new IllegalStateException(); } if (g() instanceof ec) { this.e.remove(r0.size() - 1); return this; } throw new IllegalStateException(); } @Override // com.facetec.sdk.ga public final ga c(String str) throws IOException { if (this.e.isEmpty() || this.d != null) { throw new IllegalStateException(); } if (!(g() instanceof ec)) { throw new IllegalStateException(); } this.d = str; return this; } @Override // com.facetec.sdk.ga public final ga b(String str) throws IOException { if (str == null) { return h(); } b(new eh(str)); return this; } @Override // com.facetec.sdk.ga public final ga h() throws IOException { b(ea.a); return this; } @Override // com.facetec.sdk.ga public final ga a(boolean z) throws IOException { b(new eh(Boolean.valueOf(z))); return this; } @Override // com.facetec.sdk.ga public final ga d(Boolean bool) throws IOException { if (bool == null) { return h(); } b(new eh(bool)); return this; } @Override // com.facetec.sdk.ga public final ga c(long j) throws IOException { b(new eh(Long.valueOf(j))); return this; } @Override // com.facetec.sdk.ga public final ga b(Number number) throws IOException { if (number == null) { return h(); } if (!i()) { double doubleValue = number.doubleValue(); if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) { throw new IllegalArgumentException("JSON forbids NaN and infinities: ".concat(String.valueOf(number))); } } b(new eh(number)); return this; } @Override // com.facetec.sdk.ga, java.io.Closeable, java.lang.AutoCloseable public final void close() throws IOException { if (!this.e.isEmpty()) { throw new IOException("Incomplete document"); } this.e.add(a); } }