package X6FRs_4.Mqv2r_3;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/* compiled from: ArraySet.java */
/* loaded from: classes.dex */
public final class QxJ9d_1<E> implements Collection<E>, Set<E> {

    /* renamed from: Mqv2r_3  reason: collision with root package name */
    public static Object[] f3223Mqv2r_3;
    public static int PGPF6hQ_2;

    /* renamed from: PGPF6hQ_2  reason: collision with other field name */
    public static Object[] f1015PGPF6hQ_2;
    public static int QxJ9d_1;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public static final int[] f1016QxJ9d_1 = new int[0];

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public static final Object[] f1017QxJ9d_1 = new Object[0];
    public int KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public IFxWkV_5<E, E> f1018KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public int[] f1019KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public Object[] f1020KQgRr5e_0;

    /* compiled from: ArraySet.java */
    /* loaded from: classes.dex */
    public class KQgRr5e_0 extends IFxWkV_5<E, E> {
        public KQgRr5e_0() {
        }

        @Override // X6FRs_4.Mqv2r_3.IFxWkV_5
        public int KQgRr5e_0() {
            return QxJ9d_1.this.KQgRr5e_0;
        }

        @Override // X6FRs_4.Mqv2r_3.IFxWkV_5
        public int QxJ9d_1(Object obj) {
            return QxJ9d_1.this.indexOf(obj);
        }

        @Override // X6FRs_4.Mqv2r_3.IFxWkV_5
        public Object KQgRr5e_0(int i, int i2) {
            return QxJ9d_1.this.f1020KQgRr5e_0[i];
        }

        @Override // X6FRs_4.Mqv2r_3.IFxWkV_5
        public int KQgRr5e_0(Object obj) {
            return QxJ9d_1.this.indexOf(obj);
        }

        @Override // X6FRs_4.Mqv2r_3.IFxWkV_5
        public Map<E, E> KQgRr5e_0() {
            throw new UnsupportedOperationException("not a map");
        }

        @Override // X6FRs_4.Mqv2r_3.IFxWkV_5
        public void KQgRr5e_0(E e, E e2) {
            QxJ9d_1.this.add(e);
        }

        @Override // X6FRs_4.Mqv2r_3.IFxWkV_5
        public E KQgRr5e_0(int i, E e) {
            throw new UnsupportedOperationException("not a map");
        }

        @Override // X6FRs_4.Mqv2r_3.IFxWkV_5
        public void KQgRr5e_0(int i) {
            QxJ9d_1.this.KQgRr5e_0(i);
        }

        @Override // X6FRs_4.Mqv2r_3.IFxWkV_5
        public void KQgRr5e_0() {
            QxJ9d_1.this.clear();
        }
    }

    public QxJ9d_1() {
        this(0);
    }

    public final int KQgRr5e_0(Object obj, int i) {
        int i2 = this.KQgRr5e_0;
        if (i2 == 0) {
            return -1;
        }
        int KQgRr5e_02 = PGPF6hQ_2.KQgRr5e_0(this.f1019KQgRr5e_0, i2, i);
        if (KQgRr5e_02 >= 0 && !obj.equals(this.f1020KQgRr5e_0[KQgRr5e_02])) {
            int i3 = KQgRr5e_02 + 1;
            while (i3 < i2 && this.f1019KQgRr5e_0[i3] == i) {
                if (obj.equals(this.f1020KQgRr5e_0[i3])) {
                    return i3;
                }
                i3++;
            }
            for (int i4 = KQgRr5e_02 - 1; i4 >= 0 && this.f1019KQgRr5e_0[i4] == i; i4--) {
                if (obj.equals(this.f1020KQgRr5e_0[i4])) {
                    return i4;
                }
            }
            return i3 ^ (-1);
        }
        return KQgRr5e_02;
    }

    /* renamed from: QxJ9d_1  reason: collision with other method in class */
    public void m512QxJ9d_1(int i) {
        int[] iArr = this.f1019KQgRr5e_0;
        if (iArr.length < i) {
            Object[] objArr = this.f1020KQgRr5e_0;
            m511KQgRr5e_0(i);
            int i2 = this.KQgRr5e_0;
            if (i2 > 0) {
                System.arraycopy(iArr, 0, this.f1019KQgRr5e_0, 0, i2);
                System.arraycopy(objArr, 0, this.f1020KQgRr5e_0, 0, this.KQgRr5e_0);
            }
            KQgRr5e_0(iArr, objArr, this.KQgRr5e_0);
        }
    }

