package a.b;

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

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

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

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

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

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

    public g() {
        this(10);
    }

    private void c() {
        int i = this.f147g;
        int[] iArr = this.f145e;
        Object[] objArr = this.f146f;
        int i2 = 0;
        for (int i3 = 0; i3 < i; i3++) {
            Object obj = objArr[i3];
            if (obj != f143c) {
                if (i3 != i2) {
                    iArr[i2] = iArr[i3];
                    objArr[i2] = obj;
                    objArr[i3] = null;
                }
                i2++;
            }
        }
        this.f144d = false;
        this.f147g = i2;
    }

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

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

    public E d(int i) {
        return e(i, null);
    }

    public E e(int i, E e2) {
        int iA = b.a(this.f145e, this.f147g, i);
        if (iA >= 0) {
            Object[] objArr = this.f146f;
            if (objArr[iA] != f143c) {
                return (E) objArr[iA];
            }
        }
        return e2;
    }

    public int f(int i) {
        if (this.f144d) {
            c();
        }
        return this.f145e[i];
    }

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

    public int h() {
        if (this.f144d) {
            c();
        }
        return this.f147g;
    }

    public E i(int i) {
        if (this.f144d) {
            c();
        }
        return (E) this.f146f[i];
    }

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

    public g(int i) {
        this.f144d = false;
        if (i == 0) {
            this.f145e = b.f108a;
            this.f146f = b.f110c;
        } else {
            int iE = b.e(i);
            this.f145e = new int[iE];
            this.f146f = new Object[iE];
        }
        this.f147g = 0;
    }
}
