package ῲ.㴹;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import ῲ.㴹.AbstractC2278;

/* renamed from: ῲ.㴹.ʬ  reason: contains not printable characters */
/* compiled from: ArraySet */
public final class C2274<E> implements Collection<E>, Set<E> {

    /* renamed from: ᕣ  reason: contains not printable characters */
    public static int f7855;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public static int f7856;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public static final Object[] f7857 = new Object[0];

    /* renamed from: 㳳  reason: contains not printable characters */
    public static Object[] f7858;

    /* renamed from: 㴹  reason: contains not printable characters */
    public static final int[] f7859 = new int[0];

    /* renamed from: 㿎  reason: contains not printable characters */
    public static Object[] f7860;

    /* renamed from: ʬ  reason: contains not printable characters */
    public Object[] f7861 = f7857;

    /* renamed from: ඓ  reason: contains not printable characters */
    public AbstractC2278<E, E> f7862;

    /* renamed from: ῲ  reason: contains not printable characters */
    public int[] f7863 = f7859;

    /* renamed from: 㸾  reason: contains not printable characters */
    public int f7864 = 0;

    @Override // java.util.Collection, java.util.Set
    public boolean add(E e) {
        int i;
        int i2;
        if (e == null) {
            i2 = m5910();
            i = 0;
        } else {
            int hashCode = e.hashCode();
            i = hashCode;
            i2 = m5911(e, hashCode);
        }
        if (i2 >= 0) {
            return false;
        }
        int i3 = ~i2;
        int i4 = this.f7864;
        if (i4 >= this.f7863.length) {
            int i5 = 4;
            if (i4 >= 8) {
                i5 = (i4 >> 1) + i4;
            } else if (i4 >= 4) {
                i5 = 8;
            }
            int[] iArr = this.f7863;
            Object[] objArr = this.f7861;
            m5912(i5);
            int[] iArr2 = this.f7863;
            if (iArr2.length > 0) {
                System.arraycopy(iArr, 0, iArr2, 0, iArr.length);
                System.arraycopy(objArr, 0, this.f7861, 0, objArr.length);
            }
            m5908(iArr, objArr, this.f7864);
        }
        int i6 = this.f7864;
        if (i3 < i6) {
            int[] iArr3 = this.f7863;
            int i7 = i3 + 1;
            System.arraycopy(iArr3, i3, iArr3, i7, i6 - i3);
            Object[] objArr2 = this.f7861;
            System.arraycopy(objArr2, i3, objArr2, i7, this.f7864 - i3);
        }
        this.f7863[i3] = i;
        this.f7861[i3] = e;
        this.f7864++;
        return true;
    }

    /* JADX DEBUG: Multi-variable search result rejected for r5v0, resolved type: ῲ.㴹.ʬ<E> */
    /* JADX WARN: Multi-variable type inference failed */
    @Override // java.util.Collection, java.util.Set
    public boolean addAll(Collection<? extends E> collection) {
        int size = collection.size() + this.f7864;
        int[] iArr = this.f7863;
        boolean z = false;
        if (iArr.length < size) {
            Object[] objArr = this.f7861;
            m5912(size);
            int i = this.f7864;
            if (i > 0) {
                System.arraycopy(iArr, 0, this.f7863, 0, i);
                System.arraycopy(objArr, 0, this.f7861, 0, this.f7864);
            }
            m5908(iArr, objArr, this.f7864);
        }
        Iterator<? extends E> it2 = collection.iterator();
        while (it2.hasNext()) {
            z |= add(it2.next());
        }
        return z;
    }

    public void clear() {
        int i = this.f7864;
        if (i != 0) {
            m5908(this.f7863, this.f7861, i);
            this.f7863 = f7859;
            this.f7861 = f7857;
            this.f7864 = 0;
        }
    }

