package pp;

import java.lang.reflect.Array;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.RandomAccess;

/* loaded from: classes3.dex */
public class f extends AbstractList implements RandomAccess {

    /* renamed from: p, reason: collision with root package name */
    private int f33033p;

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

    /* loaded from: classes3.dex */
    private static class b implements Iterator {

        /* renamed from: p, reason: collision with root package name */
        private static final b f33035p = new b();

        private b() {
        }

        public static b a() {
            return f33035p;
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            return false;
        }

        @Override // java.util.Iterator
        public Object next() {
            throw new NoSuchElementException();
        }

        @Override // java.util.Iterator
        public void remove() {
            throw new IllegalStateException();
        }
    }

    /* loaded from: classes3.dex */
    private class c extends d {

        /* renamed from: q, reason: collision with root package name */
        private final int f33036q;

        public c() {
            super();
            this.f33036q = ((AbstractList) f.this).modCount;
        }

        @Override // pp.f.d
        protected void a() {
            if (((AbstractList) f.this).modCount == this.f33036q) {
                return;
            }
            throw new ConcurrentModificationException("ModCount: " + ((AbstractList) f.this).modCount + "; expected: " + this.f33036q);
        }

        @Override // pp.f.d
        protected Object b() {
            return f.this.f33034q;
        }

        @Override // java.util.Iterator
        public void remove() {
            a();
            f.this.clear();
        }
    }

    /* loaded from: classes3.dex */
    private static abstract class d implements Iterator {

        /* renamed from: p, reason: collision with root package name */
        private boolean f33038p;

        private d() {
        }

        protected abstract void a();

        protected abstract Object b();

        @Override // java.util.Iterator
        public final boolean hasNext() {
            return !this.f33038p;
        }

        @Override // java.util.Iterator
        public final Object next() {
            if (this.f33038p) {
                throw new NoSuchElementException();
            }
            this.f33038p = true;
            a();
            return b();
        }
    }

    private static /* synthetic */ void e(int i10) {
        String str = (i10 == 2 || i10 == 3 || i10 == 5 || i10 == 6 || i10 == 7) ? "@NotNull method %s.%s must not return null" : "Argument for @NotNull parameter '%s' of %s.%s must not be null";
        Object[] objArr = new Object[(i10 == 2 || i10 == 3 || i10 == 5 || i10 == 6 || i10 == 7) ? 2 : 3];
        switch (i10) {
            case 2:
            case 3:
            case 5:
            case 6:
            case 7:
                objArr[0] = "kotlin/reflect/jvm/internal/impl/utils/SmartList";
                break;
            case 4:
                objArr[0] = "a";
                break;
            default:
                objArr[0] = "elements";
                break;
        }
        if (i10 == 2 || i10 == 3) {
            objArr[1] = "iterator";
        } else if (i10 == 5 || i10 == 6 || i10 == 7) {
            objArr[1] = "toArray";
        } else {
            objArr[1] = "kotlin/reflect/jvm/internal/impl/utils/SmartList";
        }
        switch (i10) {
            case 2:
            case 3:
            case 5:
            case 6:
            case 7:
                break;
            case 4:
                objArr[2] = "toArray";
                break;
            default:
                objArr[2] = "<init>";
                break;
        }
        String format = String.format(str, objArr);
        if (i10 != 2 && i10 != 3 && i10 != 5 && i10 != 6 && i10 != 7) {
            throw new IllegalArgumentException(format);
        }
        throw new IllegalStateException(format);
    }

    @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List
    public boolean add(Object obj) {
        int i10 = this.f33033p;
        if (i10 == 0) {
            this.f33034q = obj;
        } else if (i10 == 1) {
            this.f33034q = new Object[]{this.f33034q, obj};
        } else {
            Object[] objArr = (Object[]) this.f33034q;
            int length = objArr.length;
            if (i10 >= length) {
                int i11 = ((length * 3) / 2) + 1;
                int i12 = i10 + 1;
                if (i11 < i12) {
                    i11 = i12;
                }
                Object[] objArr2 = new Object[i11];
                this.f33034q = objArr2;
                System.arraycopy(objArr, 0, objArr2, 0, length);
                objArr = objArr2;
            }
            objArr[this.f33033p] = obj;
        }
        this.f33033p++;
        ((AbstractList) this).modCount++;
        return true;
    }

    @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List
    public void clear() {
        this.f33034q = null;
        this.f33033p = 0;
        ((AbstractList) this).modCount++;
    }

