package androidx.collection;

import java.util.Arrays;

/* loaded from: classes.dex */
public final class x extends j {
    public /* synthetic */ x(int i10, int i11, kotlin.jvm.internal.k kVar) {
        this((i11 & 1) != 0 ? 16 : i10);
    }

    public final void e(int i10, int i11) {
        boolean z10 = false;
        if (i10 >= 0 && i10 <= this.f1330b) {
            z10 = true;
        }
        if (!z10) {
            throw new IndexOutOfBoundsException("Index " + i10 + " must be in 0.." + this.f1330b);
        }
        h(this.f1330b + 1);
        int[] iArr = this.f1329a;
        int i12 = this.f1330b;
        if (i10 != i12) {
            sm.o.j(iArr, iArr, i10 + 1, i10, i12);
        }
        iArr[i10] = i11;
        this.f1330b++;
    }

    public final boolean f(int i10) {
        h(this.f1330b + 1);
        int[] iArr = this.f1329a;
        int i11 = this.f1330b;
        iArr[i11] = i10;
        this.f1330b = i11 + 1;
        return true;
    }

    public final boolean g(int i10, int[] elements) {
        kotlin.jvm.internal.t.g(elements, "elements");
        if (!(i10 >= 0 && i10 <= this.f1330b)) {
            throw new IndexOutOfBoundsException("Index " + i10 + " must be in 0.." + this.f1330b);
        }
        if (elements.length == 0) {
            return false;
        }
        h(this.f1330b + elements.length);
        int[] iArr = this.f1329a;
        int i11 = this.f1330b;
        if (i10 != i11) {
            sm.o.j(iArr, iArr, elements.length + i10, i10, i11);
        }
        sm.o.o(elements, iArr, i10, 0, 0, 12, null);
        this.f1330b += elements.length;
        return true;
    }

    public final void h(int i10) {
        int[] iArr = this.f1329a;
        if (iArr.length < i10) {
            int[] copyOf = Arrays.copyOf(iArr, Math.max(i10, (iArr.length * 3) / 2));
            kotlin.jvm.internal.t.f(copyOf, "copyOf(this, newSize)");
            this.f1329a = copyOf;
        }
    }

    public final void i(int[] elements) {
        kotlin.jvm.internal.t.g(elements, "elements");
        g(this.f1330b, elements);
    }

    public final int j(int i10) {
        boolean z10 = false;
        if (i10 >= 0 && i10 < this.f1330b) {
            z10 = true;
        }
        if (!z10) {
            throw new IndexOutOfBoundsException("Index " + i10 + " must be in 0.." + (this.f1330b - 1));
        }
        int[] iArr = this.f1329a;
        int i11 = iArr[i10];
        int i12 = this.f1330b;
        if (i10 != i12 - 1) {
            sm.o.j(iArr, iArr, i10, i10 + 1, i12);
        }
        this.f1330b--;
        return i11;
    }

    public final int k(int i10, int i11) {
        boolean z10 = false;
        if (i10 >= 0 && i10 < this.f1330b) {
            z10 = true;
        }
        if (z10) {
            int[] iArr = this.f1329a;
            int i12 = iArr[i10];
            iArr[i10] = i11;
            return i12;
        }
        throw new IndexOutOfBoundsException("set index " + i10 + " must be between 0 .. " + (this.f1330b - 1));
    }

    public final void l() {
        int i10 = this.f1330b;
        if (i10 == 0) {
            return;
        }
        sm.o.D(this.f1329a, 0, i10);
    }

    public x(int i10) {
        super(i10, null);
    }
}
