package com.google.crypto.tink.shaded.protobuf;

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

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public final class a1 extends c implements RandomAccess {

    /* renamed from: s, reason: collision with root package name */
    private static final a1 f14316s;

    /* renamed from: q, reason: collision with root package name */
    private Object[] f14317q;

    /* renamed from: r, reason: collision with root package name */
    private int f14318r;

    static {
        a1 a1Var = new a1(new Object[0], 0);
        f14316s = a1Var;
        a1Var.d();
    }

    private a1(Object[] objArr, int i10) {
        this.f14317q = objArr;
        this.f14318r = i10;
    }

    private static Object[] g(int i10) {
        return new Object[i10];
    }

    public static a1 i() {
        return f14316s;
    }

    private void k(int i10) {
        if (i10 < 0 || i10 >= this.f14318r) {
            throw new IndexOutOfBoundsException(l(i10));
        }
    }

    private String l(int i10) {
        return "Index:" + i10 + ", Size:" + this.f14318r;
    }

    @Override // com.google.crypto.tink.shaded.protobuf.c, java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List
    public boolean add(Object obj) {
        e();
        int i10 = this.f14318r;
        Object[] objArr = this.f14317q;
        if (i10 == objArr.length) {
            this.f14317q = Arrays.copyOf(objArr, ((i10 * 3) / 2) + 1);
        }
        Object[] objArr2 = this.f14317q;
        int i11 = this.f14318r;
        this.f14318r = i11 + 1;
        objArr2[i11] = obj;
        ((AbstractList) this).modCount++;
        return true;
    }

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

    @Override // com.google.crypto.tink.shaded.protobuf.z.d
    /* renamed from: m, reason: merged with bridge method [inline-methods] */
    public a1 a(int i10) {
        if (i10 >= this.f14318r) {
            return new a1(Arrays.copyOf(this.f14317q, i10), this.f14318r);
        }
        throw new IllegalArgumentException();
    }

    @Override // java.util.AbstractList, java.util.List
    public Object remove(int i10) {
        e();
        k(i10);
        Object[] objArr = this.f14317q;
        Object obj = objArr[i10];
        if (i10 < this.f14318r - 1) {
            System.arraycopy(objArr, i10 + 1, objArr, i10, (r2 - i10) - 1);
        }
        this.f14318r--;
        ((AbstractList) this).modCount++;
        return obj;
    }

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

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

    @Override // java.util.AbstractList, java.util.List
    public void add(int i10, Object obj) {
        int i11;
        e();
        if (i10 >= 0 && i10 <= (i11 = this.f14318r)) {
            Object[] objArr = this.f14317q;
            if (i11 < objArr.length) {
                System.arraycopy(objArr, i10, objArr, i10 + 1, i11 - i10);
            } else {
                Object[] g10 = g(((i11 * 3) / 2) + 1);
                System.arraycopy(this.f14317q, 0, g10, 0, i10);
                System.arraycopy(this.f14317q, i10, g10, i10 + 1, this.f14318r - i10);
                this.f14317q = g10;
            }
            this.f14317q[i10] = obj;
            this.f14318r++;
            ((AbstractList) this).modCount++;
            return;
        }
        throw new IndexOutOfBoundsException(l(i10));
    }
}
