package com.google.crypto.tink.shaded.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 Z extends AbstractC0736b implements RandomAccess {

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public static final Z f10471t;

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

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

    static {
        Z z8 = new Z(0, new Object[0]);
        f10471t = z8;
        z8.f10478q = false;
    }

    public Z(int i, Object[] objArr) {
        this.f10472r = objArr;
        this.f10473s = i;
    }

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

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

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

    @Override // com.google.crypto.tink.shaded.protobuf.InterfaceC0758y
    public final InterfaceC0758y q(int i) {
        if (i < this.f10473s) {
            throw new IllegalArgumentException();
        }
        return new Z(this.f10473s, Arrays.copyOf(this.f10472r, i));
    }

    @Override // com.google.crypto.tink.shaded.protobuf.AbstractC0736b, java.util.AbstractList, java.util.List
    public final Object remove(int i) {
        a();
        b(i);
        Object[] objArr = this.f10472r;
        Object obj = objArr[i];
        if (i < this.f10473s - 1) {
            System.arraycopy(objArr, i + 1, objArr, i, (r2 - i) - 1);
        }
        this.f10473s--;
        ((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.f10472r;
        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.f10473s;
    }

    @Override // java.util.AbstractList, java.util.List
    public final void add(int i, Object obj) {
        int i5;
        a();
        if (i >= 0 && i <= (i5 = this.f10473s)) {
            Object[] objArr = this.f10472r;
            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.f10472r, i, objArr2, i + 1, this.f10473s - i);
                this.f10472r = objArr2;
            }
            this.f10472r[i] = obj;
            this.f10473s++;
            ((AbstractList) this).modCount++;
            return;
        }
        StringBuilder sbO = AbstractC0844a.o(i, "Index:", ", Size:");
        sbO.append(this.f10473s);
        throw new IndexOutOfBoundsException(sbO.toString());
    }
}
