package a.b.c.f;

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

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

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

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

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

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

    public l() {
        this(10);
    }

    private void e() {
        int i = this.f223e;
        int[] iArr = this.f221c;
        Object[] objArr = this.f222d;
        int i2 = 0;
        for (int i3 = 0; i3 < i; i3++) {
            Object obj = objArr[i3];
            if (obj != f219f) {
                if (i3 != i2) {
                    iArr[i2] = iArr[i3];
                    objArr[i2] = obj;
                    objArr[i3] = null;
                }
                i2++;
            }
        }
        this.f220b = false;
        this.f223e = i2;
    }

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

    public void b() {
        int i = this.f223e;
        Object[] objArr = this.f222d;
        for (int i2 = 0; i2 < i; i2++) {
            objArr[i2] = null;
        }
        this.f223e = 0;
        this.f220b = false;
    }

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

    public void d(int i) {
        int iA = c.a(this.f221c, this.f223e, i);
        if (iA >= 0) {
            Object[] objArr = this.f222d;
            Object obj = objArr[iA];
            Object obj2 = f219f;
            if (obj != obj2) {
                objArr[iA] = obj2;
                this.f220b = true;
            }
        }
    }

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

    public E g(int i, E e2) {
        int iA = c.a(this.f221c, this.f223e, i);
        if (iA >= 0) {
            Object[] objArr = this.f222d;
            if (objArr[iA] != f219f) {
                return (E) objArr[iA];
            }
        }
        return e2;
    }

    public int h(int i) {
        if (this.f220b) {
            e();
        }
        return this.f221c[i];
    }

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

    public void j(int i) {
        d(i);
    }

    public int k() {
        if (this.f220b) {
            e();
        }
        return this.f223e;
    }

    public E l(int i) {
        if (this.f220b) {
            e();
        }
        return (E) this.f222d[i];
    }

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

    public l(int i) {
        this.f220b = false;
        if (i == 0) {
            this.f221c = c.f183a;
            this.f222d = c.f185c;
        } else {
            int iE = c.e(i);
            this.f221c = new int[iE];
            this.f222d = new Object[iE];
        }
        this.f223e = 0;
    }
}