    @Override // java.util.Collection, java.util.Set
    public boolean add(E e) {
        int i;
        int KQgRr5e_02;
        if (e == null) {
            KQgRr5e_02 = KQgRr5e_0();
            i = 0;
        } else {
            int hashCode = e.hashCode();
            i = hashCode;
            KQgRr5e_02 = KQgRr5e_0(e, hashCode);
        }
        if (KQgRr5e_02 >= 0) {
            return false;
        }
        int i2 = KQgRr5e_02 ^ (-1);
        int i3 = this.KQgRr5e_0;
        if (i3 >= this.f1019KQgRr5e_0.length) {
            int i4 = 4;
            if (i3 >= 8) {
                i4 = (i3 >> 1) + i3;
            } else if (i3 >= 4) {
                i4 = 8;
            }
            int[] iArr = this.f1019KQgRr5e_0;
            Object[] objArr = this.f1020KQgRr5e_0;
            m511KQgRr5e_0(i4);
            int[] iArr2 = this.f1019KQgRr5e_0;
            if (iArr2.length > 0) {
                System.arraycopy(iArr, 0, iArr2, 0, iArr.length);
                System.arraycopy(objArr, 0, this.f1020KQgRr5e_0, 0, objArr.length);
            }
            KQgRr5e_0(iArr, objArr, this.KQgRr5e_0);
        }
        int i5 = this.KQgRr5e_0;
        if (i2 < i5) {
            int[] iArr3 = this.f1019KQgRr5e_0;
            int i6 = i2 + 1;
            System.arraycopy(iArr3, i2, iArr3, i6, i5 - i2);
            Object[] objArr2 = this.f1020KQgRr5e_0;
            System.arraycopy(objArr2, i2, objArr2, i6, this.KQgRr5e_0 - i2);
        }
        this.f1019KQgRr5e_0[i2] = i;
        this.f1020KQgRr5e_0[i2] = e;
        this.KQgRr5e_0++;
        return true;
    }

    @Override // java.util.Collection, java.util.Set
    public boolean addAll(Collection<? extends E> collection) {
        m512QxJ9d_1(this.KQgRr5e_0 + collection.size());
        boolean z = false;
        for (E e : collection) {
            z |= add(e);
        }
        return z;
    }

    @Override // java.util.Collection, java.util.Set
    public void clear() {
        int i = this.KQgRr5e_0;
        if (i != 0) {
            KQgRr5e_0(this.f1019KQgRr5e_0, this.f1020KQgRr5e_0, i);
            this.f1019KQgRr5e_0 = f1016QxJ9d_1;
            this.f1020KQgRr5e_0 = f1017QxJ9d_1;
            this.KQgRr5e_0 = 0;
        }
    }

    @Override // java.util.Collection, java.util.Set
    public boolean contains(Object obj) {
        return indexOf(obj) >= 0;
    }

    @Override // java.util.Collection, java.util.Set
    public boolean containsAll(Collection<?> collection) {
        Iterator<?> it = collection.iterator();
        while (it.hasNext()) {
            if (!contains(it.next())) {
                return false;
            }
        }
        return true;
    }

