package a.b.c.f;

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

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

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

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

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

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

    public f() {
        this(10);
    }

    private void e() {
        int i = this.f192e;
        long[] jArr = this.f190c;
        Object[] objArr = this.f191d;
        int i2 = 0;
        for (int i3 = 0; i3 < i; i3++) {
            Object obj = objArr[i3];
            if (obj != f188f) {
                if (i3 != i2) {
                    jArr[i2] = jArr[i3];
                    objArr[i2] = obj;
                    objArr[i3] = null;
                }
                i2++;
            }
        }
        this.f189b = false;
        this.f192e = i2;
    }

    public void a(long j, E e2) {
        int i = this.f192e;
        if (i != 0 && j <= this.f190c[i - 1]) {
            i(j, e2);
            return;
        }
        if (this.f189b && this.f192e >= this.f190c.length) {
            e();
        }
        int i2 = this.f192e;
        if (i2 >= this.f190c.length) {
            int iF = c.f(i2 + 1);
            long[] jArr = new long[iF];
            Object[] objArr = new Object[iF];
            long[] jArr2 = this.f190c;
            System.arraycopy(jArr2, 0, jArr, 0, jArr2.length);
            Object[] objArr2 = this.f191d;
            System.arraycopy(objArr2, 0, objArr, 0, objArr2.length);
            this.f190c = jArr;
            this.f191d = objArr;
        }
        this.f190c[i2] = j;
        this.f191d[i2] = e2;
        this.f192e = i2 + 1;
    }

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

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

    public void d(long j) {
        int iB = c.b(this.f190c, this.f192e, j);
        if (iB >= 0) {
            Object[] objArr = this.f191d;
            Object obj = objArr[iB];
            Object obj2 = f188f;
            if (obj != obj2) {
                objArr[iB] = obj2;
                this.f189b = true;
            }
        }
    }

    public E f(long j) {
        return g(j, null);
    }

    public E g(long j, E e2) {
        int iB = c.b(this.f190c, this.f192e, j);
        if (iB >= 0) {
            Object[] objArr = this.f191d;
            if (objArr[iB] != f188f) {
                return (E) objArr[iB];
            }
        }
        return e2;
    }

    public long h(int i) {
        if (this.f189b) {
            e();
        }
        return this.f190c[i];
    }

    public void i(long j, E e2) {
        int iB = c.b(this.f190c, this.f192e, j);
        if (iB >= 0) {
            this.f191d[iB] = e2;
            return;
        }
        int i = ~iB;
        if (i < this.f192e) {
            Object[] objArr = this.f191d;
            if (objArr[i] == f188f) {
                this.f190c[i] = j;
                objArr[i] = e2;
                return;
            }
        }
        if (this.f189b && this.f192e >= this.f190c.length) {
            e();
            i = ~c.b(this.f190c, this.f192e, j);
        }
        int i2 = this.f192e;
        if (i2 >= this.f190c.length) {
            int iF = c.f(i2 + 1);
            long[] jArr = new long[iF];
            Object[] objArr2 = new Object[iF];
            long[] jArr2 = this.f190c;
            System.arraycopy(jArr2, 0, jArr, 0, jArr2.length);
            Object[] objArr3 = this.f191d;
            System.arraycopy(objArr3, 0, objArr2, 0, objArr3.length);
            this.f190c = jArr;
            this.f191d = objArr2;
        }
        int i3 = this.f192e;
        if (i3 - i != 0) {
            long[] jArr3 = this.f190c;
            int i4 = i + 1;
            System.arraycopy(jArr3, i, jArr3, i4, i3 - i);
            Object[] objArr4 = this.f191d;
            System.arraycopy(objArr4, i, objArr4, i4, this.f192e - i);
        }
        this.f190c[i] = j;
        this.f191d[i] = e2;
        this.f192e++;
    }

    public int j() {
        if (this.f189b) {
            e();
        }
        return this.f192e;
    }

    public E k(int i) {
        if (this.f189b) {
            e();
        }
        return (E) this.f191d[i];
    }

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

    public f(int i) {
        this.f189b = false;
        if (i == 0) {
            this.f190c = c.f184b;
            this.f191d = c.f185c;
        } else {
            int iF = c.f(i);
            this.f190c = new long[iF];
            this.f191d = new Object[iF];
        }
        this.f192e = 0;
    }
}
