package com.bytedance.adsdk.Sg;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
/* loaded from: classes2.dex */
abstract class EH<K, V> {
    EH<K, V>.Sg Sg;

    protected abstract Map<K, V> Sg();

    protected abstract int YFl();

    protected abstract int YFl(Object obj);

    protected abstract Object YFl(int i, int i2);

    protected abstract void YFl(int i);

    protected abstract void tN();

    /* loaded from: classes2.dex */
    final class YFl<T> implements Iterator<T> {
        boolean AlY = false;
        int Sg;
        final int YFl;
        int tN;

        @Override // java.util.Iterator
        public boolean hasNext() {
            return this.tN < this.Sg;
        }

        YFl(int i) {
            this.YFl = i;
            this.Sg = EH.this.YFl();
        }

        @Override // java.util.Iterator
        public T next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            T t = (T) EH.this.YFl(this.tN, this.YFl);
            this.tN++;
            this.AlY = true;
            return t;
        }

        @Override // java.util.Iterator
        public void remove() {
            if (!this.AlY) {
                throw new IllegalStateException();
            }
            int i = this.tN - 1;
            this.tN = i;
            this.Sg--;
            this.AlY = false;
            EH.this.YFl(i);
        }
    }

    /* loaded from: classes2.dex */
    final class Sg implements Set<K> {
        Sg() {
        }

        @Override // java.util.Set, java.util.Collection
        public boolean add(K k) {
            throw new UnsupportedOperationException();
        }

        @Override // java.util.Set, java.util.Collection
        public boolean addAll(Collection<? extends K> collection) {
            throw new UnsupportedOperationException();
        }

        @Override // java.util.Set, java.util.Collection
        public void clear() {
            EH.this.tN();
        }

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

        @Override // java.util.Set, java.util.Collection
        public boolean containsAll(Collection<?> collection) {
            return EH.YFl(EH.this.Sg(), collection);
        }

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

        @Override // java.util.Set, java.util.Collection, java.lang.Iterable
        public Iterator<K> iterator() {
            return new YFl(0);
        }

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

        @Override // java.util.Set, java.util.Collection
        public boolean removeAll(Collection<?> collection) {
            return EH.Sg(EH.this.Sg(), collection);
        }

        @Override // java.util.Set, java.util.Collection
        public boolean retainAll(Collection<?> collection) {
            return EH.tN(EH.this.Sg(), collection);
        }

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

        @Override // java.util.Set, java.util.Collection
        public Object[] toArray() {
            return EH.this.Sg(0);
        }

        @Override // java.util.Set, java.util.Collection
        public <T> T[] toArray(T[] tArr) {
            return (T[]) EH.this.YFl(tArr, 0);
        }

        @Override // java.util.Set, java.util.Collection
        public boolean equals(Object obj) {
            return EH.YFl(this, obj);
        }

        @Override // java.util.Set, java.util.Collection
        public int hashCode() {
            int i = 0;
            for (int YFl = EH.this.YFl() - 1; YFl >= 0; YFl--) {
                Object YFl2 = EH.this.YFl(YFl, 0);
                i += YFl2 == null ? 0 : YFl2.hashCode();
            }
            return i;
        }
    }

    public static <K, V> boolean YFl(Map<K, V> map, Collection<?> collection) {
        Iterator<?> it = collection.iterator();
        while (it.hasNext()) {
            if (!map.containsKey(it.next())) {
                return false;
            }
        }
        return true;
    }

    public static <K, V> boolean Sg(Map<K, V> map, Collection<?> collection) {
        int size = map.size();
        Iterator<?> it = collection.iterator();
        while (it.hasNext()) {
            map.remove(it.next());
        }
        return size != map.size();
    }

    public static <K, V> boolean tN(Map<K, V> map, Collection<?> collection) {
        int size = map.size();
        Iterator<K> it = map.keySet().iterator();
        while (it.hasNext()) {
            if (!collection.contains(it.next())) {
                it.remove();
            }
        }
        return size != map.size();
    }

    public Object[] Sg(int i) {
        int YFl2 = YFl();
        Object[] objArr = new Object[YFl2];
        for (int i2 = 0; i2 < YFl2; i2++) {
            objArr[i2] = YFl(i2, i);
        }
        return objArr;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public <T> T[] YFl(T[] tArr, int i) {
        int YFl2 = YFl();
        if (tArr.length < YFl2) {
            tArr = (T[]) ((Object[]) Array.newInstance(tArr.getClass().getComponentType(), YFl2));
        }
        for (int i2 = 0; i2 < YFl2; i2++) {
            tArr[i2] = YFl(i2, i);
        }
        if (tArr.length > YFl2) {
            tArr[YFl2] = null;
        }
        return tArr;
    }

    public static <T> boolean YFl(Set<T> set, Object obj) {
        if (set == obj) {
            return true;
        }
        if (obj instanceof Set) {
            Set set2 = (Set) obj;
            try {
                if (set.size() == set2.size()) {
                    if (set.containsAll(set2)) {
                        return true;
                    }
                }
            } catch (ClassCastException | NullPointerException unused) {
            }
        }
        return false;
    }

    public Set<K> AlY() {
        if (this.Sg == null) {
            this.Sg = new Sg();
        }
        return this.Sg;
    }
}