    @Override // java.util.Collection, java.util.Set
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof Set) {
            Set set = (Set) obj;
            if (size() != set.size()) {
                return false;
            }
            for (int i = 0; i < this.KQgRr5e_0; i++) {
                try {
                    if (!set.contains(QxJ9d_1(i))) {
                        return false;
                    }
                } catch (ClassCastException | NullPointerException unused) {
                }
            }
            return true;
        }
        return false;
    }

    @Override // java.util.Collection, java.util.Set
    public int hashCode() {
        int[] iArr = this.f1019KQgRr5e_0;
        int i = this.KQgRr5e_0;
        int i2 = 0;
        for (int i3 = 0; i3 < i; i3++) {
            i2 += iArr[i3];
        }
        return i2;
    }

    public int indexOf(Object obj) {
        return obj == null ? KQgRr5e_0() : KQgRr5e_0(obj, obj.hashCode());
    }

    @Override // java.util.Collection, java.util.Set
    public boolean isEmpty() {
        return this.KQgRr5e_0 <= 0;
    }

    @Override // java.util.Collection, java.lang.Iterable, java.util.Set
    public Iterator<E> iterator() {
        return m510KQgRr5e_0().QxJ9d_1().iterator();
    }

    @Override // java.util.Collection, java.util.Set
    public boolean remove(Object obj) {
        int indexOf = indexOf(obj);
        if (indexOf >= 0) {
            KQgRr5e_0(indexOf);
            return true;
        }
        return false;
    }

    @Override // java.util.Collection, java.util.Set
    public boolean removeAll(Collection<?> collection) {
        Iterator<?> it = collection.iterator();
        boolean z = false;
        while (it.hasNext()) {
            z |= remove(it.next());
        }
        return z;
    }

    @Override // java.util.Collection, java.util.Set
    public boolean retainAll(Collection<?> collection) {
        boolean z = false;
        for (int i = this.KQgRr5e_0 - 1; i >= 0; i--) {
            if (!collection.contains(this.f1020KQgRr5e_0[i])) {
                KQgRr5e_0(i);
                z = true;
            }
        }
        return z;
    }

    @Override // java.util.Collection, java.util.Set
    public int size() {
        return this.KQgRr5e_0;
    }

    @Override // java.util.Collection, java.util.Set
    public Object[] toArray() {
        int i = this.KQgRr5e_0;
        Object[] objArr = new Object[i];
        System.arraycopy(this.f1020KQgRr5e_0, 0, objArr, 0, i);
        return objArr;
    }

    public String toString() {
        if (isEmpty()) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.KQgRr5e_0 * 14);
        sb.append('{');
        for (int i = 0; i < this.KQgRr5e_0; i++) {
            if (i > 0) {
                sb.append(", ");
            }
            E QxJ9d_12 = QxJ9d_1(i);
            if (QxJ9d_12 != this) {
                sb.append(QxJ9d_12);
            } else {
                sb.append("(this Set)");
            }
        }
        sb.append('}');
        return sb.toString();
    }

    public QxJ9d_1(int i) {
        if (i == 0) {
            this.f1019KQgRr5e_0 = f1016QxJ9d_1;
            this.f1020KQgRr5e_0 = f1017QxJ9d_1;
        } else {
            m511KQgRr5e_0(i);
        }
        this.KQgRr5e_0 = 0;
    }

    @Override // java.util.Collection, java.util.Set
    public <T> T[] toArray(T[] tArr) {
        if (tArr.length < this.KQgRr5e_0) {
            tArr = (T[]) ((Object[]) Array.newInstance(tArr.getClass().getComponentType(), this.KQgRr5e_0));
        }
        System.arraycopy(this.f1020KQgRr5e_0, 0, tArr, 0, this.KQgRr5e_0);
        int length = tArr.length;
        int i = this.KQgRr5e_0;
        if (length > i) {
            tArr[i] = null;
        }
        return tArr;
    }

    public final int KQgRr5e_0() {
        int i = this.KQgRr5e_0;
        if (i == 0) {
            return -1;
        }
        int KQgRr5e_02 = PGPF6hQ_2.KQgRr5e_0(this.f1019KQgRr5e_0, i, 0);
        if (KQgRr5e_02 >= 0 && this.f1020KQgRr5e_0[KQgRr5e_02] != null) {
            int i2 = KQgRr5e_02 + 1;
            while (i2 < i && this.f1019KQgRr5e_0[i2] == 0) {
                if (this.f1020KQgRr5e_0[i2] == null) {
                    return i2;
                }
                i2++;
            }
            for (int i3 = KQgRr5e_02 - 1; i3 >= 0 && this.f1019KQgRr5e_0[i3] == 0; i3--) {
                if (this.f1020KQgRr5e_0[i3] == null) {
                    return i3;
                }
            }
            return i2 ^ (-1);
        }
        return KQgRr5e_02;
    }

    public E QxJ9d_1(int i) {
        return (E) this.f1020KQgRr5e_0[i];
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public final void m511KQgRr5e_0(int i) {
        if (i == 8) {
            synchronized (QxJ9d_1.class) {
                if (f3223Mqv2r_3 != null) {
                    Object[] objArr = f3223Mqv2r_3;
                    this.f1020KQgRr5e_0 = objArr;
                    f3223Mqv2r_3 = (Object[]) objArr[0];
                    this.f1019KQgRr5e_0 = (int[]) objArr[1];
                    objArr[1] = null;
                    objArr[0] = null;
                    PGPF6hQ_2--;
                    return;
                }
            }
        } else if (i == 4) {
            synchronized (QxJ9d_1.class) {
                if (f1015PGPF6hQ_2 != null) {
                    Object[] objArr2 = f1015PGPF6hQ_2;
                    this.f1020KQgRr5e_0 = objArr2;
                    f1015PGPF6hQ_2 = (Object[]) objArr2[0];
                    this.f1019KQgRr5e_0 = (int[]) objArr2[1];
                    objArr2[1] = null;
                    objArr2[0] = null;
                    QxJ9d_1--;
                    return;
                }
            }
        }
        this.f1019KQgRr5e_0 = new int[i];
        this.f1020KQgRr5e_0 = new Object[i];
    }

    public static void KQgRr5e_0(int[] iArr, Object[] objArr, int i) {
        if (iArr.length == 8) {
            synchronized (QxJ9d_1.class) {
                if (PGPF6hQ_2 < 10) {
                    objArr[0] = f3223Mqv2r_3;
                    objArr[1] = iArr;
                    for (int i2 = i - 1; i2 >= 2; i2--) {
                        objArr[i2] = null;
                    }
                    f3223Mqv2r_3 = objArr;
                    PGPF6hQ_2++;
                }
            }
        } else if (iArr.length == 4) {
            synchronized (QxJ9d_1.class) {
                if (QxJ9d_1 < 10) {
                    objArr[0] = f1015PGPF6hQ_2;
                    objArr[1] = iArr;
                    for (int i3 = i - 1; i3 >= 2; i3--) {
                        objArr[i3] = null;
                    }
                    f1015PGPF6hQ_2 = objArr;
                    QxJ9d_1++;
                }
            }
        }
    }

    public E KQgRr5e_0(int i) {
        Object[] objArr = this.f1020KQgRr5e_0;
        E e = (E) objArr[i];
        int i2 = this.KQgRr5e_0;
        if (i2 <= 1) {
            KQgRr5e_0(this.f1019KQgRr5e_0, objArr, i2);
            this.f1019KQgRr5e_0 = f1016QxJ9d_1;
            this.f1020KQgRr5e_0 = f1017QxJ9d_1;
            this.KQgRr5e_0 = 0;
        } else {
            int[] iArr = this.f1019KQgRr5e_0;
            if (iArr.length > 8 && i2 < iArr.length / 3) {
                int i3 = i2 > 8 ? i2 + (i2 >> 1) : 8;
                int[] iArr2 = this.f1019KQgRr5e_0;
                Object[] objArr2 = this.f1020KQgRr5e_0;
                m511KQgRr5e_0(i3);
                this.KQgRr5e_0--;
                if (i > 0) {
                    System.arraycopy(iArr2, 0, this.f1019KQgRr5e_0, 0, i);
                    System.arraycopy(objArr2, 0, this.f1020KQgRr5e_0, 0, i);
                }
                int i4 = this.KQgRr5e_0;
                if (i < i4) {
                    int i5 = i + 1;
                    System.arraycopy(iArr2, i5, this.f1019KQgRr5e_0, i, i4 - i);
                    System.arraycopy(objArr2, i5, this.f1020KQgRr5e_0, i, this.KQgRr5e_0 - i);
                }
            } else {
                int i6 = this.KQgRr5e_0 - 1;
                this.KQgRr5e_0 = i6;
                if (i < i6) {
                    int[] iArr3 = this.f1019KQgRr5e_0;
                    int i7 = i + 1;
                    System.arraycopy(iArr3, i7, iArr3, i, i6 - i);
                    Object[] objArr3 = this.f1020KQgRr5e_0;
                    System.arraycopy(objArr3, i7, objArr3, i, this.KQgRr5e_0 - i);
                }
                this.f1020KQgRr5e_0[this.KQgRr5e_0] = null;
            }
        }
        return e;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public final IFxWkV_5<E, E> m510KQgRr5e_0() {
        if (this.f1018KQgRr5e_0 == null) {
            this.f1018KQgRr5e_0 = new KQgRr5e_0();
        }
        return this.f1018KQgRr5e_0;
    }
}
