package j;

/* JADX INFO: compiled from: SparseArrayCompat.java */
/* JADX INFO: loaded from: classes.dex */
public class h<E> implements Cloneable {

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private static final Object f4914i = new Object();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private boolean f4915e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private int[] f4916f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private Object[] f4917g;

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

    public h() {
        this(10);
    }

    private void d() {
        int i3 = this.f4918h;
        int[] iArr = this.f4916f;
        Object[] objArr = this.f4917g;
        int i4 = 0;
        for (int i5 = 0; i5 < i3; i5++) {
            Object obj = objArr[i5];
            if (obj != f4914i) {
                if (i5 != i4) {
                    iArr[i4] = iArr[i5];
                    objArr[i4] = obj;
                    objArr[i5] = null;
                }
                i4++;
            }
        }
        this.f4915e = false;
        this.f4918h = i4;
    }

    public void a(int i3, E e3) {
        int i4 = this.f4918h;
        if (i4 != 0 && i3 <= this.f4916f[i4 - 1]) {
            i(i3, e3);
            return;
        }
        if (this.f4915e && i4 >= this.f4916f.length) {
            d();
        }
        int i5 = this.f4918h;
        if (i5 >= this.f4916f.length) {
            int iE = c.e(i5 + 1);
            int[] iArr = new int[iE];
            Object[] objArr = new Object[iE];
            int[] iArr2 = this.f4916f;
            System.arraycopy(iArr2, 0, iArr, 0, iArr2.length);
            Object[] objArr2 = this.f4917g;
            System.arraycopy(objArr2, 0, objArr, 0, objArr2.length);
            this.f4916f = iArr;
            this.f4917g = objArr;
        }
        this.f4916f[i5] = i3;
        this.f4917g[i5] = e3;
        this.f4918h = i5 + 1;
    }

    public void b() {
        int i3 = this.f4918h;
        Object[] objArr = this.f4917g;
        for (int i4 = 0; i4 < i3; i4++) {
            objArr[i4] = null;
        }
        this.f4918h = 0;
        this.f4915e = false;
    }

    /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
    public h<E> clone() {
        try {
            h<E> hVar = (h) super.clone();
            hVar.f4916f = (int[]) this.f4916f.clone();
            hVar.f4917g = (Object[]) this.f4917g.clone();
            return hVar;
        } catch (CloneNotSupportedException e3) {
            throw new AssertionError(e3);
        }
    }

    public E e(int i3) {
        return f(i3, null);
    }

    public E f(int i3, E e3) {
        int iA = c.a(this.f4916f, this.f4918h, i3);
        if (iA >= 0) {
            Object[] objArr = this.f4917g;
            if (objArr[iA] != f4914i) {
                return (E) objArr[iA];
            }
        }
        return e3;
    }

    public int g(E e3) {
        if (this.f4915e) {
            d();
        }
        for (int i3 = 0; i3 < this.f4918h; i3++) {
            if (this.f4917g[i3] == e3) {
                return i3;
            }
        }
        return -1;
    }

    public int h(int i3) {
        if (this.f4915e) {
            d();
        }
        return this.f4916f[i3];
    }

    public void i(int i3, E e3) {
        int iA = c.a(this.f4916f, this.f4918h, i3);
        if (iA >= 0) {
            this.f4917g[iA] = e3;
            return;
        }
        int i4 = ~iA;
        int i5 = this.f4918h;
        if (i4 < i5) {
            Object[] objArr = this.f4917g;
            if (objArr[i4] == f4914i) {
                this.f4916f[i4] = i3;
                objArr[i4] = e3;
                return;
            }
        }
        if (this.f4915e && i5 >= this.f4916f.length) {
            d();
            i4 = ~c.a(this.f4916f, this.f4918h, i3);
        }
        int i6 = this.f4918h;
        if (i6 >= this.f4916f.length) {
            int iE = c.e(i6 + 1);
            int[] iArr = new int[iE];
            Object[] objArr2 = new Object[iE];
            int[] iArr2 = this.f4916f;
            System.arraycopy(iArr2, 0, iArr, 0, iArr2.length);
            Object[] objArr3 = this.f4917g;
            System.arraycopy(objArr3, 0, objArr2, 0, objArr3.length);
            this.f4916f = iArr;
            this.f4917g = objArr2;
        }
        int i7 = this.f4918h;
        if (i7 - i4 != 0) {
            int[] iArr3 = this.f4916f;
            int i8 = i4 + 1;
            System.arraycopy(iArr3, i4, iArr3, i8, i7 - i4);
            Object[] objArr4 = this.f4917g;
            System.arraycopy(objArr4, i4, objArr4, i8, this.f4918h - i4);
        }
        this.f4916f[i4] = i3;
        this.f4917g[i4] = e3;
        this.f4918h++;
    }

    public int j() {
        if (this.f4915e) {
            d();
        }
        return this.f4918h;
    }

    public E k(int i3) {
        if (this.f4915e) {
            d();
        }
        return (E) this.f4917g[i3];
    }

    public String toString() {
        if (j() <= 0) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.f4918h * 28);
        sb.append('{');
        for (int i3 = 0; i3 < this.f4918h; i3++) {
            if (i3 > 0) {
                sb.append(", ");
            }
            sb.append(h(i3));
            sb.append('=');
            E eK = k(i3);
            if (eK != this) {
                sb.append(eK);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        return sb.toString();
    }

    public h(int i3) {
        this.f4915e = false;
        if (i3 == 0) {
            this.f4916f = c.f4876a;
            this.f4917g = c.f4878c;
        } else {
            int iE = c.e(i3);
            this.f4916f = new int[iE];
            this.f4917g = new Object[iE];
        }
    }
}
