package androidx.collection; /* loaded from: classes.dex */ public class LongSparseArray implements Cloneable { private static final Object e = new Object(); private boolean a; private long[] b; private Object[] c; private int d; public LongSparseArray() { this(10); } private void h() { int i = this.d; long[] jArr = this.b; Object[] objArr = this.c; int i2 = 0; for (int i3 = 0; i3 < i; i3++) { Object obj = objArr[i3]; if (obj != e) { if (i3 != i2) { jArr[i2] = jArr[i3]; objArr[i2] = obj; objArr[i3] = null; } i2++; } } this.a = false; this.d = i2; } public void a(long j) { int a = ContainerHelpers.a(this.b, this.d, j); if (a >= 0) { Object[] objArr = this.c; Object obj = objArr[a]; Object obj2 = e; if (obj != obj2) { objArr[a] = obj2; this.a = true; } } } public E b(long j) { return b(j, null); } public void c(long j, E e2) { int a = ContainerHelpers.a(this.b, this.d, j); if (a >= 0) { this.c[a] = e2; return; } int i = ~a; if (i < this.d) { Object[] objArr = this.c; if (objArr[i] == e) { this.b[i] = j; objArr[i] = e2; return; } } if (this.a && this.d >= this.b.length) { h(); i = ~ContainerHelpers.a(this.b, this.d, j); } int i2 = this.d; if (i2 >= this.b.length) { int c = ContainerHelpers.c(i2 + 1); long[] jArr = new long[c]; Object[] objArr2 = new Object[c]; long[] jArr2 = this.b; System.arraycopy(jArr2, 0, jArr, 0, jArr2.length); Object[] objArr3 = this.c; System.arraycopy(objArr3, 0, objArr2, 0, objArr3.length); this.b = jArr; this.c = objArr2; } int i3 = this.d; if (i3 - i != 0) { long[] jArr3 = this.b; int i4 = i + 1; System.arraycopy(jArr3, i, jArr3, i4, i3 - i); Object[] objArr4 = this.c; System.arraycopy(objArr4, i, objArr4, i4, this.d - i); } this.b[i] = j; this.c[i] = e2; this.d++; } public String toString() { if (b() <= 0) { return "{}"; } StringBuilder sb = new StringBuilder(this.d * 28); sb.append('{'); for (int i = 0; i < this.d; i++) { if (i > 0) { sb.append(", "); } sb.append(a(i)); sb.append('='); E c = c(i); if (c != this) { sb.append(c); } else { sb.append("(this Map)"); } } sb.append('}'); return sb.toString(); } public LongSparseArray(int i) { this.a = false; if (i == 0) { this.b = ContainerHelpers.b; this.c = ContainerHelpers.c; } else { int c = ContainerHelpers.c(i); this.b = new long[c]; this.c = new Object[c]; } this.d = 0; } public E b(long j, E e2) { int a = ContainerHelpers.a(this.b, this.d, j); if (a >= 0) { Object[] objArr = this.c; if (objArr[a] != e) { return (E) objArr[a]; } } return e2; } /* renamed from: clone, reason: merged with bridge method [inline-methods] */ public LongSparseArray m0clone() { try { LongSparseArray longSparseArray = (LongSparseArray) super.clone(); longSparseArray.b = (long[]) this.b.clone(); longSparseArray.c = (Object[]) this.c.clone(); return longSparseArray; } catch (CloneNotSupportedException e2) { throw new AssertionError(e2); } } public long a(int i) { if (this.a) { h(); } return this.b[i]; } public void b(int i) { Object[] objArr = this.c; Object obj = objArr[i]; Object obj2 = e; if (obj != obj2) { objArr[i] = obj2; this.a = true; } } public void a() { int i = this.d; Object[] objArr = this.c; for (int i2 = 0; i2 < i; i2++) { objArr[i2] = null; } this.d = 0; this.a = false; } public int b() { if (this.a) { h(); } return this.d; } public void a(long j, E e2) { int i = this.d; if (i != 0 && j <= this.b[i - 1]) { c(j, e2); return; } if (this.a && this.d >= this.b.length) { h(); } int i2 = this.d; if (i2 >= this.b.length) { int c = ContainerHelpers.c(i2 + 1); long[] jArr = new long[c]; Object[] objArr = new Object[c]; long[] jArr2 = this.b; System.arraycopy(jArr2, 0, jArr, 0, jArr2.length); Object[] objArr2 = this.c; System.arraycopy(objArr2, 0, objArr, 0, objArr2.length); this.b = jArr; this.c = objArr; } this.b[i2] = j; this.c[i2] = e2; this.d = i2 + 1; } public E c(int i) { if (this.a) { h(); } return (E) this.c[i]; } public int c(long j) { if (this.a) { h(); } return ContainerHelpers.a(this.b, this.d, j); } }