package o; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.NoSuchElementException; import java.util.Set; /* loaded from: classes.dex */ public class gaG extends gaD { /* loaded from: classes.dex */ public static final class IeS implements gdE { private Iterable d; public IeS(Iterable iterable) { this.d = iterable; } @Override // o.gdE public final Iterator e() { return this.d.iterator(); } } public static final boolean b(Iterable iterable, T t) { C14957gcv.e(iterable, ""); if (iterable instanceof Collection) { return ((Collection) iterable).contains(t); } return C14881gav.a(iterable, t) >= 0; } public static final T a(Iterable iterable) { C14957gcv.e(iterable, ""); if (iterable instanceof List) { return (T) C14881gav.e((List) iterable); } Iterator it = iterable.iterator(); if (!it.hasNext()) { throw new NoSuchElementException("Collection is empty."); } return it.next(); } public static final T e(List list) { C14957gcv.e(list, ""); if (list.isEmpty()) { throw new NoSuchElementException("List is empty."); } return list.get(0); } public static final T b(List list, int i) { C14957gcv.e(list, ""); if (i >= 0) { C14957gcv.e(list, ""); if (i <= list.size() - 1) { return list.get(i); } } return null; } public static final int a(Iterable iterable, T t) { C14957gcv.e(iterable, ""); if (iterable instanceof List) { return ((List) iterable).indexOf(t); } int i = 0; for (T t2 : iterable) { if (i >= 0) { if (C14957gcv.b(t, t2)) { return i; } i++; } else { throw new ArithmeticException("Index overflow has happened."); } } return -1; } public static final T d(List list) { C14957gcv.e(list, ""); if (list.isEmpty()) { throw new NoSuchElementException("List is empty."); } C14957gcv.e(list, ""); return list.get(list.size() - 1); } public static final , T> C b(Iterable iterable, C c) { C14957gcv.e(iterable, ""); C14957gcv.e(c, ""); for (T t : iterable) { if (t != null) { c.add(t); } } return c; } public static final > List b(Iterable iterable) { C14957gcv.e(iterable, ""); if (iterable instanceof Collection) { Collection collection = (Collection) iterable; if (collection.size() <= 1) { return C14881gav.d(iterable); } Object[] array = collection.toArray(new Comparable[0]); Comparable[] comparableArr = (Comparable[]) array; C14957gcv.e(comparableArr, ""); if (comparableArr.length > 1) { Arrays.sort(comparableArr); } C14957gcv.e(array, ""); List asList = Arrays.asList(array); C14957gcv.c(asList, ""); return asList; } List c = C14881gav.c(iterable); C14957gcv.e(c, ""); if (c.size() > 1) { Collections.sort(c); } return c; } /* JADX WARN: Multi-variable type inference failed */ public static final List a(Iterable iterable, Comparator comparator) { C14957gcv.e(iterable, ""); C14957gcv.e(comparator, ""); if (iterable instanceof Collection) { Collection collection = (Collection) iterable; if (collection.size() <= 1) { return C14881gav.d(iterable); } Object[] array = collection.toArray(new Object[0]); C14957gcv.e(array, ""); C14957gcv.e(comparator, ""); if (array.length > 1) { Arrays.sort(array, comparator); } C14957gcv.e(array, ""); List asList = Arrays.asList(array); C14957gcv.c(asList, ""); return asList; } List c = C14881gav.c(iterable); C14957gcv.e(c, ""); C14957gcv.e(comparator, ""); if (c.size() > 1) { Collections.sort(c, comparator); } return c; } public static final int[] a(Collection collection) { C14957gcv.e(collection, ""); int[] iArr = new int[collection.size()]; Iterator it = collection.iterator(); int i = 0; while (it.hasNext()) { iArr[i] = it.next().intValue(); i++; } return iArr; } public static final > C a(Iterable iterable, C c) { C14957gcv.e(iterable, ""); C14957gcv.e(c, ""); Iterator it = iterable.iterator(); while (it.hasNext()) { c.add(it.next()); } return c; } public static final HashSet e(Iterable iterable) { C14957gcv.e(iterable, ""); C14957gcv.e(iterable, ""); return (HashSet) C14881gav.a((Iterable) iterable, new HashSet(C14856gaP.a(iterable instanceof Collection ? ((Collection) iterable).size() : 12))); } public static final List d(Iterable iterable) { C14957gcv.e(iterable, ""); if (iterable instanceof Collection) { Collection collection = (Collection) iterable; int size = collection.size(); if (size == 0) { return C14851gaI.c; } if (size != 1) { C14957gcv.e(collection, ""); return new ArrayList(collection); } List singletonList = Collections.singletonList(iterable instanceof List ? ((List) iterable).get(0) : iterable.iterator().next()); C14957gcv.c(singletonList, ""); return singletonList; } return C14881gav.a(C14881gav.c(iterable)); } public static final List c(Iterable iterable) { C14957gcv.e(iterable, ""); if (iterable instanceof Collection) { Collection collection = (Collection) iterable; C14957gcv.e(collection, ""); return new ArrayList(collection); } return (List) C14881gav.a((Iterable) iterable, new ArrayList()); } public static final Set h(Iterable iterable) { C14957gcv.e(iterable, ""); if (iterable instanceof Collection) { Collection collection = (Collection) iterable; int size = collection.size(); if (size == 0) { return gaH.e; } if (size != 1) { return (Set) C14881gav.a((Iterable) iterable, new LinkedHashSet(C14856gaP.a(collection.size()))); } Set singleton = Collections.singleton(iterable instanceof List ? ((List) iterable).get(0) : iterable.iterator().next()); C14957gcv.c(singleton, ""); return singleton; } return C14858gaV.d((Set) C14881gav.a((Iterable) iterable, new LinkedHashSet())); } public static final List a(Collection collection, T t) { C14957gcv.e(collection, ""); ArrayList arrayList = new ArrayList(collection.size() + 1); arrayList.addAll(collection); arrayList.add(t); return arrayList; } public static final List e(Collection collection, Iterable iterable) { C14957gcv.e(collection, ""); C14957gcv.e(iterable, ""); if (iterable instanceof Collection) { Collection collection2 = (Collection) iterable; ArrayList arrayList = new ArrayList(collection.size() + collection2.size()); arrayList.addAll(collection); arrayList.addAll(collection2); return arrayList; } ArrayList arrayList2 = new ArrayList(collection); C14881gav.d(arrayList2, iterable); return arrayList2; } public static /* synthetic */ Appendable c(Iterable iterable, Appendable appendable, CharSequence charSequence) { return C14881gav.a(iterable, appendable, charSequence, "", "", -1, "...", null); } public static final A a(Iterable iterable, A a, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i, CharSequence charSequence4, InterfaceC14894gbR interfaceC14894gbR) { C14957gcv.e(iterable, ""); C14957gcv.e(a, ""); C14957gcv.e(charSequence, ""); C14957gcv.e(charSequence2, ""); C14957gcv.e(charSequence3, ""); C14957gcv.e(charSequence4, ""); a.append(charSequence2); int i2 = 0; for (T t : iterable) { i2++; if (i2 > 1) { a.append(charSequence); } if (i >= 0 && i2 > i) { break; } gdZ.e(a, t, interfaceC14894gbR); } if (i >= 0 && i2 > i) { a.append(charSequence4); } a.append(charSequence3); return a; } public static /* synthetic */ String b(Iterable iterable, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i, CharSequence charSequence4, InterfaceC14894gbR interfaceC14894gbR, int i2) { if ((i2 & 1) != 0) { } CharSequence charSequence5 = charSequence; if ((i2 & 2) != 0) { } CharSequence charSequence6 = charSequence2; if ((i2 & 4) != 0) { } CharSequence charSequence7 = charSequence3; if ((i2 & 8) != 0) { i = -1; } int i3 = i; if ((i2 & 16) != 0) { } CharSequence charSequence8 = charSequence4; if ((i2 & 32) != 0) { interfaceC14894gbR = null; } return C14881gav.d(iterable, charSequence5, charSequence6, charSequence7, i3, charSequence8, interfaceC14894gbR); } public static final String d(Iterable iterable, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i, CharSequence charSequence4, InterfaceC14894gbR interfaceC14894gbR) { C14957gcv.e(iterable, ""); C14957gcv.e(charSequence, ""); C14957gcv.e(charSequence2, ""); C14957gcv.e(charSequence3, ""); C14957gcv.e(charSequence4, ""); String obj = ((StringBuilder) C14881gav.a(iterable, new StringBuilder(), charSequence, charSequence2, charSequence3, i, charSequence4, interfaceC14894gbR)).toString(); C14957gcv.c((Object) obj, ""); return obj; } public static final List c(Iterable iterable, int i) { C14957gcv.e(iterable, ""); if (i < 0) { StringBuilder sb = new StringBuilder("Requested element count "); sb.append(i); sb.append(" is less than zero."); throw new IllegalArgumentException(sb.toString().toString()); } if (i != 0) { if (iterable instanceof Collection) { if (i >= ((Collection) iterable).size()) { return C14881gav.d(iterable); } if (i == 1) { List singletonList = Collections.singletonList(C14881gav.a(iterable)); C14957gcv.c(singletonList, ""); return singletonList; } } ArrayList arrayList = new ArrayList(i); Iterator it = iterable.iterator(); int i2 = 0; while (it.hasNext()) { arrayList.add(it.next()); i2++; if (i2 == i) { break; } } return C14881gav.a((List) arrayList); } return C14851gaI.c; } }