package com.google.protobuf;

import java.nio.charset.Charset;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Collection;
import java.util.RandomAccess;

/* JADX INFO: loaded from: classes3.dex */
public final class P extends AbstractC1300d implements W, RandomAccess, C0 {

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

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

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

    public P(int[] iArr, int i6, boolean z6) {
        super(z6);
        this.f14220b = iArr;
        this.f14221c = i6;
    }

    @Override // com.google.protobuf.Y
    public final Y a(int i6) {
        if (i6 >= this.f14221c) {
            return new P(Arrays.copyOf(this.f14220b, i6), this.f14221c, true);
        }
        throw new IllegalArgumentException();
    }

    @Override // java.util.AbstractList, java.util.List
    public final void add(int i6, Object obj) {
        int i7;
        int iIntValue = ((Integer) obj).intValue();
        e();
        if (i6 < 0 || i6 > (i7 = this.f14221c)) {
            StringBuilder sbR = com.google.android.recaptcha.internal.a.r(i6, "Index:", ", Size:");
            sbR.append(this.f14221c);
            throw new IndexOutOfBoundsException(sbR.toString());
        }
        int[] iArr = this.f14220b;
        if (i7 < iArr.length) {
            System.arraycopy(iArr, i6, iArr, i6 + 1, i7 - i6);
        } else {
            int[] iArr2 = new int[Z0.o.A(i7, 3, 2, 1)];
            System.arraycopy(iArr, 0, iArr2, 0, i6);
            System.arraycopy(this.f14220b, i6, iArr2, i6 + 1, this.f14221c - i6);
            this.f14220b = iArr2;
        }
        this.f14220b[i6] = iIntValue;
        this.f14221c++;
        ((AbstractList) this).modCount++;
    }

    @Override // com.google.protobuf.AbstractC1300d, java.util.AbstractCollection, java.util.Collection, java.util.List
    public final boolean addAll(Collection collection) {
        e();
        Charset charset = Z.f14234a;
        collection.getClass();
        if (!(collection instanceof P)) {
            return super.addAll(collection);
        }
        P p6 = (P) collection;
        int i6 = p6.f14221c;
        if (i6 == 0) {
            return false;
        }
        int i7 = this.f14221c;
        if (Integer.MAX_VALUE - i7 < i6) {
            throw new OutOfMemoryError();
        }
        int i8 = i7 + i6;
        int[] iArr = this.f14220b;
        if (i8 > iArr.length) {
            this.f14220b = Arrays.copyOf(iArr, i8);
        }
        System.arraycopy(p6.f14220b, 0, this.f14220b, this.f14221c, p6.f14221c);
        this.f14221c = i8;
        ((AbstractList) this).modCount++;
        return true;
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
    public final boolean contains(Object obj) {
        return indexOf(obj) != -1;
    }

    @Override // com.google.protobuf.AbstractC1300d, java.util.AbstractList, java.util.Collection, java.util.List
    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof P)) {
            return super.equals(obj);
        }
        P p6 = (P) obj;
        if (this.f14221c != p6.f14221c) {
            return false;
        }
        int[] iArr = p6.f14220b;
        for (int i6 = 0; i6 < this.f14221c; i6++) {
            if (this.f14220b[i6] != iArr[i6]) {
                return false;
            }
        }
        return true;
    }

    public final void g(int i6) {
        e();
        int i7 = this.f14221c;
        int[] iArr = this.f14220b;
        if (i7 == iArr.length) {
            int[] iArr2 = new int[Z0.o.A(i7, 3, 2, 1)];
            System.arraycopy(iArr, 0, iArr2, 0, i7);
            this.f14220b = iArr2;
        }
        int[] iArr3 = this.f14220b;
        int i8 = this.f14221c;
        this.f14221c = i8 + 1;
        iArr3[i8] = i6;
    }

    @Override // java.util.AbstractList, java.util.List
    public final Object get(int i6) {
        h(i6);
        return Integer.valueOf(this.f14220b[i6]);
    }

    public final void h(int i6) {
        if (i6 < 0 || i6 >= this.f14221c) {
            StringBuilder sbR = com.google.android.recaptcha.internal.a.r(i6, "Index:", ", Size:");
            sbR.append(this.f14221c);
            throw new IndexOutOfBoundsException(sbR.toString());
        }
    }

    @Override // com.google.protobuf.AbstractC1300d, java.util.AbstractList, java.util.Collection, java.util.List
    public final int hashCode() {
        int i6 = 1;
        for (int i7 = 0; i7 < this.f14221c; i7++) {
            i6 = (i6 * 31) + this.f14220b[i7];
        }
        return i6;
    }

    @Override // java.util.AbstractList, java.util.List
    public final int indexOf(Object obj) {
        if (!(obj instanceof Integer)) {
            return -1;
        }
        int iIntValue = ((Integer) obj).intValue();
        int i6 = this.f14221c;
        for (int i7 = 0; i7 < i6; i7++) {
            if (this.f14220b[i7] == iIntValue) {
                return i7;
            }
        }
        return -1;
    }

    @Override // com.google.protobuf.AbstractC1300d, java.util.AbstractList, java.util.List
    public final Object remove(int i6) {
        e();
        h(i6);
        int[] iArr = this.f14220b;
        int i7 = iArr[i6];
        if (i6 < this.f14221c - 1) {
            System.arraycopy(iArr, i6 + 1, iArr, i6, (r2 - i6) - 1);
        }
        this.f14221c--;
        ((AbstractList) this).modCount++;
        return Integer.valueOf(i7);
    }

    @Override // java.util.AbstractList
    public final void removeRange(int i6, int i7) {
        e();
        if (i7 < i6) {
            throw new IndexOutOfBoundsException("toIndex < fromIndex");
        }
        int[] iArr = this.f14220b;
        System.arraycopy(iArr, i7, iArr, i6, this.f14221c - i7);
        this.f14221c -= i7 - i6;
        ((AbstractList) this).modCount++;
    }

    @Override // java.util.AbstractList, java.util.List
    public final Object set(int i6, Object obj) {
        int iIntValue = ((Integer) obj).intValue();
        e();
        h(i6);
        int[] iArr = this.f14220b;
        int i7 = iArr[i6];
        iArr[i6] = iIntValue;
        return Integer.valueOf(i7);
    }

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

    @Override // com.google.protobuf.AbstractC1300d, java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List
    public final boolean add(Object obj) {
        g(((Integer) obj).intValue());
        return true;
    }
}
