package o1;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
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 okhttp3.HttpUrl;

/* JADX INFO: Access modifiers changed from: package-private */
/* JADX INFO: loaded from: classes.dex */
public abstract class v extends u {

    public static final class a implements D1.f {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ Iterable f6002a;

        public a(Iterable iterable) {
            this.f6002a = iterable;
        }

        @Override // D1.f
        public Iterator iterator() {
            return this.f6002a.iterator();
        }
    }

    public static final int A(Iterable iterable, Object obj) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        if (iterable instanceof List) {
            return ((List) iterable).indexOf(obj);
        }
        int i2 = 0;
        for (Object obj2 : iterable) {
            if (i2 < 0) {
                AbstractC0676l.n();
            }
            if (kotlin.jvm.internal.l.a(obj, obj2)) {
                return i2;
            }
            i2++;
        }
        return -1;
    }

    public static final Appendable B(Iterable iterable, Appendable buffer, CharSequence separator, CharSequence prefix, CharSequence postfix, int i2, CharSequence truncated, y1.l lVar) throws IOException {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        kotlin.jvm.internal.l.e(buffer, "buffer");
        kotlin.jvm.internal.l.e(separator, "separator");
        kotlin.jvm.internal.l.e(prefix, "prefix");
        kotlin.jvm.internal.l.e(postfix, "postfix");
        kotlin.jvm.internal.l.e(truncated, "truncated");
        buffer.append(prefix);
        int i3 = 0;
        for (Object obj : iterable) {
            i3++;
            if (i3 > 1) {
                buffer.append(separator);
            }
            if (i2 >= 0 && i3 > i2) {
                break;
            }
            E1.g.a(buffer, obj, lVar);
        }
        if (i2 >= 0 && i3 > i2) {
            buffer.append(truncated);
        }
        buffer.append(postfix);
        return buffer;
    }

    public static /* synthetic */ Appendable C(Iterable iterable, Appendable appendable, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i2, CharSequence charSequence4, y1.l lVar, int i3, Object obj) {
        CharSequence charSequence5 = (i3 & 2) != 0 ? ", " : charSequence;
        int i4 = i3 & 4;
        CharSequence charSequence6 = HttpUrl.FRAGMENT_ENCODE_SET;
        CharSequence charSequence7 = i4 != 0 ? HttpUrl.FRAGMENT_ENCODE_SET : charSequence2;
        if ((i3 & 8) == 0) {
            charSequence6 = charSequence3;
        }
        return B(iterable, appendable, charSequence5, charSequence7, charSequence6, (i3 & 16) != 0 ? -1 : i2, (i3 & 32) != 0 ? "..." : charSequence4, (i3 & 64) != 0 ? null : lVar);
    }

    public static final String D(Iterable iterable, CharSequence separator, CharSequence prefix, CharSequence postfix, int i2, CharSequence truncated, y1.l lVar) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        kotlin.jvm.internal.l.e(separator, "separator");
        kotlin.jvm.internal.l.e(prefix, "prefix");
        kotlin.jvm.internal.l.e(postfix, "postfix");
        kotlin.jvm.internal.l.e(truncated, "truncated");
        String string = ((StringBuilder) B(iterable, new StringBuilder(), separator, prefix, postfix, i2, truncated, lVar)).toString();
        kotlin.jvm.internal.l.d(string, "toString(...)");
        return string;
    }

    public static /* synthetic */ String E(Iterable iterable, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i2, CharSequence charSequence4, y1.l lVar, int i3, Object obj) {
        if ((i3 & 1) != 0) {
            charSequence = ", ";
        }
        int i4 = i3 & 2;
        CharSequence charSequence5 = HttpUrl.FRAGMENT_ENCODE_SET;
        CharSequence charSequence6 = i4 != 0 ? HttpUrl.FRAGMENT_ENCODE_SET : charSequence2;
        if ((i3 & 4) == 0) {
            charSequence5 = charSequence3;
        }
        if ((i3 & 8) != 0) {
            i2 = -1;
        }
        int i5 = i2;
        if ((i3 & 16) != 0) {
            charSequence4 = "...";
        }
        CharSequence charSequence7 = charSequence4;
        if ((i3 & 32) != 0) {
            lVar = null;
        }
        return D(iterable, charSequence, charSequence6, charSequence5, i5, charSequence7, lVar);
    }

    public static Object F(List list) {
        kotlin.jvm.internal.l.e(list, "<this>");
        if (list.isEmpty()) {
            throw new NoSuchElementException("List is empty.");
        }
        return list.get(AbstractC0676l.g(list));
    }

    public static List G(Collection collection, Iterable elements) {
        kotlin.jvm.internal.l.e(collection, "<this>");
        kotlin.jvm.internal.l.e(elements, "elements");
        if (!(elements instanceof Collection)) {
            ArrayList arrayList = new ArrayList(collection);
            AbstractC0676l.r(arrayList, elements);
            return arrayList;
        }
        Collection collection2 = (Collection) elements;
        ArrayList arrayList2 = new ArrayList(collection.size() + collection2.size());
        arrayList2.addAll(collection);
        arrayList2.addAll(collection2);
        return arrayList2;
    }

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

    public static List I(Iterable iterable) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        if ((iterable instanceof Collection) && ((Collection) iterable).size() <= 1) {
            return AbstractC0676l.P(iterable);
        }
        List listQ = Q(iterable);
        u.t(listQ);
        return listQ;
    }

    public static Object J(Iterable iterable) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        if (iterable instanceof List) {
            return K((List) iterable);
        }
        Iterator it = iterable.iterator();
        if (!it.hasNext()) {
            throw new NoSuchElementException("Collection is empty.");
        }
        Object next = it.next();
        if (it.hasNext()) {
            throw new IllegalArgumentException("Collection has more than one element.");
        }
        return next;
    }

    public static final Object K(List list) {
        kotlin.jvm.internal.l.e(list, "<this>");
        int size = list.size();
        if (size == 0) {
            throw new NoSuchElementException("List is empty.");
        }
        if (size == 1) {
            return list.get(0);
        }
        throw new IllegalArgumentException("List has more than one element.");
    }

    public static List L(Iterable iterable, Comparator comparator) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        kotlin.jvm.internal.l.e(comparator, "comparator");
        if (!(iterable instanceof Collection)) {
            List listQ = Q(iterable);
            r.q(listQ, comparator);
            return listQ;
        }
        Collection collection = (Collection) iterable;
        if (collection.size() <= 1) {
            return AbstractC0676l.P(iterable);
        }
        Object[] array = collection.toArray(new Object[0]);
        AbstractC0671g.m(array, comparator);
        return AbstractC0668d.b(array);
    }

    public static List M(Iterable iterable, int i2) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        if (i2 < 0) {
            throw new IllegalArgumentException(("Requested element count " + i2 + " is less than zero.").toString());
        }
        if (i2 == 0) {
            return AbstractC0676l.f();
        }
        if (iterable instanceof Collection) {
            if (i2 >= ((Collection) iterable).size()) {
                return AbstractC0676l.P(iterable);
            }
            if (i2 == 1) {
                return AbstractC0676l.b(x(iterable));
            }
        }
        ArrayList arrayList = new ArrayList(i2);
        Iterator it = iterable.iterator();
        int i3 = 0;
        while (it.hasNext()) {
            arrayList.add(it.next());
            i3++;
            if (i3 == i2) {
                break;
            }
        }
        return AbstractC0678n.k(arrayList);
    }

    public static byte[] N(Collection collection) {
        kotlin.jvm.internal.l.e(collection, "<this>");
        byte[] bArr = new byte[collection.size()];
        Iterator it = collection.iterator();
        int i2 = 0;
        while (it.hasNext()) {
            bArr[i2] = ((Number) it.next()).byteValue();
            i2++;
        }
        return bArr;
    }

    public static final Collection O(Iterable iterable, Collection destination) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        kotlin.jvm.internal.l.e(destination, "destination");
        Iterator it = iterable.iterator();
        while (it.hasNext()) {
            destination.add(it.next());
        }
        return destination;
    }

    public static List P(Iterable iterable) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        if (!(iterable instanceof Collection)) {
            return AbstractC0678n.k(Q(iterable));
        }
        Collection collection = (Collection) iterable;
        int size = collection.size();
        if (size == 0) {
            return AbstractC0676l.f();
        }
        if (size != 1) {
            return AbstractC0676l.R(collection);
        }
        return AbstractC0676l.b(iterable instanceof List ? ((List) iterable).get(0) : iterable.iterator().next());
    }

    public static final List Q(Iterable iterable) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        return iterable instanceof Collection ? AbstractC0676l.R((Collection) iterable) : (List) O(iterable, new ArrayList());
    }

    public static List R(Collection collection) {
        kotlin.jvm.internal.l.e(collection, "<this>");
        return new ArrayList(collection);
    }

    public static Set S(Iterable iterable) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        if (!(iterable instanceof Collection)) {
            return AbstractC0663K.c((Set) O(iterable, new LinkedHashSet()));
        }
        Collection collection = (Collection) iterable;
        int size = collection.size();
        if (size == 0) {
            return AbstractC0661I.b();
        }
        if (size != 1) {
            return (Set) O(iterable, new LinkedHashSet(AbstractC0655C.a(collection.size())));
        }
        return AbstractC0662J.a(iterable instanceof List ? ((List) iterable).get(0) : iterable.iterator().next());
    }

    public static D1.f u(Iterable iterable) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        return new a(iterable);
    }

    public static boolean v(Iterable iterable, Object obj) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        return iterable instanceof Collection ? ((Collection) iterable).contains(obj) : A(iterable, obj) >= 0;
    }

    public static List w(List list, int i2) {
        kotlin.jvm.internal.l.e(list, "<this>");
        if (i2 >= 0) {
            return AbstractC0676l.M(list, kotlin.ranges.m.b(list.size() - i2, 0));
        }
        throw new IllegalArgumentException(("Requested element count " + i2 + " is less than zero.").toString());
    }

    public static final Object x(Iterable iterable) {
        kotlin.jvm.internal.l.e(iterable, "<this>");
        if (iterable instanceof List) {
            return AbstractC0676l.y((List) iterable);
        }
        Iterator it = iterable.iterator();
        if (it.hasNext()) {
            return it.next();
        }
        throw new NoSuchElementException("Collection is empty.");
    }

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

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