package androidx.datastore.preferences.protobuf;

import java.util.AbstractList;
import java.util.Arrays;
import java.util.RandomAccess;

/* JADX INFO: loaded from: classes.dex */
public final class w0 extends c implements RandomAccess {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final w0 f2165d = new w0(new Object[0], 0, false);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Object[] f2166b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f2167c;

    public w0(Object[] objArr, int i10, boolean z10) {
        this.f2049a = z10;
        this.f2166b = objArr;
        this.f2167c = i10;
    }

    @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List
    public final boolean add(Object obj) {
        c();
        int i10 = this.f2167c;
        Object[] objArr = this.f2166b;
        if (i10 == objArr.length) {
            this.f2166b = Arrays.copyOf(objArr, ((i10 * 3) / 2) + 1);
        }
        Object[] objArr2 = this.f2166b;
        int i11 = this.f2167c;
        this.f2167c = i11 + 1;
        objArr2[i11] = obj;
        ((AbstractList) this).modCount++;
        return true;
    }

    public final void f(int i10) {
        if (i10 < 0 || i10 >= this.f2167c) {
            StringBuilder sbQ = defpackage.e.q("Index:", i10, ", Size:");
            sbQ.append(this.f2167c);
            throw new IndexOutOfBoundsException(sbQ.toString());
        }
    }

    public final w0 g(int i10) {
        if (i10 >= this.f2167c) {
            return new w0(Arrays.copyOf(this.f2166b, i10), this.f2167c, true);
        }
        throw new IllegalArgumentException();
    }

    @Override // java.util.AbstractList, java.util.List
    public final Object get(int i10) {
        f(i10);
        return this.f2166b[i10];
    }

    @Override // androidx.datastore.preferences.protobuf.c, java.util.AbstractList, java.util.List
    public final Object remove(int i10) {
        c();
        f(i10);
        Object[] objArr = this.f2166b;
        Object obj = objArr[i10];
        if (i10 < this.f2167c - 1) {
            System.arraycopy(objArr, i10 + 1, objArr, i10, (r2 - i10) - 1);
        }
        this.f2167c--;
        ((AbstractList) this).modCount++;
        return obj;
    }

    @Override // java.util.AbstractList, java.util.List
    public final Object set(int i10, Object obj) {
        c();
        f(i10);
        Object[] objArr = this.f2166b;
        Object obj2 = objArr[i10];
        objArr[i10] = obj;
        ((AbstractList) this).modCount++;
        return obj2;
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
    public final int size() {
        return this.f2167c;
    }

    @Override // java.util.AbstractList, java.util.List
    public final void add(int i10, Object obj) {
        int i11;
        c();
        if (i10 >= 0 && i10 <= (i11 = this.f2167c)) {
            Object[] objArr = this.f2166b;
            if (i11 < objArr.length) {
                System.arraycopy(objArr, i10, objArr, i10 + 1, i11 - i10);
            } else {
                Object[] objArr2 = new Object[defpackage.e.C(i11, 3, 2, 1)];
                System.arraycopy(objArr, 0, objArr2, 0, i10);
                System.arraycopy(this.f2166b, i10, objArr2, i10 + 1, this.f2167c - i10);
                this.f2166b = objArr2;
            }
            this.f2166b[i10] = obj;
            this.f2167c++;
            ((AbstractList) this).modCount++;
            return;
        }
        StringBuilder sbQ = defpackage.e.q("Index:", i10, ", Size:");
        sbQ.append(this.f2167c);
        throw new IndexOutOfBoundsException(sbQ.toString());
    }
}
