package o;

import java.util.AbstractCollection;
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;

/* renamed from: o.zi, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public abstract class AbstractC3117zi extends AbstractC0138Fi {
    public static ArrayList a0(List list) {
        if (!(list instanceof RandomAccess) || list == null) {
            ArrayList arrayList = new ArrayList();
            Iterator it = list.iterator();
            Iterator itC = !it.hasNext() ? C0306Lv.l : AbstractC2461sm0.C(new C0886c90(it, null));
            while (itC.hasNext()) {
                arrayList.add((List) itC.next());
            }
            return arrayList;
        }
        int size = list.size();
        ArrayList arrayList2 = new ArrayList((size / 50) + (size % 50 == 0 ? 0 : 1));
        for (int i = 0; i >= 0 && i < size; i += 50) {
            int i2 = size - i;
            if (50 <= i2) {
                i2 = 50;
            }
            ArrayList arrayList3 = new ArrayList(i2);
            for (int i3 = 0; i3 < i2; i3++) {
                arrayList3.add(list.get(i3 + i));
            }
            arrayList2.add(arrayList3);
        }
        return arrayList2;
    }

    public static boolean b0(Iterable iterable, Object obj) {
        int iIndexOf;
        if (iterable instanceof Collection) {
            return ((Collection) iterable).contains(obj);
        }
        if (!(iterable instanceof List)) {
            Iterator it = iterable.iterator();
            int i = 0;
            while (true) {
                if (!it.hasNext()) {
                    iIndexOf = -1;
                    break;
                }
                Object next = it.next();
                if (i < 0) {
                    AbstractC0008Ai.V();
                    throw null;
                }
                if (F3.c(obj, next)) {
                    iIndexOf = i;
                    break;
                }
                i++;
            }
        } else {
            iIndexOf = ((List) iterable).indexOf(obj);
        }
        return iIndexOf >= 0;
    }

    public static List c0(int i, List list) {
        ArrayList arrayList;
        Object objJ0;
        if (i < 0) {
            throw new IllegalArgumentException(AbstractC0126Ew.k(i, "Requested element count ", " is less than zero.").toString());
        }
        if (i == 0) {
            return t0(list);
        }
        if (list != null) {
            int size = list.size() - i;
            if (size <= 0) {
                return C0332Mv.l;
            }
            if (size == 1) {
                if (list != null) {
                    objJ0 = j0(list);
                } else {
                    Iterator it = list.iterator();
                    if (!it.hasNext()) {
                        throw new NoSuchElementException("Collection is empty.");
                    }
                    Object next = it.next();
                    while (it.hasNext()) {
                        next = it.next();
                    }
                    objJ0 = next;
                }
                return Collections.singletonList(objJ0);
            }
            arrayList = new ArrayList(size);
            if (list != null) {
                if (list instanceof RandomAccess) {
                    int size2 = list.size();
                    while (i < size2) {
                        arrayList.add(list.get(i));
                        i++;
                    }
                } else {
                    ListIterator listIterator = list.listIterator(i);
                    while (listIterator.hasNext()) {
                        arrayList.add(listIterator.next());
                    }
                }
                return arrayList;
            }
        } else {
            arrayList = new ArrayList();
        }
        int i2 = 0;
        for (Object obj : list) {
            if (i2 >= i) {
                arrayList.add(obj);
            } else {
                i2++;
            }
        }
        return AbstractC0008Ai.U(arrayList);
    }

    public static Object d0(Iterable iterable) {
        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) {
        if (list.isEmpty()) {
            throw new NoSuchElementException("List is empty.");
        }
        return list.get(0);
    }

    public static Object f0(List list) {
        if (list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }

    public static final void g0(Iterable iterable, StringBuilder sb, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, OC oc) {
        sb.append(charSequence2);
        int i = 0;
        for (Object obj : iterable) {
            i++;
            if (i > 1) {
                sb.append(charSequence);
            }
            AbstractC1904ms0.b(sb, obj, oc);
        }
        sb.append(charSequence3);
    }

    public static /* synthetic */ void h0(List list, StringBuilder sb, S1 s1, int i) {
        if ((i & 64) != 0) {
            s1 = null;
        }
        g0(list, sb, "\n", "", "", s1);
    }

    public static String i0(Iterable iterable, String str, String str2, String str3, OC oc, int i) {
        if ((i & 1) != 0) {
            str = ", ";
        }
        String str4 = str;
        String str5 = (i & 2) != 0 ? "" : str2;
        String str6 = (i & 4) != 0 ? "" : str3;
        if ((i & 32) != 0) {
            oc = null;
        }
        StringBuilder sb = new StringBuilder();
        g0(iterable, sb, str4, str5, str6, oc);
        return sb.toString();
    }

    public static Object j0(List list) {
        if (list.isEmpty()) {
            throw new NoSuchElementException("List is empty.");
        }
        return list.get(AbstractC0008Ai.R(list));
    }

    public static Object k0(List list) {
        if (list.isEmpty()) {
            return null;
        }
        return list.get(list.size() - 1);
    }

    public static ArrayList l0(Collection collection, List list) {
        if (list == null) {
            ArrayList arrayList = new ArrayList(collection);
            AbstractC0138Fi.Y(list, arrayList);
            return arrayList;
        }
        ArrayList arrayList2 = new ArrayList(list.size() + collection.size());
        arrayList2.addAll(collection);
        arrayList2.addAll(list);
        return arrayList2;
    }

    public static ArrayList m0(List list, Object obj) {
        ArrayList arrayList = new ArrayList(list.size() + 1);
        arrayList.addAll(list);
        arrayList.add(obj);
        return arrayList;
    }

    public static List n0(List list) {
        if (list.size() <= 1) {
            return t0(list);
        }
        List listU0 = u0(list);
        Collections.reverse(listU0);
        return listU0;
    }

    public static List o0(Iterable iterable) {
        if (!(iterable instanceof Collection)) {
            List listU0 = u0(iterable);
            if (((ArrayList) listU0).size() > 1) {
                Collections.sort(listU0);
            }
            return listU0;
        }
        Collection collection = (Collection) iterable;
        if (collection.size() <= 1) {
            return t0(iterable);
        }
        Object[] array = collection.toArray(new Comparable[0]);
        Comparable[] comparableArr = (Comparable[]) array;
        if (comparableArr.length > 1) {
            Arrays.sort(comparableArr);
        }
        return Arrays.asList(array);
    }

    public static List p0(ArrayList arrayList, Comparator comparator) {
        if (arrayList == null) {
            List listU0 = u0(arrayList);
            AbstractC0112Ei.X(listU0, comparator);
            return listU0;
        }
        if (arrayList.size() <= 1) {
            return t0(arrayList);
        }
        Object[] array = arrayList.toArray(new Object[0]);
        if (array.length > 1) {
            Arrays.sort(array, comparator);
        }
        return Arrays.asList(array);
    }

    public static List q0(int i, List list) {
        if (i < 0) {
            throw new IllegalArgumentException(AbstractC0126Ew.k(i, "Requested element count ", " is less than zero.").toString());
        }
        if (i == 0) {
            return C0332Mv.l;
        }
        if (i >= list.size()) {
            return t0(list);
        }
        if (i == 1) {
            return Collections.singletonList(d0(list));
        }
        ArrayList arrayList = new ArrayList(i);
        Iterator it = list.iterator();
        int i2 = 0;
        while (it.hasNext()) {
            arrayList.add(it.next());
            i2++;
            if (i2 == i) {
                break;
            }
        }
        return AbstractC0008Ai.U(arrayList);
    }

    public static byte[] r0(ArrayList arrayList) {
        byte[] bArr = new byte[arrayList.size()];
        int size = arrayList.size();
        int i = 0;
        int i2 = 0;
        while (i2 < size) {
            Object obj = arrayList.get(i2);
            i2++;
            bArr[i] = ((Number) obj).byteValue();
            i++;
        }
        return bArr;
    }

    public static final void s0(Iterable iterable, AbstractCollection abstractCollection) {
        Iterator it = iterable.iterator();
        while (it.hasNext()) {
            abstractCollection.add(it.next());
        }
    }

    public static List t0(Iterable iterable) {
        if (!(iterable instanceof Collection)) {
            return AbstractC0008Ai.U(u0(iterable));
        }
        Collection collection = (Collection) iterable;
        int size = collection.size();
        if (size == 0) {
            return C0332Mv.l;
        }
        if (size != 1) {
            return new ArrayList(collection);
        }
        return Collections.singletonList(iterable instanceof List ? ((List) iterable).get(0) : iterable.iterator().next());
    }

    public static final List u0(Iterable iterable) {
        if (iterable instanceof Collection) {
            return new ArrayList((Collection) iterable);
        }
        ArrayList arrayList = new ArrayList();
        s0(iterable, arrayList);
        return arrayList;
    }

    public static Set v0(Collection collection) {
        if (collection instanceof Collection) {
            return new LinkedHashSet(collection);
        }
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        s0(collection, linkedHashSet);
        return linkedHashSet;
    }

    public static Set w0(Iterable iterable) {
        if (iterable instanceof Collection) {
            Collection collection = (Collection) iterable;
            int size = collection.size();
            if (size != 0) {
                if (size == 1) {
                    return Collections.singleton(iterable instanceof List ? ((List) iterable).get(0) : iterable.iterator().next());
                }
                LinkedHashSet linkedHashSet = new LinkedHashSet(GN.Z(collection.size()));
                s0(iterable, linkedHashSet);
                return linkedHashSet;
            }
        } else {
            LinkedHashSet linkedHashSet2 = new LinkedHashSet();
            s0(iterable, linkedHashSet2);
            int size2 = linkedHashSet2.size();
            if (size2 != 0) {
                return size2 != 1 ? linkedHashSet2 : Collections.singleton(linkedHashSet2.iterator().next());
            }
        }
        return C0462Rv.l;
    }
}
