package x4;

import androidx.compose.runtime.external.kotlinx.collections.immutable.PersistentCollection;
import java.util.AbstractList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.RandomAccess;

/* JADX INFO: renamed from: x4.w, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC3257w extends AbstractC3256v {
    public static void K(PersistentCollection.Builder builder, R4.k elements) {
        kotlin.jvm.internal.o.h(builder, "<this>");
        kotlin.jvm.internal.o.h(elements, "elements");
        Iterator it = elements.iterator();
        while (it.hasNext()) {
            builder.add(it.next());
        }
    }

    public static void L(Iterable elements, Collection collection) {
        kotlin.jvm.internal.o.h(collection, "<this>");
        kotlin.jvm.internal.o.h(elements, "elements");
        if (elements instanceof Collection) {
            collection.addAll((Collection) elements);
            return;
        }
        Iterator it = elements.iterator();
        while (it.hasNext()) {
            collection.add(it.next());
        }
    }

    public static void M(Collection collection, Object[] elements) {
        kotlin.jvm.internal.o.h(collection, "<this>");
        kotlin.jvm.internal.o.h(elements, "elements");
        collection.addAll(AbstractC3250p.r(elements));
    }

    public static final Collection N(Iterable iterable) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        return iterable instanceof Collection ? (Collection) iterable : AbstractC3251q.C0(iterable);
    }

    public static final boolean O(Iterable iterable, J4.c cVar, boolean z6) {
        Iterator it = iterable.iterator();
        boolean z7 = false;
        while (it.hasNext()) {
            if (((Boolean) cVar.invoke(it.next())).booleanValue() == z6) {
                it.remove();
                z7 = true;
            }
        }
        return z7;
    }

    public static void P(J4.c predicate, List list) {
        int iA;
        kotlin.jvm.internal.o.h(list, "<this>");
        kotlin.jvm.internal.o.h(predicate, "predicate");
        if (!(list instanceof RandomAccess)) {
            if (!(list instanceof K4.a) || (list instanceof K4.b)) {
                O(list, predicate, true);
                return;
            } else {
                kotlin.jvm.internal.F.f(list, "kotlin.collections.MutableIterable");
                throw null;
            }
        }
        int iA2 = AbstractC3252r.A(list);
        int i6 = 0;
        if (iA2 >= 0) {
            int i7 = 0;
            while (true) {
                Object obj = list.get(i6);
                if (!((Boolean) predicate.invoke(obj)).booleanValue()) {
                    if (i7 != i6) {
                        list.set(i7, obj);
                    }
                    i7++;
                }
                if (i6 == iA2) {
                    break;
                } else {
                    i6++;
                }
            }
            i6 = i7;
        }
        if (i6 >= list.size() || i6 > (iA = AbstractC3252r.A(list))) {
            return;
        }
        while (true) {
            list.remove(iA);
            if (iA == i6) {
                return;
            } else {
                iA--;
            }
        }
    }

    public static void Q(Iterable iterable, J4.c predicate) {
        kotlin.jvm.internal.o.h(iterable, "<this>");
        kotlin.jvm.internal.o.h(predicate, "predicate");
        O(iterable, predicate, true);
    }

    public static void R(Iterable elements, Collection collection) {
        kotlin.jvm.internal.o.h(collection, "<this>");
        kotlin.jvm.internal.o.h(elements, "elements");
        collection.removeAll(N(elements));
    }

    public static void S(Collection collection, R4.k elements) {
        kotlin.jvm.internal.o.h(collection, "<this>");
        kotlin.jvm.internal.o.h(elements, "elements");
        List listD0 = R4.n.d0(elements);
        if (listD0.isEmpty()) {
            return;
        }
        collection.removeAll(listD0);
    }

    public static void T(Collection collection, Object[] elements) {
        kotlin.jvm.internal.o.h(collection, "<this>");
        kotlin.jvm.internal.o.h(elements, "elements");
        if (elements.length == 0) {
            return;
        }
        collection.removeAll(AbstractC3250p.r(elements));
    }

    public static Object U(List list) {
        kotlin.jvm.internal.o.h(list, "<this>");
        if (list.isEmpty()) {
            throw new NoSuchElementException("List is empty.");
        }
        return list.remove(AbstractC3252r.A(list));
    }

    public static Object V(AbstractList abstractList) {
        if (abstractList.isEmpty()) {
            return null;
        }
        return abstractList.remove(AbstractC3252r.A(abstractList));
    }
}
