package kotlin.collections; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.HashSet; 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 kotlin.TuplesKt; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.Intrinsics; import kotlin.random.Random; import kotlin.ranges.IntRange; import kotlin.sequences.Sequence; import kotlin.text.StringsKt__AppendableKt; /* loaded from: classes5.dex */ public abstract class CollectionsKt___CollectionsKt extends CollectionsKt___CollectionsJvmKt { public static boolean contains(Iterable iterable, Object obj) { Intrinsics.checkNotNullParameter(iterable, ""); if (iterable instanceof Collection) { return ((Collection) iterable).contains(obj); } return indexOf(iterable, obj) >= 0; } public static final Object elementAt(Iterable iterable, final int i) { Intrinsics.checkNotNullParameter(iterable, ""); if (iterable instanceof List) { return ((List) iterable).get(i); } return elementAtOrElse(iterable, i, new Function1() { // from class: kotlin.collections.CollectionsKt___CollectionsKt$elementAt$1 /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ { super(1); } public final Object invoke(int i2) { throw new IndexOutOfBoundsException("Collection doesn't contain element at index " + i + '.'); } @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Object invoke(Object obj) { return invoke(((Number) obj).intValue()); } }); } public static final Object elementAtOrElse(Iterable iterable, int i, Function1 defaultValue) { Intrinsics.checkNotNullParameter(iterable, ""); Intrinsics.checkNotNullParameter(defaultValue, "defaultValue"); if (iterable instanceof List) { List list = (List) iterable; return (i < 0 || i > CollectionsKt__CollectionsKt.getLastIndex(list)) ? defaultValue.invoke(Integer.valueOf(i)) : list.get(i); } if (i < 0) { return defaultValue.invoke(Integer.valueOf(i)); } int i2 = 0; for (Object obj : iterable) { int i3 = i2 + 1; if (i == i2) { return obj; } i2 = i3; } return defaultValue.invoke(Integer.valueOf(i)); } public static final Object first(Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); if (iterable instanceof List) { return first((List) iterable); } Iterator it = iterable.iterator(); if (!it.hasNext()) { throw new NoSuchElementException("Collection is empty."); } return it.next(); } public static Object first(List list) { Intrinsics.checkNotNullParameter(list, ""); if (list.isEmpty()) { throw new NoSuchElementException("List is empty."); } return list.get(0); } public static Object firstOrNull(Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); 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 firstOrNull(List list) { Intrinsics.checkNotNullParameter(list, ""); if (list.isEmpty()) { return null; } return list.get(0); } public static Object getOrNull(List list, int i) { Intrinsics.checkNotNullParameter(list, ""); if (i < 0 || i > CollectionsKt__CollectionsKt.getLastIndex(list)) { return null; } return list.get(i); } public static final int indexOf(Iterable iterable, Object obj) { Intrinsics.checkNotNullParameter(iterable, ""); if (iterable instanceof List) { return ((List) iterable).indexOf(obj); } int i = 0; for (Object obj2 : iterable) { if (i < 0) { CollectionsKt__CollectionsKt.throwIndexOverflow(); } if (Intrinsics.areEqual(obj, obj2)) { return i; } i++; } return -1; } public static final Object last(Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); if (iterable instanceof List) { return last((List) iterable); } Iterator it = iterable.iterator(); if (!it.hasNext()) { throw new NoSuchElementException("Collection is empty."); } Object next = it.next(); while (it.hasNext()) { next = it.next(); } return next; } public static Object last(List list) { Intrinsics.checkNotNullParameter(list, ""); if (list.isEmpty()) { throw new NoSuchElementException("List is empty."); } return list.get(CollectionsKt__CollectionsKt.getLastIndex(list)); } public static Object random(Collection collection, Random random) { Intrinsics.checkNotNullParameter(collection, ""); Intrinsics.checkNotNullParameter(random, "random"); if (collection.isEmpty()) { throw new NoSuchElementException("Collection is empty."); } return elementAt(collection, random.nextInt(collection.size())); } public static Object single(Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); if (iterable instanceof List) { return single((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 single(List list) { Intrinsics.checkNotNullParameter(list, ""); 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 drop(Iterable iterable, int i) { ArrayList arrayList; Intrinsics.checkNotNullParameter(iterable, ""); if (i < 0) { throw new IllegalArgumentException(("Requested element count " + i + " is less than zero.").toString()); } if (i == 0) { return toList(iterable); } if (iterable instanceof Collection) { Collection collection = (Collection) iterable; int size = collection.size() - i; if (size <= 0) { return CollectionsKt__CollectionsKt.emptyList(); } if (size == 1) { return CollectionsKt__CollectionsJVMKt.listOf(last(iterable)); } arrayList = new ArrayList(size); if (iterable instanceof List) { if (iterable instanceof RandomAccess) { int size2 = collection.size(); while (i < size2) { arrayList.add(((List) iterable).get(i)); i++; } } else { ListIterator listIterator = ((List) iterable).listIterator(i); while (listIterator.hasNext()) { arrayList.add(listIterator.next()); } } return arrayList; } } else { arrayList = new ArrayList(); } int i2 = 0; for (Object obj : iterable) { if (i2 >= i) { arrayList.add(obj); } else { i2++; } } return CollectionsKt__CollectionsKt.optimizeReadOnlyList(arrayList); } public static List filterNotNull(Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); return (List) filterNotNullTo(iterable, new ArrayList()); } public static final Collection filterNotNullTo(Iterable iterable, Collection destination) { Intrinsics.checkNotNullParameter(iterable, ""); Intrinsics.checkNotNullParameter(destination, "destination"); for (Object obj : iterable) { if (obj != null) { destination.add(obj); } } return destination; } public static List slice(List list, IntRange indices) { Intrinsics.checkNotNullParameter(list, ""); Intrinsics.checkNotNullParameter(indices, "indices"); return indices.isEmpty() ? CollectionsKt__CollectionsKt.emptyList() : toList(list.subList(indices.getStart().intValue(), indices.getEndInclusive().intValue() + 1)); } public static List take(Iterable iterable, int i) { Intrinsics.checkNotNullParameter(iterable, ""); if (i < 0) { throw new IllegalArgumentException(("Requested element count " + i + " is less than zero.").toString()); } if (i == 0) { return CollectionsKt__CollectionsKt.emptyList(); } if (iterable instanceof Collection) { if (i >= ((Collection) iterable).size()) { return toList(iterable); } if (i == 1) { return CollectionsKt__CollectionsJVMKt.listOf(first(iterable)); } } 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 CollectionsKt__CollectionsKt.optimizeReadOnlyList(arrayList); } public static List sorted(Iterable iterable) { List asList; Intrinsics.checkNotNullParameter(iterable, ""); if (iterable instanceof Collection) { Collection collection = (Collection) iterable; if (collection.size() <= 1) { return toList(iterable); } Object[] array = collection.toArray(new Comparable[0]); ArraysKt___ArraysJvmKt.sort((Comparable[]) array); asList = ArraysKt___ArraysJvmKt.asList(array); return asList; } List mutableList = toMutableList(iterable); CollectionsKt__MutableCollectionsJVMKt.sort(mutableList); return mutableList; } public static List sortedWith(Iterable iterable, Comparator comparator) { List asList; Intrinsics.checkNotNullParameter(iterable, ""); Intrinsics.checkNotNullParameter(comparator, "comparator"); if (iterable instanceof Collection) { Collection collection = (Collection) iterable; if (collection.size() <= 1) { return toList(iterable); } Object[] array = collection.toArray(new Object[0]); ArraysKt___ArraysJvmKt.sortWith(array, comparator); asList = ArraysKt___ArraysJvmKt.asList(array); return asList; } List mutableList = toMutableList(iterable); CollectionsKt__MutableCollectionsJVMKt.sortWith(mutableList, comparator); return mutableList; } public static int[] toIntArray(Collection collection) { Intrinsics.checkNotNullParameter(collection, ""); int[] iArr = new int[collection.size()]; Iterator it = collection.iterator(); int i = 0; while (it.hasNext()) { iArr[i] = ((Number) it.next()).intValue(); i++; } return iArr; } public static final Collection toCollection(Iterable iterable, Collection destination) { Intrinsics.checkNotNullParameter(iterable, ""); Intrinsics.checkNotNullParameter(destination, "destination"); Iterator it = iterable.iterator(); while (it.hasNext()) { destination.add(it.next()); } return destination; } public static HashSet toHashSet(Iterable iterable) { int mapCapacity; Intrinsics.checkNotNullParameter(iterable, ""); mapCapacity = MapsKt__MapsJVMKt.mapCapacity(CollectionsKt__IterablesKt.collectionSizeOrDefault(iterable, 12)); return (HashSet) toCollection(iterable, new HashSet(mapCapacity)); } public static List toList(Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); if (iterable instanceof Collection) { Collection collection = (Collection) iterable; int size = collection.size(); if (size == 0) { return CollectionsKt__CollectionsKt.emptyList(); } if (size != 1) { return toMutableList(collection); } return CollectionsKt__CollectionsJVMKt.listOf(iterable instanceof List ? ((List) iterable).get(0) : iterable.iterator().next()); } return CollectionsKt__CollectionsKt.optimizeReadOnlyList(toMutableList(iterable)); } public static final List toMutableList(Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); if (iterable instanceof Collection) { return toMutableList((Collection) iterable); } return (List) toCollection(iterable, new ArrayList()); } public static List toMutableList(Collection collection) { Intrinsics.checkNotNullParameter(collection, ""); return new ArrayList(collection); } public static Set toSet(Iterable iterable) { Set emptySet; Set of; int mapCapacity; Intrinsics.checkNotNullParameter(iterable, ""); if (iterable instanceof Collection) { Collection collection = (Collection) iterable; int size = collection.size(); if (size == 0) { emptySet = SetsKt__SetsKt.emptySet(); return emptySet; } if (size == 1) { of = SetsKt__SetsJVMKt.setOf(iterable instanceof List ? ((List) iterable).get(0) : iterable.iterator().next()); return of; } mapCapacity = MapsKt__MapsJVMKt.mapCapacity(collection.size()); return (Set) toCollection(iterable, new LinkedHashSet(mapCapacity)); } return SetsKt__SetsKt.optimizeReadOnlySet((Set) toCollection(iterable, new LinkedHashSet())); } public static List distinct(Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); return toList(toMutableSet(iterable)); } public static Set intersect(Iterable iterable, Iterable other) { Intrinsics.checkNotNullParameter(iterable, ""); Intrinsics.checkNotNullParameter(other, "other"); Set mutableSet = toMutableSet(iterable); CollectionsKt__MutableCollectionsKt.retainAll(mutableSet, other); return mutableSet; } public static Set toMutableSet(Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); return iterable instanceof Collection ? new LinkedHashSet((Collection) iterable) : (Set) toCollection(iterable, new LinkedHashSet()); } public static Comparable minOrNull(Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); 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 List minus(Iterable iterable, Object obj) { Intrinsics.checkNotNullParameter(iterable, ""); ArrayList arrayList = new ArrayList(CollectionsKt__IterablesKt.collectionSizeOrDefault(iterable, 10)); boolean z = false; for (Object obj2 : iterable) { boolean z2 = true; if (!z && Intrinsics.areEqual(obj2, obj)) { z = true; z2 = false; } if (z2) { arrayList.add(obj2); } } return arrayList; } public static List plus(Collection collection, Object obj) { Intrinsics.checkNotNullParameter(collection, ""); ArrayList arrayList = new ArrayList(collection.size() + 1); arrayList.addAll(collection); arrayList.add(obj); return arrayList; } public static List plus(Iterable iterable, Iterable elements) { Intrinsics.checkNotNullParameter(iterable, ""); Intrinsics.checkNotNullParameter(elements, "elements"); if (iterable instanceof Collection) { return plus((Collection) iterable, elements); } ArrayList arrayList = new ArrayList(); CollectionsKt__MutableCollectionsKt.addAll(arrayList, iterable); CollectionsKt__MutableCollectionsKt.addAll(arrayList, elements); return arrayList; } public static List plus(Collection collection, Iterable elements) { Intrinsics.checkNotNullParameter(collection, ""); Intrinsics.checkNotNullParameter(elements, "elements"); if (elements instanceof Collection) { Collection collection2 = (Collection) elements; ArrayList arrayList = new ArrayList(collection.size() + collection2.size()); arrayList.addAll(collection); arrayList.addAll(collection2); return arrayList; } ArrayList arrayList2 = new ArrayList(collection); CollectionsKt__MutableCollectionsKt.addAll(arrayList2, elements); return arrayList2; } public static List zip(Iterable iterable, Iterable other) { Intrinsics.checkNotNullParameter(iterable, ""); Intrinsics.checkNotNullParameter(other, "other"); Iterator it = iterable.iterator(); Iterator it2 = other.iterator(); ArrayList arrayList = new ArrayList(Math.min(CollectionsKt__IterablesKt.collectionSizeOrDefault(iterable, 10), CollectionsKt__IterablesKt.collectionSizeOrDefault(other, 10))); while (it.hasNext() && it2.hasNext()) { arrayList.add(TuplesKt.to(it.next(), it2.next())); } return arrayList; } public static /* synthetic */ Appendable joinTo$default(Iterable iterable, Appendable appendable, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i, CharSequence charSequence4, Function1 function1, int i2, Object obj) { return joinTo(iterable, appendable, (i2 & 2) != 0 ? ", " : charSequence, (i2 & 4) != 0 ? "" : charSequence2, (i2 & 8) == 0 ? charSequence3 : "", (i2 & 16) != 0 ? -1 : i, (i2 & 32) != 0 ? "..." : charSequence4, (i2 & 64) != 0 ? null : function1); } public static final Appendable joinTo(Iterable iterable, Appendable buffer, CharSequence separator, CharSequence prefix, CharSequence postfix, int i, CharSequence truncated, Function1 function1) { Intrinsics.checkNotNullParameter(iterable, ""); Intrinsics.checkNotNullParameter(buffer, "buffer"); Intrinsics.checkNotNullParameter(separator, "separator"); Intrinsics.checkNotNullParameter(prefix, "prefix"); Intrinsics.checkNotNullParameter(postfix, "postfix"); Intrinsics.checkNotNullParameter(truncated, "truncated"); buffer.append(prefix); int i2 = 0; for (Object obj : iterable) { i2++; if (i2 > 1) { buffer.append(separator); } if (i >= 0 && i2 > i) { break; } StringsKt__AppendableKt.appendElement(buffer, obj, function1); } if (i >= 0 && i2 > i) { buffer.append(truncated); } buffer.append(postfix); return buffer; } public static /* synthetic */ String joinToString$default(Iterable iterable, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i, CharSequence charSequence4, Function1 function1, int i2, Object obj) { if ((i2 & 1) != 0) { charSequence = ", "; } CharSequence charSequence5 = (i2 & 2) != 0 ? "" : charSequence2; CharSequence charSequence6 = (i2 & 4) == 0 ? charSequence3 : ""; if ((i2 & 8) != 0) { i = -1; } int i3 = i; if ((i2 & 16) != 0) { charSequence4 = "..."; } CharSequence charSequence7 = charSequence4; if ((i2 & 32) != 0) { function1 = null; } return joinToString(iterable, charSequence, charSequence5, charSequence6, i3, charSequence7, function1); } public static final String joinToString(Iterable iterable, CharSequence separator, CharSequence prefix, CharSequence postfix, int i, CharSequence truncated, Function1 function1) { Intrinsics.checkNotNullParameter(iterable, ""); Intrinsics.checkNotNullParameter(separator, "separator"); Intrinsics.checkNotNullParameter(prefix, "prefix"); Intrinsics.checkNotNullParameter(postfix, "postfix"); Intrinsics.checkNotNullParameter(truncated, "truncated"); String sb = ((StringBuilder) joinTo(iterable, new StringBuilder(), separator, prefix, postfix, i, truncated, function1)).toString(); Intrinsics.checkNotNullExpressionValue(sb, "toString(...)"); return sb; } public static Sequence asSequence(final Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); return new Sequence() { // from class: kotlin.collections.CollectionsKt___CollectionsKt$asSequence$$inlined$Sequence$1 @Override // kotlin.sequences.Sequence public Iterator iterator() { return iterable.iterator(); } }; } }