package androidx.collection; /* loaded from: classes.dex */ public class SparseArrayCompat implements Cloneable { private static final Object e = new Object(); private boolean a; private int[] b; private Object[] c; private int d; public SparseArrayCompat() { this(10); } private void h() { int i = this.d; int[] iArr = 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) { iArr[i2] = iArr[i3]; objArr[i2] = obj; objArr[i3] = null; } i2++; } } this.a = false; this.d = i2; } public void a(int i) { int a = ContainerHelpers.a(this.b, this.d, i); 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(int i) { return b(i, null); } public void c(int i, E e2) { int a = ContainerHelpers.a(this.b, this.d, i); if (a >= 0) { this.c[a] = e2; return; } int i2 = ~a; if (i2 < this.d) { Object[] objArr = this.c; if (objArr[i2] == e) { this.b[i2] = i; objArr[i2] = e2; return; } } if (this.a && this.d >= this.b.length) { h(); i2 = ~ContainerHelpers.a(this.b, this.d, i); } int i3 = this.d; if (i3 >= this.b.length) { int b = ContainerHelpers.b(i3 + 1); int[] iArr = new int[b]; Object[] objArr2 = new Object[b]; int[] iArr2 = this.b; System.arraycopy(iArr2, 0, iArr, 0, iArr2.length); Object[] objArr3 = this.c; System.arraycopy(objArr3, 0, objArr2, 0, objArr3.length); this.b = iArr; this.c = objArr2; } int i4 = this.d; if (i4 - i2 != 0) { int[] iArr3 = this.b; int i5 = i2 + 1; System.arraycopy(iArr3, i2, iArr3, i5, i4 - i2); Object[] objArr4 = this.c; System.arraycopy(objArr4, i2, objArr4, i5, this.d - i2); } this.b[i2] = i; this.c[i2] = e2; this.d++; } public int d(int i) { if (this.a) { h(); } return this.b[i]; } public void e(int i) { a(i); } public E f(int i) { if (this.a) { h(); } return (E) this.c[i]; } 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(d(i)); sb.append('='); E f = f(i); if (f != this) { sb.append(f); } else { sb.append("(this Map)"); } } sb.append('}'); return sb.toString(); } public SparseArrayCompat(int i) { this.a = false; if (i == 0) { this.b = ContainerHelpers.a; this.c = ContainerHelpers.c; } else { int b = ContainerHelpers.b(i); this.b = new int[b]; this.c = new Object[b]; } this.d = 0; } public E b(int i, E e2) { int a = ContainerHelpers.a(this.b, this.d, i); 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 SparseArrayCompat m1clone() { try { SparseArrayCompat sparseArrayCompat = (SparseArrayCompat) super.clone(); sparseArrayCompat.b = (int[]) this.b.clone(); sparseArrayCompat.c = (Object[]) this.c.clone(); return sparseArrayCompat; } catch (CloneNotSupportedException e2) { throw new AssertionError(e2); } } 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(int i, E e2) { int i2 = this.d; if (i2 != 0 && i <= this.b[i2 - 1]) { c(i, e2); return; } if (this.a && this.d >= this.b.length) { h(); } int i3 = this.d; if (i3 >= this.b.length) { int b = ContainerHelpers.b(i3 + 1); int[] iArr = new int[b]; Object[] objArr = new Object[b]; int[] iArr2 = this.b; System.arraycopy(iArr2, 0, iArr, 0, iArr2.length); Object[] objArr2 = this.c; System.arraycopy(objArr2, 0, objArr, 0, objArr2.length); this.b = iArr; this.c = objArr; } this.b[i3] = i; this.c[i3] = e2; this.d = i3 + 1; } public int c(int i) { if (this.a) { h(); } return ContainerHelpers.a(this.b, this.d, i); } }