package F3;

import a.AbstractC0872a;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.RandomAccess;
import java.util.Set;
import java.util.SortedSet;

/* JADX INFO: renamed from: F3.u, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC0220u {
    public static int a(int i6) {
        if (i6 < 3) {
            d(i6, "expectedSize");
            return i6 + 1;
        }
        if (i6 < 1073741824) {
            return (int) Math.ceil(((double) i6) / 0.75d);
        }
        return Integer.MAX_VALUE;
    }

    public static void b(int i6, Object[] objArr) {
        for (int i7 = 0; i7 < i6; i7++) {
            if (objArr[i7] == null) {
                throw new NullPointerException(Z0.o.l("at index ", i7));
            }
        }
    }

    public static void c(Object obj, Object obj2) {
        if (obj == null) {
            throw new NullPointerException("null key in entry: null=" + obj2);
        }
        if (obj2 != null) {
            return;
        }
        throw new NullPointerException("null value in entry: " + obj + "=null");
    }

    public static void d(int i6, String str) {
        if (i6 >= 0) {
            return;
        }
        throw new IllegalArgumentException(str + " cannot be negative but was: " + i6);
    }

    public static boolean e(C0 c02, Object obj) {
        Iterator it = c02.f1493a;
        if (obj == null) {
            while (it.hasNext()) {
                if (c02.next() == null) {
                    return true;
                }
            }
            return false;
        }
        while (it.hasNext()) {
            if (obj.equals(c02.next())) {
                return true;
            }
        }
        return false;
    }

    public static Object f(int i6) {
        if (i6 < 2 || i6 > 1073741824 || Integer.highestOneBit(i6) != i6) {
            throw new IllegalArgumentException(Z0.o.l("must be power of 2 between 2^1 and 2^30: ", i6));
        }
        return i6 <= 256 ? new byte[i6] : i6 <= 65536 ? new short[i6] : new int[i6];
    }

    public static boolean g(Object obj, Map map) {
        if (map == obj) {
            return true;
        }
        if (obj instanceof Map) {
            return map.entrySet().equals(((Map) obj).entrySet());
        }
        return false;
    }

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

    public static y0 i(Set set, E3.k kVar) {
        if (!(set instanceof SortedSet)) {
            if (!(set instanceof y0)) {
                set.getClass();
                return new y0(set, kVar);
            }
            y0 y0Var = (y0) set;
            E3.k kVar2 = y0Var.f1632b;
            kVar2.getClass();
            return new y0(y0Var.f1631a, new E3.l(Arrays.asList(kVar2, kVar)));
        }
        Set set2 = (SortedSet) set;
        if (!(set2 instanceof y0)) {
            set2.getClass();
            return new z0(set2, kVar);
        }
        y0 y0Var2 = (y0) set2;
        E3.k kVar3 = y0Var2.f1632b;
        kVar3.getClass();
        return new z0((SortedSet) y0Var2.f1631a, new E3.l(Arrays.asList(kVar3, kVar)));
    }

    public static Object j(Collection collection, String str) {
        Iterator it = collection.iterator();
        return it.hasNext() ? it.next() : str;
    }

    public static Object k(Iterable iterable) {
        Object next;
        if (iterable instanceof List) {
            List list = (List) iterable;
            if (list.isEmpty()) {
                throw new NoSuchElementException();
            }
            return list.get(list.size() - 1);
        }
        Iterator it = iterable.iterator();
        do {
            next = it.next();
        } while (it.hasNext());
        return next;
    }

    public static Object l(Iterable iterable) {
        Object next;
        if (iterable instanceof Collection) {
            if (((Collection) iterable).isEmpty()) {
                return null;
            }
            if (iterable instanceof List) {
                return ((List) iterable).get(r2.size() - 1);
            }
        }
        Iterator it = iterable.iterator();
        if (!it.hasNext()) {
            return null;
        }
        do {
            next = it.next();
        } while (it.hasNext());
        return next;
    }

    public static int m(Set set) {
        Iterator it = set.iterator();
        int i6 = 0;
        while (it.hasNext()) {
            Object next = it.next();
            i6 = ~(~(i6 + (next != null ? next.hashCode() : 0)));
        }
        return i6;
    }

    public static x0 n(Z z6, Z z7) {
        A4.g.o(z6, "set1");
        A4.g.o(z7, "set2");
        return new x0(z6, z7);
    }

    public static int o(int i6, int i7, int i8) {
        return (i6 & (~i8)) | (i7 & i8);
    }

    public static ArrayList p(Object... objArr) {
        int length = objArr.length;
        d(length, "arraySize");
        ArrayList arrayList = new ArrayList(AbstractC0872a.d0(((long) length) + 5 + ((long) (length / 10))));
        Collections.addAll(arrayList, objArr);
        return arrayList;
    }

    public static int q(Object obj, Object obj2, int i6, Object obj3, int[] iArr, Object[] objArr, Object[] objArr2) {
        int i7;
        int i8;
        int iT = t(obj);
        int i9 = iT & i6;
        int iU = u(i9, obj3);
        if (iU != 0) {
            int i10 = ~i6;
            int i11 = iT & i10;
            int i12 = -1;
            while (true) {
                i7 = iU - 1;
                i8 = iArr[i7];
                if ((i8 & i10) == i11 && android.support.v4.media.session.b.n(obj, objArr[i7]) && (objArr2 == null || android.support.v4.media.session.b.n(obj2, objArr2[i7]))) {
                    break;
                }
                int i13 = i8 & i6;
                if (i13 == 0) {
                    break;
                }
                i12 = i7;
                iU = i13;
            }
            int i14 = i8 & i6;
            if (i12 == -1) {
                v(i9, i14, obj3);
                return i7;
            }
            iArr[i12] = o(iArr[i12], i14, i6);
            return i7;
        }
        return -1;
    }

    public static void r(List list, E3.k kVar, int i6, int i7) {
        for (int size = list.size() - 1; size > i7; size--) {
            if (kVar.apply(list.get(size))) {
                list.remove(size);
            }
        }
        for (int i8 = i7 - 1; i8 >= i6; i8--) {
            list.remove(i8);
        }
    }

    public static int s(int i6) {
        return (int) (((long) Integer.rotateLeft((int) (((long) i6) * (-862048943)), 15)) * 461845907);
    }

    public static int t(Object obj) {
        return s(obj == null ? 0 : obj.hashCode());
    }

    public static int u(int i6, Object obj) {
        return obj instanceof byte[] ? ((byte[]) obj)[i6] & 255 : obj instanceof short[] ? ((short[]) obj)[i6] & 65535 : ((int[]) obj)[i6];
    }

    public static void v(int i6, int i7, Object obj) {
        if (obj instanceof byte[]) {
            ((byte[]) obj)[i6] = (byte) i7;
        } else if (obj instanceof short[]) {
            ((short[]) obj)[i6] = (short) i7;
        } else {
            ((int[]) obj)[i6] = i7;
        }
    }

    public static String w(Map map) {
        int size = map.size();
        d(size, "size");
        StringBuilder sb = new StringBuilder((int) Math.min(((long) size) * 8, 1073741824L));
        sb.append('{');
        boolean z6 = true;
        for (Map.Entry entry : map.entrySet()) {
            if (!z6) {
                sb.append(", ");
            }
            sb.append(entry.getKey());
            sb.append('=');
            sb.append(entry.getValue());
            z6 = false;
        }
        sb.append('}');
        return sb.toString();
    }

    public static AbstractList x(List list, E3.g gVar) {
        return list instanceof RandomAccess ? new g0(list, gVar) : new h0(list, gVar);
    }
}
