package o;

import com.google.android.gms.common.api.Api;
import java.io.NotSerializableException;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.RandomAccess;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class HL extends V implements RandomAccess, Serializable {

    /* renamed from: o, reason: collision with root package name */
    public static final HL f144o;
    public Object[] l;
    public int m;
    public boolean n;

    static {
        HL hl = new HL(0);
        hl.n = true;
        f144o = hl;
    }

    public HL(int i) {
        if (i < 0) {
            throw new IllegalArgumentException("capacity must be non-negative.");
        }
        this.l = new Object[i];
    }

    private final Object writeReplace() throws NotSerializableException {
        if (this.n) {
            return new P60(this, 0);
        }
        throw new NotSerializableException("The list cannot be serialized while it is being built.");
    }

    @Override // o.V
    public final int a() {
        return this.m;
    }

    @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List
    public final boolean add(Object obj) {
        f();
        int i = this.m;
        ((AbstractList) this).modCount++;
        h(i, 1);
        this.l[i] = obj;
        return true;
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
    public final boolean addAll(Collection collection) {
        f();
        int size = collection.size();
        d(this.m, collection, size);
        return size > 0;
    }

    @Override // o.V
    public final Object b(int i) {
        f();
        int i2 = this.m;
        if (i < 0 || i >= i2) {
            throw new IndexOutOfBoundsException(AbstractC0126Ew.i(i, i2, "index: ", ", size: "));
        }
        return i(i);
    }

    @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List
    public final void clear() {
        f();
        k(0, this.m);
    }

    public final void d(int i, Collection collection, int i2) {
        ((AbstractList) this).modCount++;
        h(i, i2);
        Iterator it = collection.iterator();
        for (int i3 = 0; i3 < i2; i3++) {
            this.l[i + i3] = it.next();
        }
    }

    public final void e(int i, Object obj) {
        ((AbstractList) this).modCount++;
        h(i, 1);
        this.l[i] = obj;
    }

    @Override // java.util.AbstractList, java.util.Collection, java.util.List
    public final boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj instanceof List) {
            List list = (List) obj;
            Object[] objArr = this.l;
            int i = this.m;
            if (i == list.size()) {
                for (int i2 = 0; i2 < i; i2++) {
                    if (F3.c(objArr[i2], list.get(i2))) {
                    }
                }
                return true;
            }
        }
        return false;
    }

    public final void f() {
        if (this.n) {
            throw new UnsupportedOperationException();
        }
    }

    @Override // java.util.AbstractList, java.util.List
    public final Object get(int i) {
        int i2 = this.m;
        if (i < 0 || i >= i2) {
            throw new IndexOutOfBoundsException(AbstractC0126Ew.i(i, i2, "index: ", ", size: "));
        }
        return this.l[i];
    }

    public final void h(int i, int i2) {
        int i3 = this.m + i2;
        if (i3 < 0) {
            throw new OutOfMemoryError();
        }
        Object[] objArr = this.l;
        if (i3 > objArr.length) {
            int length = objArr.length;
            int i4 = length + (length >> 1);
            if (i4 - i3 < 0) {
                i4 = i3;
            }
            if (i4 - 2147483639 > 0) {
                i4 = i3 > 2147483639 ? Api.BaseClientBuilder.API_PRIORITY_OTHER : 2147483639;
            }
            this.l = Arrays.copyOf(objArr, i4);
        }
        Object[] objArr2 = this.l;
        AbstractC2219q9.J(i + i2, i, this.m, objArr2, objArr2);
        this.m += i2;
    }

    @Override // java.util.AbstractList, java.util.Collection, java.util.List
    public final int hashCode() {
        Object[] objArr = this.l;
        int i = this.m;
        int iHashCode = 1;
        for (int i2 = 0; i2 < i; i2++) {
            Object obj = objArr[i2];
            iHashCode = (iHashCode * 31) + (obj != null ? obj.hashCode() : 0);
        }
        return iHashCode;
    }

    public final Object i(int i) {
        ((AbstractList) this).modCount++;
        Object[] objArr = this.l;
        Object obj = objArr[i];
        AbstractC2219q9.J(i, i + 1, this.m, objArr, objArr);
        Object[] objArr2 = this.l;
        int i2 = this.m;
        objArr2[i2 - 1] = null;
        this.m = i2 - 1;
        return obj;
    }

    @Override // java.util.AbstractList, java.util.List
    public final int indexOf(Object obj) {
        for (int i = 0; i < this.m; i++) {
            if (F3.c(this.l[i], obj)) {
                return i;
            }
        }
        return -1;
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
    public final boolean isEmpty() {
        return this.m == 0;
    }

    @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.List
    public final Iterator iterator() {
        return listIterator(0);
    }

    public final void k(int i, int i2) {
        if (i2 > 0) {
            ((AbstractList) this).modCount++;
        }
        Object[] objArr = this.l;
        AbstractC2219q9.J(i, i + i2, this.m, objArr, objArr);
        Object[] objArr2 = this.l;
        int i3 = this.m;
        AbstractC0249Jp.c0(objArr2, i3 - i2, i3);
        this.m -= i2;
    }

    public final int l(int i, int i2, Collection collection, boolean z) {
        int i3 = 0;
        int i4 = 0;
        while (i3 < i2) {
            int i5 = i + i3;
            if (collection.contains(this.l[i5]) == z) {
                Object[] objArr = this.l;
                i3++;
                objArr[i4 + i] = objArr[i5];
                i4++;
            } else {
                i3++;
            }
        }
        int i6 = i2 - i4;
        Object[] objArr2 = this.l;
        AbstractC2219q9.J(i + i4, i2 + i, this.m, objArr2, objArr2);
        Object[] objArr3 = this.l;
        int i7 = this.m;
        AbstractC0249Jp.c0(objArr3, i7 - i6, i7);
        if (i6 > 0) {
            ((AbstractList) this).modCount++;
        }
        this.m -= i6;
        return i6;
    }

    @Override // java.util.AbstractList, java.util.List
    public final int lastIndexOf(Object obj) {
        for (int i = this.m - 1; i >= 0; i--) {
            if (F3.c(this.l[i], obj)) {
                return i;
            }
        }
        return -1;
    }

    @Override // java.util.AbstractList, java.util.List
    public final ListIterator listIterator() {
        return listIterator(0);
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
    public final boolean remove(Object obj) {
        f();
        int iIndexOf = indexOf(obj);
        if (iIndexOf >= 0) {
            b(iIndexOf);
        }
        return iIndexOf >= 0;
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
    public final boolean removeAll(Collection collection) {
        f();
        return l(0, this.m, collection, false) > 0;
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
    public final boolean retainAll(Collection collection) {
        f();
        return l(0, this.m, collection, true) > 0;
    }

    @Override // java.util.AbstractList, java.util.List
    public final Object set(int i, Object obj) {
        f();
        int i2 = this.m;
        if (i < 0 || i >= i2) {
            throw new IndexOutOfBoundsException(AbstractC0126Ew.i(i, i2, "index: ", ", size: "));
        }
        Object[] objArr = this.l;
        Object obj2 = objArr[i];
        objArr[i] = obj;
        return obj2;
    }

    @Override // java.util.AbstractList, java.util.List
    public final List subList(int i, int i2) {
        AbstractC0752ap.x(i, i2, this.m);
        return new GL(this.l, i, i2 - i, null, this);
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
    public final Object[] toArray(Object[] objArr) {
        int length = objArr.length;
        int i = this.m;
        if (length < i) {
            return Arrays.copyOfRange(this.l, 0, i, objArr.getClass());
        }
        AbstractC2219q9.J(0, 0, i, this.l, objArr);
        int i2 = this.m;
        if (i2 < objArr.length) {
            objArr[i2] = null;
        }
        return objArr;
    }

    @Override // java.util.AbstractCollection
    public final String toString() {
        return AbstractC0249Jp.m(this.l, 0, this.m, this);
    }

    @Override // java.util.AbstractList, java.util.List
    public final ListIterator listIterator(int i) {
        int i2 = this.m;
        if (i < 0 || i > i2) {
            throw new IndexOutOfBoundsException(AbstractC0126Ew.i(i, i2, "index: ", ", size: "));
        }
        return new C1083eF(this, i);
    }

    @Override // java.util.AbstractList, java.util.List
    public final boolean addAll(int i, Collection collection) {
        f();
        int i2 = this.m;
        if (i >= 0 && i <= i2) {
            int size = collection.size();
            d(i, collection, size);
            return size > 0;
        }
        throw new IndexOutOfBoundsException(AbstractC0126Ew.i(i, i2, "index: ", ", size: "));
    }

    @Override // java.util.AbstractList, java.util.List
    public final void add(int i, Object obj) {
        f();
        int i2 = this.m;
        if (i >= 0 && i <= i2) {
            ((AbstractList) this).modCount++;
            h(i, 1);
            this.l[i] = obj;
            return;
        }
        throw new IndexOutOfBoundsException(AbstractC0126Ew.i(i, i2, "index: ", ", size: "));
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
    public final Object[] toArray() {
        Object[] objArr = this.l;
        int i = this.m;
        AbstractC2461sm0.d(i, objArr.length);
        return Arrays.copyOfRange(objArr, 0, i);
    }
}
