package kotlin.collections; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.Intrinsics; /* loaded from: classes5.dex */ public abstract class CollectionsKt__MutableCollectionsKt extends CollectionsKt__MutableCollectionsJVMKt { public static boolean addAll(Collection collection, Iterable elements) { Intrinsics.checkNotNullParameter(collection, ""); Intrinsics.checkNotNullParameter(elements, "elements"); if (elements instanceof Collection) { return collection.addAll((Collection) elements); } Iterator it = elements.iterator(); boolean z = false; while (it.hasNext()) { if (collection.add(it.next())) { z = true; } } return z; } public static boolean addAll(Collection collection, Object[] elements) { List asList; Intrinsics.checkNotNullParameter(collection, ""); Intrinsics.checkNotNullParameter(elements, "elements"); asList = ArraysKt___ArraysJvmKt.asList(elements); return collection.addAll(asList); } public static final Collection convertToListIfNotCollection(Iterable iterable) { Intrinsics.checkNotNullParameter(iterable, ""); if (!(iterable instanceof Collection)) { iterable = CollectionsKt___CollectionsKt.toList(iterable); } return (Collection) iterable; } public static final boolean retainAll(Collection collection, Iterable elements) { Intrinsics.checkNotNullParameter(collection, ""); Intrinsics.checkNotNullParameter(elements, "elements"); return collection.retainAll(convertToListIfNotCollection(elements)); } public static boolean removeAll(Iterable iterable, Function1 predicate) { Intrinsics.checkNotNullParameter(iterable, ""); Intrinsics.checkNotNullParameter(predicate, "predicate"); return filterInPlace$CollectionsKt__MutableCollectionsKt(iterable, predicate, true); } public static final boolean filterInPlace$CollectionsKt__MutableCollectionsKt(Iterable iterable, Function1 function1, boolean z) { Iterator it = iterable.iterator(); boolean z2 = false; while (it.hasNext()) { if (((Boolean) function1.invoke(it.next())).booleanValue() == z) { it.remove(); z2 = true; } } return z2; } public static Object removeFirstOrNull(List list) { Intrinsics.checkNotNullParameter(list, ""); if (list.isEmpty()) { return null; } return list.remove(0); } public static Object removeLast(List list) { Intrinsics.checkNotNullParameter(list, ""); if (list.isEmpty()) { throw new NoSuchElementException("List is empty."); } return list.remove(CollectionsKt__CollectionsKt.getLastIndex(list)); } }