package x4;

import B.B0;
import java.util.AbstractCollection;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.RandomAccess;
import java.util.Set;
import n2.AbstractC2612c;
import w4.InterfaceC3143e;

/* JADX INFO: renamed from: x4.q, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC3251q extends AbstractC3257w {
    public static final void A0(Iterable iterable, AbstractCollection abstractCollection) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        Iterator it = iterable.iterator();
        while (it.hasNext()) {
            abstractCollection.add(it.next());
        }
    }

    public static int[] B0(List list) {
        kotlin.jvm.internal.o.h(list, "<this>");
        int[] iArr = new int[list.size()];
        Iterator it = list.iterator();
        int i6 = 0;
        while (it.hasNext()) {
            iArr[i6] = ((Number) it.next()).intValue();
            i6++;
        }
        return iArr;
    }

    public static List C0(Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if (!(iterable instanceof Collection)) {
            return AbstractC3252r.D(F0(iterable));
        }
        Collection collection = (Collection) iterable;
        int size = collection.size();
        if (size == 0) {
            return y.f26065a;
        }
        if (size != 1) {
            return E0(collection);
        }
        return AbstractC2612c.q(iterable instanceof List ? ((List) iterable).get(0) : collection.iterator().next());
    }

    public static long[] D0(List list) {
        kotlin.jvm.internal.o.h(list, "<this>");
        long[] jArr = new long[list.size()];
        Iterator it = list.iterator();
        int i6 = 0;
        while (it.hasNext()) {
            jArr[i6] = ((Number) it.next()).longValue();
            i6++;
        }
        return jArr;
    }

    public static ArrayList E0(Collection collection) {
        kotlin.jvm.internal.o.h(collection, "<this>");
        return new ArrayList(collection);
    }

    public static final List F0(Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if (iterable instanceof Collection) {
            return E0((Collection) iterable);
        }
        ArrayList arrayList = new ArrayList();
        A0(iterable, arrayList);
        return arrayList;
    }

    public static Set G0(Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if (iterable instanceof Collection) {
            return new LinkedHashSet((Collection) iterable);
        }
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        A0(iterable, linkedHashSet);
        return linkedHashSet;
    }

    public static Set H0(Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        boolean z6 = iterable instanceof Collection;
        C3224A c3224a = C3224A.f26032a;
        if (z6) {
            Collection collection = (Collection) iterable;
            int size = collection.size();
            if (size != 0) {
                if (size == 1) {
                    return m1.g.o(iterable instanceof List ? ((List) iterable).get(0) : collection.iterator().next());
                }
                LinkedHashSet linkedHashSet = new LinkedHashSet(AbstractC3229F.u(collection.size()));
                A0(iterable, linkedHashSet);
                return linkedHashSet;
            }
        } else {
            LinkedHashSet linkedHashSet2 = new LinkedHashSet();
            A0(iterable, linkedHashSet2);
            int size2 = linkedHashSet2.size();
            if (size2 != 0) {
                return size2 != 1 ? linkedHashSet2 : m1.g.o(linkedHashSet2.iterator().next());
            }
        }
        return c3224a;
    }

    public static ArrayList I0(Iterable iterable, int i6, int i7) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if (i6 <= 0 || i7 <= 0) {
            throw new IllegalArgumentException((i6 != i7 ? "Both size " + i6 + " and step " + i7 + " must be greater than zero." : Z0.o.j(i6, "size ", " must be greater than zero.")).toString());
        }
        if (!(iterable instanceof RandomAccess) || !(iterable instanceof List)) {
            ArrayList arrayList = new ArrayList();
            Iterator iterator = iterable.iterator();
            kotlin.jvm.internal.o.h(iterator, "iterator");
            Iterator itL = !iterator.hasNext() ? C3258x.f26064a : A4.g.L(new C3234K(i6, i7, iterator, null));
            while (itL.hasNext()) {
                arrayList.add((List) itL.next());
            }
            return arrayList;
        }
        List list = (List) iterable;
        int size = list.size();
        ArrayList arrayList2 = new ArrayList((size / i7) + (size % i7 == 0 ? 0 : 1));
        int i8 = 0;
        while (i8 >= 0 && i8 < size) {
            int i9 = size - i8;
            if (i6 <= i9) {
                i9 = i6;
            }
            ArrayList arrayList3 = new ArrayList(i9);
            for (int i10 = 0; i10 < i9; i10++) {
                arrayList3.add(list.get(i10 + i8));
            }
            arrayList2.add(arrayList3);
            i8 += i7;
        }
        return arrayList2;
    }

    public static ArrayList J0(List list, ArrayList arrayList) {
        Iterator it = list.iterator();
        Iterator it2 = arrayList.iterator();
        ArrayList arrayList2 = new ArrayList(Math.min(AbstractC3253s.G(list, 10), AbstractC3253s.G(arrayList, 10)));
        while (it.hasNext() && it2.hasNext()) {
            arrayList2.add(new w4.k(it.next(), it2.next()));
        }
        return arrayList2;
    }

    public static H4.f W(Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        return new H4.f(iterable, 6);
    }

    public static double X(ArrayList arrayList) {
        Iterator it = arrayList.iterator();
        double dFloatValue = 0.0d;
        int i6 = 0;
        while (it.hasNext()) {
            dFloatValue += (double) ((Number) it.next()).floatValue();
            i6++;
            if (i6 < 0) {
                throw new ArithmeticException("Count overflow has happened.");
            }
        }
        if (i6 == 0) {
            return Double.NaN;
        }
        return dFloatValue / ((double) i6);
    }

    public static boolean Y(Iterable iterable, Object obj) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        return iterable instanceof Collection ? ((Collection) iterable).contains(obj) : i0(iterable, obj) >= 0;
    }

    public static List Z(List list) {
        return C0(G0(list));
    }

    public static List a0(Iterable iterable, int i6) {
        ArrayList arrayList;
        Object objN0;
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if (i6 < 0) {
            throw new IllegalArgumentException(Z0.o.j(i6, "Requested element count ", " is less than zero.").toString());
        }
        if (i6 == 0) {
            return C0(iterable);
        }
        if (iterable instanceof Collection) {
            int size = ((Collection) iterable).size() - i6;
            if (size <= 0) {
                return y.f26065a;
            }
            if (size == 1) {
                if (iterable instanceof List) {
                    objN0 = n0((List) iterable);
                } else {
                    Iterator it = iterable.iterator();
                    if (!it.hasNext()) {
                        throw new NoSuchElementException("Collection is empty.");
                    }
                    Object next = it.next();
                    while (it.hasNext()) {
                        next = it.next();
                    }
                    objN0 = next;
                }
                return AbstractC2612c.q(objN0);
            }
            arrayList = new ArrayList(size);
            if (iterable instanceof List) {
                if (iterable instanceof RandomAccess) {
                    List list = (List) iterable;
                    int size2 = list.size();
                    while (i6 < size2) {
                        arrayList.add(list.get(i6));
                        i6++;
                    }
                } else {
                    ListIterator listIterator = ((List) iterable).listIterator(i6);
                    while (listIterator.hasNext()) {
                        arrayList.add(listIterator.next());
                    }
                }
                return arrayList;
            }
        } else {
            arrayList = new ArrayList();
        }
        int i7 = 0;
        for (Object obj : iterable) {
            if (i7 >= i6) {
                arrayList.add(obj);
            } else {
                i7++;
            }
        }
        return AbstractC3252r.D(arrayList);
    }

    public static List b0(List list) {
        kotlin.jvm.internal.o.h(list, "<this>");
        int size = list.size() - 1;
        if (size < 0) {
            size = 0;
        }
        return y0(list, size);
    }

    public static ArrayList c0(List list) {
        kotlin.jvm.internal.o.h(list, "<this>");
        ArrayList arrayList = new ArrayList();
        for (Object obj : list) {
            if (obj != null) {
                arrayList.add(obj);
            }
        }
        return arrayList;
    }

    public static Object d0(Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if (iterable instanceof List) {
            return e0((List) iterable);
        }
        Iterator it = iterable.iterator();
        if (it.hasNext()) {
            return it.next();
        }
        throw new NoSuchElementException("Collection is empty.");
    }

    public static Object e0(List list) {
        kotlin.jvm.internal.o.h(list, "<this>");
        if (list.isEmpty()) {
            throw new NoSuchElementException("List is empty.");
        }
        return list.get(0);
    }

    public static Object f0(Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if (iterable instanceof List) {
            List list = (List) iterable;
            if (list.isEmpty()) {
                return null;
            }
            return list.get(0);
        }
        Iterator it = iterable.iterator();
        if (it.hasNext()) {
            return it.next();
        }
        return null;
    }

    public static Object g0(List list) {
        kotlin.jvm.internal.o.h(list, "<this>");
        if (list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }

    public static Object h0(int i6, List list) {
        kotlin.jvm.internal.o.h(list, "<this>");
        if (i6 < 0 || i6 >= list.size()) {
            return null;
        }
        return list.get(i6);
    }

    public static int i0(Iterable iterable, Object obj) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if (iterable instanceof List) {
            return ((List) iterable).indexOf(obj);
        }
        int i6 = 0;
        for (Object obj2 : iterable) {
            if (i6 < 0) {
                AbstractC3252r.F();
                throw null;
            }
            if (kotlin.jvm.internal.o.c(obj, obj2)) {
                return i6;
            }
            i6++;
        }
        return -1;
    }

    public static Set j0(Iterable iterable, Iterable other) {
        kotlin.jvm.internal.o.h(other, "other");
        Set setG0 = G0(iterable);
        setG0.retainAll(AbstractC3257w.N(other));
        return setG0;
    }

    public static final void k0(Iterable iterable, StringBuilder sb, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i6, CharSequence charSequence4, J4.c cVar) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        sb.append(charSequence2);
        int i7 = 0;
        for (Object obj : iterable) {
            i7++;
            if (i7 > 1) {
                sb.append(charSequence);
            }
            if (i6 >= 0 && i7 > i6) {
                break;
            } else {
                e4.C.l(sb, obj, cVar);
            }
        }
        if (i6 >= 0 && i7 > i6) {
            sb.append(charSequence4);
        }
        sb.append(charSequence3);
    }

    public static /* synthetic */ void l0(List list, StringBuilder sb, B0 b02, int i6) {
        if ((i6 & 64) != 0) {
            b02 = null;
        }
        k0(list, sb, "\n", "", "", -1, "...", b02);
    }

    public static String m0(Iterable iterable, String str, String str2, String str3, J4.c cVar, int i6) {
        if ((i6 & 1) != 0) {
            str = ", ";
        }
        String str4 = str;
        String prefix = (i6 & 2) != 0 ? "" : str2;
        String str5 = (i6 & 4) != 0 ? "" : str3;
        int i7 = (i6 & 8) != 0 ? -1 : 4000;
        if ((i6 & 32) != 0) {
            cVar = null;
        }
        kotlin.jvm.internal.o.h(iterable, "<this>");
        kotlin.jvm.internal.o.h(prefix, "prefix");
        StringBuilder sb = new StringBuilder();
        k0(iterable, sb, str4, prefix, str5, i7, "...", cVar);
        return sb.toString();
    }

    public static Object n0(List list) {
        kotlin.jvm.internal.o.h(list, "<this>");
        if (list.isEmpty()) {
            throw new NoSuchElementException("List is empty.");
        }
        return list.get(AbstractC3252r.A(list));
    }

    public static Object o0(List list) {
        kotlin.jvm.internal.o.h(list, "<this>");
        if (list.isEmpty()) {
            return null;
        }
        return list.get(list.size() - 1);
    }

    public static Comparable p0(Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        Iterator it = iterable.iterator();
        if (!it.hasNext()) {
            return null;
        }
        Comparable comparable = (Comparable) it.next();
        while (it.hasNext()) {
            Comparable comparable2 = (Comparable) it.next();
            if (comparable.compareTo(comparable2) < 0) {
                comparable = comparable2;
            }
        }
        return comparable;
    }

    public static Object q0(AbstractList abstractList, Comparator comparator) {
        Iterator it = abstractList.iterator();
        if (!it.hasNext()) {
            return null;
        }
        Object next = it.next();
        while (it.hasNext()) {
            Object next2 = it.next();
            if (comparator.compare(next, next2) < 0) {
                next = next2;
            }
        }
        return next;
    }

    public static ArrayList r0(List list, InterfaceC3143e interfaceC3143e) {
        kotlin.jvm.internal.o.h(list, "<this>");
        ArrayList arrayList = new ArrayList(AbstractC3253s.G(list, 10));
        boolean z6 = false;
        for (Object obj : list) {
            boolean z7 = true;
            if (!z6 && kotlin.jvm.internal.o.c(obj, interfaceC3143e)) {
                z6 = true;
                z7 = false;
            }
            if (z7) {
                arrayList.add(obj);
            }
        }
        return arrayList;
    }

    public static ArrayList s0(Iterable elements, Collection collection) {
        kotlin.jvm.internal.o.h(collection, "<this>");
        kotlin.jvm.internal.o.h(elements, "elements");
        if (!(elements instanceof Collection)) {
            ArrayList arrayList = new ArrayList(collection);
            AbstractC3257w.L(elements, arrayList);
            return arrayList;
        }
        Collection collection2 = (Collection) elements;
        ArrayList arrayList2 = new ArrayList(collection2.size() + collection.size());
        arrayList2.addAll(collection);
        arrayList2.addAll(collection2);
        return arrayList2;
    }

    public static ArrayList t0(Collection collection, Object obj) {
        kotlin.jvm.internal.o.h(collection, "<this>");
        ArrayList arrayList = new ArrayList(collection.size() + 1);
        arrayList.addAll(collection);
        arrayList.add(obj);
        return arrayList;
    }

    public static List u0(Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if ((iterable instanceof Collection) && ((Collection) iterable).size() <= 1) {
            return C0(iterable);
        }
        List listF0 = F0(iterable);
        Collections.reverse(listF0);
        return listF0;
    }

    public static List v0(List list, P4.g indices) {
        kotlin.jvm.internal.o.h(list, "<this>");
        kotlin.jvm.internal.o.h(indices, "indices");
        if (indices.isEmpty()) {
            return y.f26065a;
        }
        return C0(list.subList(indices.f5676a, indices.f5677b + 1));
    }

    public static List w0(Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if (!(iterable instanceof Collection)) {
            List listF0 = F0(iterable);
            AbstractC3256v.I(listF0);
            return listF0;
        }
        Collection collection = (Collection) iterable;
        if (collection.size() <= 1) {
            return C0(iterable);
        }
        Object[] array = collection.toArray(new Comparable[0]);
        Comparable[] comparableArr = (Comparable[]) array;
        kotlin.jvm.internal.o.h(comparableArr, "<this>");
        if (comparableArr.length > 1) {
            Arrays.sort(comparableArr);
        }
        return AbstractC3250p.r(array);
    }

    public static List x0(Comparator comparator, Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if (!(iterable instanceof Collection)) {
            List listF0 = F0(iterable);
            AbstractC3256v.J(listF0, comparator);
            return listF0;
        }
        Collection collection = (Collection) iterable;
        if (collection.size() <= 1) {
            return C0(iterable);
        }
        Object[] array = collection.toArray(new Object[0]);
        kotlin.jvm.internal.o.h(array, "<this>");
        if (array.length > 1) {
            Arrays.sort(array, comparator);
        }
        return AbstractC3250p.r(array);
    }

    public static List y0(Iterable iterable, int i6) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        if (i6 < 0) {
            throw new IllegalArgumentException(Z0.o.j(i6, "Requested element count ", " is less than zero.").toString());
        }
        if (i6 == 0) {
            return y.f26065a;
        }
        if (iterable instanceof Collection) {
            if (i6 >= ((Collection) iterable).size()) {
                return C0(iterable);
            }
            if (i6 == 1) {
                return AbstractC2612c.q(d0(iterable));
            }
        }
        ArrayList arrayList = new ArrayList(i6);
        Iterator it = iterable.iterator();
        int i7 = 0;
        while (it.hasNext()) {
            arrayList.add(it.next());
            i7++;
            if (i7 == i6) {
                break;
            }
        }
        return AbstractC3252r.D(arrayList);
    }

    public static byte[] z0(ArrayList arrayList) {
        byte[] bArr = new byte[arrayList.size()];
        Iterator it = arrayList.iterator();
        int i6 = 0;
        while (it.hasNext()) {
            bArr[i6] = ((Number) it.next()).byteValue();
            i6++;
        }
        return bArr;
    }
}
