package c.d;

/* 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 f1353i = new Object();

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

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

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

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

    public h() {
        this(10);
    }

    private void e() {
        int i2 = this.f1357h;
        int[] iArr = this.f1355f;
        Object[] objArr = this.f1356g;
        int i3 = 0;
        for (int i4 = 0; i4 < i2; i4++) {
            Object obj = objArr[i4];
            if (obj != f1353i) {
                if (i4 != i3) {
                    iArr[i3] = iArr[i4];
                    objArr[i3] = obj;
                    objArr[i4] = null;
                }
                i3++;
            }
        }
        this.f1354b = false;
        this.f1357h = i3;
    }

    public void a(int i2, E e2) {
        int i3 = this.f1357h;
        if (i3 != 0 && i2 <= this.f1355f[i3 - 1]) {
            i(i2, e2);
            return;
        }
        if (this.f1354b && this.f1357h >= this.f1355f.length) {
            e();
        }
        int i4 = this.f1357h;
        if (i4 >= this.f1355f.length) {
            int iE = c.e(i4 + 1);
            int[] iArr = new int[iE];
            Object[] objArr = new Object[iE];
            int[] iArr2 = this.f1355f;
            System.arraycopy(iArr2, 0, iArr, 0, iArr2.length);
            Object[] objArr2 = this.f1356g;
            System.arraycopy(objArr2, 0, objArr, 0, objArr2.length);
            this.f1355f = iArr;
            this.f1356g = objArr;
        }
        this.f1355f[i4] = i2;
        this.f1356g[i4] = e2;
        this.f1357h = i4 + 1;
    }

    public void b() {
        int i2 = this.f1357h;
        Object[] objArr = this.f1356g;
        for (int i3 = 0; i3 < i2; i3++) {
            objArr[i3] = null;
        }
        this.f1357h = 0;
        this.f1354b = 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.f1355f = (int[]) this.f1355f.clone();
            hVar.f1356g = (Object[]) this.f1356g.clone();
            return hVar;
        } catch (CloneNotSupportedException e2) {
            throw new AssertionError(e2);
        }
    }

    public E f(int i2) {
        return g(i2, null);
    }

    public E g(int i2, E e2) {
        int iA = c.a(this.f1355f, this.f1357h, i2);
        if (iA >= 0) {
            Object[] objArr = this.f1356g;
            if (objArr[iA] != f1353i) {
                return (E) objArr[iA];
            }
        }
        return e2;
    }

    public int h(int i2) {
        if (this.f1354b) {
            e();
        }
        return this.f1355f[i2];
    }

    public void i(int i2, E e2) {
        int iA = c.a(this.f1355f, this.f1357h, i2);
        if (iA >= 0) {
            this.f1356g[iA] = e2;
            return;
        }
        int i3 = ~iA;
        if (i3 < this.f1357h) {
            Object[] objArr = this.f1356g;
            if (objArr[i3] == f1353i) {
                this.f1355f[i3] = i2;
                objArr[i3] = e2;
                return;
            }
        }
        if (this.f1354b && this.f1357h >= this.f1355f.length) {
            e();
            i3 = ~c.a(this.f1355f, this.f1357h, i2);
        }
        int i4 = this.f1357h;
        if (i4 >= this.f1355f.length) {
            int iE = c.e(i4 + 1);
            int[] iArr = new int[iE];
            Object[] objArr2 = new Object[iE];
            int[] iArr2 = this.f1355f;
            System.arraycopy(iArr2, 0, iArr, 0, iArr2.length);
            Object[] objArr3 = this.f1356g;
            System.arraycopy(objArr3, 0, objArr2, 0, objArr3.length);
            this.f1355f = iArr;
            this.f1356g = objArr2;
        }
        int i5 = this.f1357h;
        if (i5 - i3 != 0) {
            int[] iArr3 = this.f1355f;
            int i6 = i3 + 1;
            System.arraycopy(iArr3, i3, iArr3, i6, i5 - i3);
            Object[] objArr4 = this.f1356g;
            System.arraycopy(objArr4, i3, objArr4, i6, this.f1357h - i3);
        }
        this.f1355f[i3] = i2;
        this.f1356g[i3] = e2;
        this.f1357h++;
    }

    public int j() {
        if (this.f1354b) {
            e();
        }
        return this.f1357h;
    }

    public E k(int i2) {
        if (this.f1354b) {
            e();
        }
        return (E) this.f1356g[i2];
    }

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

    public h(int i2) {
        this.f1354b = false;
        if (i2 == 0) {
            this.f1355f = c.a;
            this.f1356g = c.f1319c;
        } else {
            int iE = c.e(i2);
            this.f1355f = new int[iE];
            this.f1356g = new Object[iE];
        }
    }
}
