package androidx.room;

import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

/* JADX INFO: loaded from: classes.dex */
public final class s0 implements l3.i, l3.h {

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public static final TreeMap f4144i = new TreeMap();

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final int f4145a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public volatile String f4146b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final long[] f4147c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final double[] f4148d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final String[] f4149e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final byte[][] f4150f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final int[] f4151g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f4152h;

    public s0(int i10) {
        this.f4145a = i10;
        int i11 = i10 + 1;
        this.f4151g = new int[i11];
        this.f4147c = new long[i11];
        this.f4148d = new double[i11];
        this.f4149e = new String[i11];
        this.f4150f = new byte[i11][];
    }

    public static final s0 k(int i10, String str) {
        TreeMap treeMap = f4144i;
        synchronized (treeMap) {
            Map.Entry entryCeilingEntry = treeMap.ceilingEntry(Integer.valueOf(i10));
            if (entryCeilingEntry == null) {
                s0 s0Var = new s0(i10);
                s0Var.f4146b = str;
                s0Var.f4152h = i10;
                return s0Var;
            }
            treeMap.remove(entryCeilingEntry.getKey());
            s0 s0Var2 = (s0) entryCeilingEntry.getValue();
            s0Var2.f4146b = str;
            s0Var2.f4152h = i10;
            return s0Var2;
        }
    }

    @Override // l3.h
    public final void a(int i10, long j10) {
        this.f4151g[i10] = 2;
        this.f4147c[i10] = j10;
    }

    @Override // l3.h
    public final void b(double d10, int i10) {
        this.f4151g[i10] = 3;
        this.f4148d[i10] = d10;
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
    }

    @Override // l3.h
    public final void d(int i10) {
        this.f4151g[i10] = 1;
    }

    @Override // l3.i
    public final String e() {
        String str = this.f4146b;
        if (str != null) {
            return str;
        }
        throw new IllegalStateException("Required value was null.".toString());
    }

    @Override // l3.i
    public final void g(l3.h hVar) {
        int i10 = this.f4152h;
        if (1 > i10) {
            return;
        }
        int i11 = 1;
        while (true) {
            int i12 = this.f4151g[i11];
            if (i12 == 1) {
                hVar.d(i11);
            } else if (i12 == 2) {
                hVar.a(i11, this.f4147c[i11]);
            } else if (i12 == 3) {
                hVar.b(this.f4148d[i11], i11);
            } else if (i12 == 4) {
                String str = this.f4149e[i11];
                if (str == null) {
                    throw new IllegalArgumentException("Required value was null.".toString());
                }
                hVar.l(i11, str);
            } else if (i12 == 5) {
                byte[] bArr = this.f4150f[i11];
                if (bArr == null) {
                    throw new IllegalArgumentException("Required value was null.".toString());
                }
                hVar.w(i11, bArr);
            }
            if (i11 == i10) {
                return;
            } else {
                i11++;
            }
        }
    }

    @Override // l3.h
    public final void l(int i10, String str) {
        nb.g.i(str, "value");
        this.f4151g[i10] = 4;
        this.f4149e[i10] = str;
    }

    public final void m() {
        TreeMap treeMap = f4144i;
        synchronized (treeMap) {
            treeMap.put(Integer.valueOf(this.f4145a), this);
            if (treeMap.size() > 15) {
                int size = treeMap.size() - 10;
                Iterator it = treeMap.descendingKeySet().iterator();
                nb.g.h(it, "iterator(...)");
                while (true) {
                    int i10 = size - 1;
                    if (size <= 0) {
                        break;
                    }
                    it.next();
                    it.remove();
                    size = i10;
                }
            }
        }
    }

    @Override // l3.h
    public final void w(int i10, byte[] bArr) {
        this.f4151g[i10] = 5;
        this.f4150f[i10] = bArr;
    }
}
