package c.i.d.q.x; import c.i.d.g; import c.i.d.j; import c.i.d.k; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.List; /* compiled from: JsonTreeWriter */ public final class b extends JsonWriter { public static final Writer t = new a(); public static final k u = new k("closed"); public final List v = new ArrayList(); public String w; /* renamed from: x reason: collision with root package name */ public JsonElement f1433x = j.a; /* compiled from: JsonTreeWriter */ public class a extends Writer { @Override // java.io.Writer, java.io.Closeable, java.lang.AutoCloseable public void close() throws IOException { throw new AssertionError(); } @Override // java.io.Writer, java.io.Flushable public void flush() throws IOException { throw new AssertionError(); } @Override // java.io.Writer public void write(char[] cArr, int i, int i2) { throw new AssertionError(); } } public b() { super(t); } @Override // com.google.gson.stream.JsonWriter public JsonWriter A(long j) throws IOException { O(new k(Long.valueOf(j))); return this; } @Override // com.google.gson.stream.JsonWriter public JsonWriter C(Boolean bool) throws IOException { if (bool == null) { O(j.a); return this; } O(new k(bool)); return this; } @Override // com.google.gson.stream.JsonWriter public JsonWriter D(Number number) throws IOException { if (number == null) { O(j.a); return this; } if (!this.p) { double doubleValue = number.doubleValue(); if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) { throw new IllegalArgumentException("JSON forbids NaN and infinities: " + number); } } O(new k(number)); return this; } @Override // com.google.gson.stream.JsonWriter public JsonWriter H(String str) throws IOException { if (str == null) { O(j.a); return this; } O(new k(str)); return this; } @Override // com.google.gson.stream.JsonWriter public JsonWriter I(boolean z2) throws IOException { O(new k(Boolean.valueOf(z2))); return this; } public JsonElement L() { if (this.v.isEmpty()) { return this.f1433x; } StringBuilder R = c.d.b.a.a.R("Expected one JSON element but was "); R.append(this.v); throw new IllegalStateException(R.toString()); } public final JsonElement N() { List list = this.v; return list.get(list.size() - 1); } public final void O(JsonElement jsonElement) { if (this.w != null) { if (!(jsonElement instanceof j) || this.f2473s) { ((JsonObject) N()).a.put(this.w, jsonElement); } this.w = null; } else if (this.v.isEmpty()) { this.f1433x = jsonElement; } else { JsonElement N = N(); if (N instanceof g) { ((g) N).i.add(jsonElement); return; } throw new IllegalStateException(); } } @Override // com.google.gson.stream.JsonWriter public JsonWriter b() throws IOException { g gVar = new g(); O(gVar); this.v.add(gVar); return this; } @Override // com.google.gson.stream.JsonWriter public JsonWriter c() throws IOException { JsonObject jsonObject = new JsonObject(); O(jsonObject); this.v.add(jsonObject); return this; } @Override // com.google.gson.stream.JsonWriter, java.io.Closeable, java.lang.AutoCloseable public void close() throws IOException { if (this.v.isEmpty()) { this.v.add(u); return; } throw new IOException("Incomplete document"); } @Override // com.google.gson.stream.JsonWriter public JsonWriter e() throws IOException { if (this.v.isEmpty() || this.w != null) { throw new IllegalStateException(); } else if (N() instanceof g) { List list = this.v; list.remove(list.size() - 1); return this; } else { throw new IllegalStateException(); } } @Override // com.google.gson.stream.JsonWriter public JsonWriter f() throws IOException { if (this.v.isEmpty() || this.w != null) { throw new IllegalStateException(); } else if (N() instanceof JsonObject) { List list = this.v; list.remove(list.size() - 1); return this; } else { throw new IllegalStateException(); } } @Override // com.google.gson.stream.JsonWriter, java.io.Flushable public void flush() throws IOException { } @Override // com.google.gson.stream.JsonWriter public JsonWriter n(String str) throws IOException { if (this.v.isEmpty() || this.w != null) { throw new IllegalStateException(); } else if (N() instanceof JsonObject) { this.w = str; return this; } else { throw new IllegalStateException(); } } @Override // com.google.gson.stream.JsonWriter public JsonWriter s() throws IOException { O(j.a); return this; } }