package androidx.datastore.preferences.protobuf;

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

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

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

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

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

    public S(Object[] objArr, int i, boolean z8) {
        this.f8052q = z8;
        this.f8028r = objArr;
        this.f8029s = i;
    }

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

    public final void b(int i) {
        if (i < 0 || i >= this.f8029s) {
            StringBuilder sbO = AbstractC0844a.o(i, "Index:", ", Size:");
            sbO.append(this.f8029s);
            throw new IndexOutOfBoundsException(sbO.toString());
        }
    }

    public final S c(int i) {
        if (i >= this.f8029s) {
            return new S(Arrays.copyOf(this.f8028r, i), this.f8029s, true);
        }
        throw new IllegalArgumentException();
    }

    @Override // java.util.AbstractList, java.util.List
    public final Object get(int i) {
        b(i);
        return this.f8028r[i];
    }

    @Override // androidx.datastore.preferences.protobuf.AbstractC0424b, java.util.AbstractList, java.util.List
    public final Object remove(int i) {
        a();
        b(i);
        Object[] objArr = this.f8028r;
        Object obj = objArr[i];
        if (i < this.f8029s - 1) {
            System.arraycopy(objArr, i + 1, objArr, i, (r2 - i) - 1);
        }
        this.f8029s--;
        ((AbstractList) this).modCount++;
        return obj;
    }

    @Override // java.util.AbstractList, java.util.List
    public final Object set(int i, Object obj) {
        a();
        b(i);
        Object[] objArr = this.f8028r;
        Object obj2 = objArr[i];
        objArr[i] = obj;
        ((AbstractList) this).modCount++;
        return obj2;
    }

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

    @Override // java.util.AbstractList, java.util.List
    public final void add(int i, Object obj) {
        int i5;
        a();
        if (i >= 0 && i <= (i5 = this.f8029s)) {
            Object[] objArr = this.f8028r;
            if (i5 < objArr.length) {
                System.arraycopy(objArr, i, objArr, i + 1, i5 - i);
            } else {
                Object[] objArr2 = new Object[((i5 * 3) / 2) + 1];
                System.arraycopy(objArr, 0, objArr2, 0, i);
                System.arraycopy(this.f8028r, i, objArr2, i + 1, this.f8029s - i);
                this.f8028r = objArr2;
            }
            this.f8028r[i] = obj;
            this.f8029s++;
            ((AbstractList) this).modCount++;
            return;
        }
        StringBuilder sbO = AbstractC0844a.o(i, "Index:", ", Size:");
        sbO.append(this.f8029s);
        throw new IndexOutOfBoundsException(sbO.toString());
    }
}