    public boolean contains(Object obj) {
        return indexOf(obj) >= 0;
    }

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

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof Set) {
            Set set = (Set) obj;
            if (this.f7864 != set.size()) {
                return false;
            }
            for (int i = 0; i < this.f7864; i++) {
                try {
                    if (!set.contains(this.f7861[i])) {
                        return false;
                    }
                } catch (ClassCastException | NullPointerException unused) {
                }
            }
            return true;
        }
        return false;
    }

    public int hashCode() {
        int[] iArr = this.f7863;
        int i = this.f7864;
        int i2 = 0;
        for (int i3 = 0; i3 < i; i3++) {
            i2 += iArr[i3];
        }
        return i2;
    }

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

    public boolean isEmpty() {
        return this.f7864 <= 0;
    }

    @Override // java.util.Collection, java.util.Set, java.lang.Iterable
    public Iterator<E> iterator() {
        if (this.f7862 == null) {
            this.f7862 = new C2277(this);
        }
        AbstractC2278<E, E> r0 = this.f7862;
        if (r0.f7877 == null) {
            r0.f7877 = new AbstractC2278.C2279();
        }
        return r0.f7877.iterator();
    }

    public boolean remove(Object obj) {
        int indexOf = indexOf(obj);
        if (indexOf < 0) {
            return false;
        }
        m5909(indexOf);
        return true;
    }

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

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

    public int size() {
        return this.f7864;
    }

    public Object[] toArray() {
        int i = this.f7864;
        Object[] objArr = new Object[i];
        System.arraycopy(this.f7861, 0, objArr, 0, i);
        return objArr;
    }

    public String toString() {
        if (isEmpty()) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.f7864 * 14);
        sb.append('{');
        for (int i = 0; i < this.f7864; i++) {
            if (i > 0) {
                sb.append(", ");
            }
            Object obj = this.f7861[i];
            if (obj != this) {
                sb.append(obj);
            } else {
                sb.append("(this Set)");
            }
        }
        sb.append('}');
        return sb.toString();
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public E m5909(int i) {
        Object[] objArr = this.f7861;
        E e = (E) objArr[i];
        int i2 = this.f7864;
        if (i2 <= 1) {
            m5908(this.f7863, objArr, i2);
            this.f7863 = f7859;
            this.f7861 = f7857;
            this.f7864 = 0;
        } else {
            int[] iArr = this.f7863;
            int i3 = 8;
            if (iArr.length <= 8 || i2 >= iArr.length / 3) {
                this.f7864--;
                int i4 = this.f7864;
                if (i < i4) {
                    int[] iArr2 = this.f7863;
                    int i5 = i + 1;
                    System.arraycopy(iArr2, i5, iArr2, i, i4 - i);
                    Object[] objArr2 = this.f7861;
                    System.arraycopy(objArr2, i5, objArr2, i, this.f7864 - i);
                }
                this.f7861[this.f7864] = null;
            } else {
                if (i2 > 8) {
                    i3 = i2 + (i2 >> 1);
                }
                int[] iArr3 = this.f7863;
                Object[] objArr3 = this.f7861;
                m5912(i3);
                this.f7864--;
                if (i > 0) {
                    System.arraycopy(iArr3, 0, this.f7863, 0, i);
                    System.arraycopy(objArr3, 0, this.f7861, 0, i);
                }
                int i6 = this.f7864;
                if (i < i6) {
                    int i7 = i + 1;
                    System.arraycopy(iArr3, i7, this.f7863, i, i6 - i);
                    System.arraycopy(objArr3, i7, this.f7861, i, this.f7864 - i);
                }
            }
        }
        return e;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final int m5911(Object obj, int i) {
        int i2 = this.f7864;
        if (i2 == 0) {
            return -1;
        }
        int r1 = C2287.m5968(this.f7863, i2, i);
        if (r1 < 0 || obj.equals(this.f7861[r1])) {
            return r1;
        }
        int i3 = r1 + 1;
        while (i3 < i2 && this.f7863[i3] == i) {
            if (obj.equals(this.f7861[i3])) {
                return i3;
            }
            i3++;
        }
        int i4 = r1 - 1;
        while (i4 >= 0 && this.f7863[i4] == i) {
            if (obj.equals(this.f7861[i4])) {
                return i4;
            }
            i4--;
        }
        return ~i3;
    }

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

    /* renamed from: K  reason: contains not printable characters */
    public final int m5910() {
        int i = this.f7864;
        if (i == 0) {
            return -1;
        }
        int r1 = C2287.m5968(this.f7863, i, 0);
        if (r1 < 0 || this.f7861[r1] == null) {
            return r1;
        }
        int i2 = r1 + 1;
        while (i2 < i && this.f7863[i2] == 0) {
            if (this.f7861[i2] == null) {
                return i2;
            }
            i2++;
        }
        int i3 = r1 - 1;
        while (i3 >= 0 && this.f7863[i3] == 0) {
            if (this.f7861[i3] == null) {
                return i3;
            }
            i3--;
        }
        return ~i2;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m5912(int i) {
        if (i == 8) {
            synchronized (C2274.class) {
                if (f7858 != null) {
                    Object[] objArr = f7858;
                    this.f7861 = objArr;
                    f7858 = (Object[]) objArr[0];
                    this.f7863 = (int[]) objArr[1];
                    objArr[1] = null;
                    objArr[0] = null;
                    f7855--;
                    return;
                }
            }
        } else if (i == 4) {
            synchronized (C2274.class) {
                if (f7860 != null) {
                    Object[] objArr2 = f7860;
                    this.f7861 = objArr2;
                    f7860 = (Object[]) objArr2[0];
                    this.f7863 = (int[]) objArr2[1];
                    objArr2[1] = null;
                    objArr2[0] = null;
                    f7856--;
                    return;
                }
            }
        }
        this.f7863 = new int[i];
        this.f7861 = new Object[i];
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m5908(int[] iArr, Object[] objArr, int i) {
        if (iArr.length == 8) {
            synchronized (C2274.class) {
                if (f7855 < 10) {
                    objArr[0] = f7858;
                    objArr[1] = iArr;
                    for (int i2 = i - 1; i2 >= 2; i2--) {
                        objArr[i2] = null;
                    }
                    f7858 = objArr;
                    f7855++;
                }
            }
        } else if (iArr.length == 4) {
            synchronized (C2274.class) {
                if (f7856 < 10) {
                    objArr[0] = f7860;
                    objArr[1] = iArr;
                    for (int i3 = i - 1; i3 >= 2; i3--) {
                        objArr[i3] = null;
                    }
                    f7860 = objArr;
                    f7856++;
                }
            }
        }
    }
}