    @Override // java.util.AbstractList, java.util.List
    public Object get(int i10) {
        int i11;
        if (i10 >= 0 && i10 < (i11 = this.f33033p)) {
            return i11 == 1 ? this.f33034q : ((Object[]) this.f33034q)[i10];
        }
        throw new IndexOutOfBoundsException("Index: " + i10 + ", Size: " + this.f33033p);
    }

    @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.List
    public Iterator iterator() {
        int i10 = this.f33033p;
        if (i10 == 0) {
            b a10 = b.a();
            if (a10 == null) {
                e(2);
            }
            return a10;
        }
        if (i10 == 1) {
            return new c();
        }
        Iterator it = super.iterator();
        if (it == null) {
            e(3);
        }
        return it;
    }

    @Override // java.util.AbstractList, java.util.List
    public Object remove(int i10) {
        int i11;
        Object obj;
        if (i10 < 0 || i10 >= (i11 = this.f33033p)) {
            throw new IndexOutOfBoundsException("Index: " + i10 + ", Size: " + this.f33033p);
        }
        if (i11 == 1) {
            obj = this.f33034q;
            this.f33034q = null;
        } else {
            Object[] objArr = (Object[]) this.f33034q;
            Object obj2 = objArr[i10];
            if (i11 == 2) {
                this.f33034q = objArr[1 - i10];
            } else {
                int i12 = (i11 - i10) - 1;
                if (i12 > 0) {
                    System.arraycopy(objArr, i10 + 1, objArr, i10, i12);
                }
                objArr[this.f33033p - 1] = null;
            }
            obj = obj2;
        }
        this.f33033p--;
        ((AbstractList) this).modCount++;
        return obj;
    }

    @Override // java.util.AbstractList, java.util.List
    public Object set(int i10, Object obj) {
        int i11;
        if (i10 < 0 || i10 >= (i11 = this.f33033p)) {
            throw new IndexOutOfBoundsException("Index: " + i10 + ", Size: " + this.f33033p);
        }
        if (i11 == 1) {
            Object obj2 = this.f33034q;
            this.f33034q = obj;
            return obj2;
        }
        Object[] objArr = (Object[]) this.f33034q;
        Object obj3 = objArr[i10];
        objArr[i10] = obj;
        return obj3;
    }

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

    @Override // java.util.List
    public void sort(Comparator comparator) {
        int i10 = this.f33033p;
        if (i10 >= 2) {
            Arrays.sort((Object[]) this.f33034q, 0, i10, comparator);
        }
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
    public Object[] toArray(Object[] objArr) {
        if (objArr == null) {
            e(4);
        }
        int length = objArr.length;
        int i10 = this.f33033p;
        if (i10 == 1) {
            if (length == 0) {
                Object[] objArr2 = (Object[]) Array.newInstance(objArr.getClass().getComponentType(), 1);
                objArr2[0] = this.f33034q;
                return objArr2;
            }
            objArr[0] = this.f33034q;
        } else {
            if (length < i10) {
                Object[] copyOf = Arrays.copyOf((Object[]) this.f33034q, i10, objArr.getClass());
                if (copyOf == null) {
                    e(6);
                }
                return copyOf;
            }
            if (i10 != 0) {
                System.arraycopy(this.f33034q, 0, objArr, 0, i10);
            }
        }
        int i11 = this.f33033p;
        if (length > i11) {
            objArr[i11] = null;
        }
        return objArr;
    }

    @Override // java.util.AbstractList, java.util.List
    public void add(int i10, Object obj) {
        int i11;
        if (i10 >= 0 && i10 <= (i11 = this.f33033p)) {
            if (i11 == 0) {
                this.f33034q = obj;
            } else if (i11 == 1 && i10 == 0) {
                this.f33034q = new Object[]{obj, this.f33034q};
            } else {
                Object[] objArr = new Object[i11 + 1];
                if (i11 == 1) {
                    objArr[0] = this.f33034q;
                } else {
                    Object[] objArr2 = (Object[]) this.f33034q;
                    System.arraycopy(objArr2, 0, objArr, 0, i10);
                    System.arraycopy(objArr2, i10, objArr, i10 + 1, this.f33033p - i10);
                }
                objArr[i10] = obj;
                this.f33034q = objArr;
            }
            this.f33033p++;
            ((AbstractList) this).modCount++;
            return;
        }
        throw new IndexOutOfBoundsException("Index: " + i10 + ", Size: " + this.f33033p);
    }
}
