package com.bytedance.adsdk.ro;

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;

/* JADX INFO: loaded from: classes.dex */
abstract class fhx<K, V> {
    fhx<K, V>.ro ro;

    public final class fm<T> implements Iterator<T> {
        final int fm;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        int f6201lb;
        int ro;
        boolean yz = false;

        public fm(int i10) {
            this.fm = i10;
            this.ro = fhx.this.fm();
        }

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

        @Override // java.util.Iterator
        public T next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            T t10 = (T) fhx.this.fm(this.f6201lb, this.fm);
            this.f6201lb++;
            this.yz = true;
            return t10;
        }

        @Override // java.util.Iterator
        public void remove() {
            if (!this.yz) {
                throw new IllegalStateException();
            }
            int i10 = this.f6201lb - 1;
            this.f6201lb = i10;
            this.ro--;
            this.yz = false;
            fhx.this.fm(i10);
        }
    }

    public final class ro implements Set<K> {
        public ro() {
        }

        @Override // java.util.Set, java.util.Collection
        public boolean add(K k6) {
            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() {
            fhx.this.lb();
        }

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

        @Override // java.util.Set, java.util.Collection
        public boolean containsAll(Collection<?> collection) {
            return fhx.fm(fhx.this.ro(), collection);
        }

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

        @Override // java.util.Set, java.util.Collection
        public int hashCode() {
            int iHashCode = 0;
            for (int iFm = fhx.this.fm() - 1; iFm >= 0; iFm--) {
                Object objFm = fhx.this.fm(iFm, 0);
                iHashCode += objFm == null ? 0 : objFm.hashCode();
            }
            return iHashCode;
        }

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

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

        @Override // java.util.Set, java.util.Collection
        public boolean remove(Object obj) {
            int iFm = fhx.this.fm(obj);
            if (iFm < 0) {
                return false;
            }
            fhx.this.fm(iFm);
            return true;
        }

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

        @Override // java.util.Set, java.util.Collection
        public boolean retainAll(Collection<?> collection) {
            return fhx.lb(fhx.this.ro(), collection);
        }

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

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

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

    public static <K, V> boolean fm(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 lb(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 static <K, V> boolean ro(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 abstract int fm();

    public abstract int fm(Object obj);

    public abstract Object fm(int i10, int i11);

    public abstract void fm(int i10);

    public abstract void lb();

    public abstract Map<K, V> ro();

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

    public <T> T[] fm(T[] tArr, int i10) {
        int iFm = fm();
        if (tArr.length < iFm) {
            tArr = (T[]) ((Object[]) Array.newInstance(tArr.getClass().getComponentType(), iFm));
        }
        for (int i11 = 0; i11 < iFm; i11++) {
            tArr[i11] = fm(i11, i10);
        }
        if (tArr.length > iFm) {
            tArr[iFm] = null;
        }
        return tArr;
    }

    public Object[] ro(int i10) {
        int iFm = fm();
        Object[] objArr = new Object[iFm];
        for (int i11 = 0; i11 < iFm; i11++) {
            objArr[i11] = fm(i11, i10);
        }
        return objArr;
    }

    public static <T> boolean fm(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;
    }
}
