package e4;

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.NoSuchElementException;
import java.util.Set;
import r4.AbstractC0983h;

/* JADX INFO: renamed from: e4.i, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC0565i extends AbstractC0571o {
    public static boolean e0(Iterable iterable, Object obj) {
        int iIndexOf;
        AbstractC0983h.e("<this>", iterable);
        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) {
                    AbstractC0566j.y();
                    throw null;
                }
                if (AbstractC0983h.a(obj, next)) {
                    iIndexOf = i;
                    break;
                }
                i++;
            }
        } else {
            iIndexOf = ((List) iterable).indexOf(obj);
        }
        return iIndexOf >= 0;
    }

    public static Object f0(List list) {
        AbstractC0983h.e("<this>", list);
        if (list.isEmpty()) {
            throw new NoSuchElementException("List is empty.");
        }
        return list.get(0);
    }

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

    public static final void h0(Collection collection, StringBuilder sb, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, CharSequence charSequence4, q4.l lVar) {
        AbstractC0983h.e("<this>", collection);
        sb.append(charSequence2);
        int i = 0;
        for (Object obj : collection) {
            i++;
            if (i > 1) {
                sb.append(charSequence);
            }
            S4.m.a(sb, obj, lVar);
        }
        sb.append(charSequence3);
    }

    public static String j0(Collection collection, String str, String str2, String str3, q4.l lVar, int i) {
        String str4 = (i & 2) != 0 ? "" : str2;
        String str5 = (i & 4) != 0 ? "" : str3;
        if ((i & 32) != 0) {
            lVar = null;
        }
        AbstractC0983h.e("<this>", collection);
        StringBuilder sb = new StringBuilder();
        h0(collection, sb, str, str4, str5, "...", lVar);
        return sb.toString();
    }

    public static Object k0(List list) {
        AbstractC0983h.e("<this>", list);
        if (list.isEmpty()) {
            throw new NoSuchElementException("List is empty.");
        }
        return list.get(AbstractC0566j.l(list));
    }

    public static List l0(Iterable iterable, Comparator comparator) {
        Collection collection = (Collection) iterable;
        if (collection.size() <= 1) {
            return n0(iterable);
        }
        Object[] array = collection.toArray(new Object[0]);
        AbstractC0983h.e("<this>", array);
        if (array.length > 1) {
            Arrays.sort(array, comparator);
        }
        return AbstractC0564h.K(array);
    }

    public static final void m0(Iterable iterable, AbstractCollection abstractCollection) {
        AbstractC0983h.e("<this>", iterable);
        Iterator it = iterable.iterator();
        while (it.hasNext()) {
            abstractCollection.add(it.next());
        }
    }

    public static List n0(Iterable iterable) {
        ArrayList arrayListO0;
        AbstractC0983h.e("<this>", iterable);
        boolean z5 = iterable instanceof Collection;
        C0574r c0574r = C0574r.f6259k;
        if (z5) {
            Collection collection = (Collection) iterable;
            int size = collection.size();
            if (size == 0) {
                return c0574r;
            }
            if (size != 1) {
                return o0(collection);
            }
            return AbstractC0566j.r(iterable instanceof List ? ((List) iterable).get(0) : collection.iterator().next());
        }
        if (z5) {
            arrayListO0 = o0((Collection) iterable);
        } else {
            ArrayList arrayList = new ArrayList();
            m0(iterable, arrayList);
            arrayListO0 = arrayList;
        }
        int size2 = arrayListO0.size();
        return size2 != 0 ? size2 != 1 ? arrayListO0 : AbstractC0566j.r(arrayListO0.get(0)) : c0574r;
    }

    public static ArrayList o0(Collection collection) {
        AbstractC0983h.e("<this>", collection);
        return new ArrayList(collection);
    }

    public static Set p0(Iterable iterable) {
        AbstractC0983h.e("<this>", iterable);
        boolean z5 = iterable instanceof Collection;
        C0576t c0576t = C0576t.f6261k;
        if (z5) {
            Collection collection = (Collection) iterable;
            int size = collection.size();
            if (size != 0) {
                if (size != 1) {
                    LinkedHashSet linkedHashSet = new LinkedHashSet(AbstractC0577u.o(collection.size()));
                    m0(iterable, linkedHashSet);
                    return linkedHashSet;
                }
                Set setSingleton = Collections.singleton(iterable instanceof List ? ((List) iterable).get(0) : collection.iterator().next());
                AbstractC0983h.d("singleton(...)", setSingleton);
                return setSingleton;
            }
        } else {
            LinkedHashSet linkedHashSet2 = new LinkedHashSet();
            m0(iterable, linkedHashSet2);
            int size2 = linkedHashSet2.size();
            if (size2 != 0) {
                if (size2 != 1) {
                    return linkedHashSet2;
                }
                Set setSingleton2 = Collections.singleton(linkedHashSet2.iterator().next());
                AbstractC0983h.d("singleton(...)", setSingleton2);
                return setSingleton2;
            }
        }
        return c0576t;
    }
}
