package androidx.collection;

import java.util.Arrays;

/* loaded from: classes.dex */
public class u0 implements Cloneable {

    /* renamed from: p, reason: collision with root package name */
    public /* synthetic */ boolean f1394p;

    /* renamed from: q, reason: collision with root package name */
    public /* synthetic */ int[] f1395q;

    /* renamed from: r, reason: collision with root package name */
    public /* synthetic */ Object[] f1396r;

    /* renamed from: s, reason: collision with root package name */
    public /* synthetic */ int f1397s;

    public u0() {
        this(0, 1, null);
    }

    public void a(int i10, Object obj) {
        int i11 = this.f1397s;
        if (i11 != 0 && i10 <= this.f1395q[i11 - 1]) {
            n(i10, obj);
            return;
        }
        if (this.f1394p && i11 >= this.f1395q.length) {
            v0.d(this);
        }
        int i12 = this.f1397s;
        if (i12 >= this.f1395q.length) {
            int e10 = w.a.e(i12 + 1);
            int[] copyOf = Arrays.copyOf(this.f1395q, e10);
            kotlin.jvm.internal.t.f(copyOf, "copyOf(this, newSize)");
            this.f1395q = copyOf;
            Object[] copyOf2 = Arrays.copyOf(this.f1396r, e10);
            kotlin.jvm.internal.t.f(copyOf2, "copyOf(this, newSize)");
            this.f1396r = copyOf2;
        }
        this.f1395q[i12] = i10;
        this.f1396r[i12] = obj;
        this.f1397s = i12 + 1;
    }

    public void b() {
        int i10 = this.f1397s;
        Object[] objArr = this.f1396r;
        for (int i11 = 0; i11 < i10; i11++) {
            objArr[i11] = null;
        }
        this.f1397s = 0;
        this.f1394p = false;
    }

    /* renamed from: c, reason: merged with bridge method [inline-methods] */
    public u0 clone() {
        Object clone = super.clone();
        kotlin.jvm.internal.t.e(clone, "null cannot be cast to non-null type androidx.collection.SparseArrayCompat<E of androidx.collection.SparseArrayCompat>");
        u0 u0Var = (u0) clone;
        u0Var.f1395q = (int[]) this.f1395q.clone();
        u0Var.f1396r = (Object[]) this.f1396r.clone();
        return u0Var;
    }

    public boolean d(int i10) {
        return i(i10) >= 0;
    }

    public boolean f(Object obj) {
        if (this.f1394p) {
            v0.d(this);
        }
        int i10 = this.f1397s;
        int i11 = 0;
        while (true) {
            if (i11 >= i10) {
                i11 = -1;
                break;
            }
            if (this.f1396r[i11] == obj) {
                break;
            }
            i11++;
        }
        return i11 >= 0;
    }

    public Object h(int i10) {
        return v0.c(this, i10);
    }

    public int i(int i10) {
        if (this.f1394p) {
            v0.d(this);
        }
        return w.a.a(this.f1395q, this.f1397s, i10);
    }

    public int j(Object obj) {
        if (this.f1394p) {
            v0.d(this);
        }
        int i10 = this.f1397s;
        for (int i11 = 0; i11 < i10; i11++) {
            if (this.f1396r[i11] == obj) {
                return i11;
            }
        }
        return -1;
    }

    public boolean k() {
        return q() == 0;
    }

    public int l(int i10) {
        if (this.f1394p) {
            v0.d(this);
        }
        return this.f1395q[i10];
    }

    public void n(int i10, Object obj) {
        Object obj2;
        int a10 = w.a.a(this.f1395q, this.f1397s, i10);
        if (a10 >= 0) {
            this.f1396r[a10] = obj;
            return;
        }
        int i11 = ~a10;
        if (i11 < this.f1397s) {
            Object obj3 = this.f1396r[i11];
            obj2 = v0.f1399a;
            if (obj3 == obj2) {
                this.f1395q[i11] = i10;
                this.f1396r[i11] = obj;
                return;
            }
        }
        if (this.f1394p && this.f1397s >= this.f1395q.length) {
            v0.d(this);
            i11 = ~w.a.a(this.f1395q, this.f1397s, i10);
        }
        int i12 = this.f1397s;
        if (i12 >= this.f1395q.length) {
            int e10 = w.a.e(i12 + 1);
            int[] copyOf = Arrays.copyOf(this.f1395q, e10);
            kotlin.jvm.internal.t.f(copyOf, "copyOf(this, newSize)");
            this.f1395q = copyOf;
            Object[] copyOf2 = Arrays.copyOf(this.f1396r, e10);
            kotlin.jvm.internal.t.f(copyOf2, "copyOf(this, newSize)");
            this.f1396r = copyOf2;
        }
        int i13 = this.f1397s;
        if (i13 - i11 != 0) {
            int[] iArr = this.f1395q;
            int i14 = i11 + 1;
            sm.o.j(iArr, iArr, i14, i11, i13);
            Object[] objArr = this.f1396r;
            sm.o.l(objArr, objArr, i14, i11, this.f1397s);
        }
        this.f1395q[i11] = i10;
        this.f1396r[i11] = obj;
        this.f1397s++;
    }

    public void o(int i10) {
        Object obj;
        Object obj2;
        Object obj3 = this.f1396r[i10];
        obj = v0.f1399a;
        if (obj3 != obj) {
            Object[] objArr = this.f1396r;
            obj2 = v0.f1399a;
            objArr[i10] = obj2;
            this.f1394p = true;
        }
    }

    public Object p(int i10, Object obj) {
        int i11 = i(i10);
        if (i11 < 0) {
            return null;
        }
        Object[] objArr = this.f1396r;
        Object obj2 = objArr[i11];
        objArr[i11] = obj;
        return obj2;
    }

    public int q() {
        if (this.f1394p) {
            v0.d(this);
        }
        return this.f1397s;
    }

    public Object s(int i10) {
        if (this.f1394p) {
            v0.d(this);
        }
        return this.f1396r[i10];
    }

    public String toString() {
        if (q() <= 0) {
            return "{}";
        }
        StringBuilder sb2 = new StringBuilder(this.f1397s * 28);
        sb2.append('{');
        int i10 = this.f1397s;
        for (int i11 = 0; i11 < i10; i11++) {
            if (i11 > 0) {
                sb2.append(", ");
            }
            sb2.append(l(i11));
            sb2.append('=');
            Object s10 = s(i11);
            if (s10 != this) {
                sb2.append(s10);
            } else {
                sb2.append("(this Map)");
            }
        }
        sb2.append('}');
        String sb3 = sb2.toString();
        kotlin.jvm.internal.t.f(sb3, "buffer.toString()");
        return sb3;
    }

    public u0(int i10) {
        if (i10 == 0) {
            this.f1395q = w.a.f40528a;
            this.f1396r = w.a.f40530c;
        } else {
            int e10 = w.a.e(i10);
            this.f1395q = new int[e10];
            this.f1396r = new Object[e10];
        }
    }

    public /* synthetic */ u0(int i10, int i11, kotlin.jvm.internal.k kVar) {
        this((i11 & 1) != 0 ? 10 : i10);
    }
}
