package kotlin.collections;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import kotlin.Pair;

/* JADX INFO: loaded from: classes.dex */
public abstract class q extends ua.b {
    public static List O(Object[] objArr) {
        nb.g.i(objArr, "<this>");
        List listAsList = Arrays.asList(objArr);
        nb.g.h(listAsList, "asList(this)");
        return listAsList;
    }

    public static void P(int i10, int i11, int[] iArr, int[] iArr2, int i12) {
        nb.g.i(iArr, "<this>");
        nb.g.i(iArr2, "destination");
        System.arraycopy(iArr, i11, iArr2, i10, i12 - i11);
    }

    public static void Q(byte[] bArr, int i10, int i11, byte[] bArr2, int i12) {
        nb.g.i(bArr, "<this>");
        nb.g.i(bArr2, "destination");
        System.arraycopy(bArr, i11, bArr2, i10, i12 - i11);
    }

    public static void R(Object[] objArr, int i10, Object[] objArr2, int i11, int i12) {
        nb.g.i(objArr, "<this>");
        nb.g.i(objArr2, "destination");
        System.arraycopy(objArr, i11, objArr2, i10, i12 - i11);
    }

    public static /* synthetic */ void S(Object[] objArr, Object[] objArr2, int i10, int i11, int i12) {
        if ((i12 & 4) != 0) {
            i10 = 0;
        }
        if ((i12 & 8) != 0) {
            i11 = objArr.length;
        }
        R(objArr, 0, objArr2, i10, i11);
    }

    public static byte[] T(int i10, int i11, byte[] bArr) {
        nb.g.i(bArr, "<this>");
        ua.b.o(i11, bArr.length);
        byte[] bArrCopyOfRange = Arrays.copyOfRange(bArr, i10, i11);
        nb.g.h(bArrCopyOfRange, "copyOfRange(this, fromIndex, toIndex)");
        return bArrCopyOfRange;
    }

    public static Object[] U(Object[] objArr, int i10, int i11) {
        nb.g.i(objArr, "<this>");
        ua.b.o(i11, objArr.length);
        Object[] objArrCopyOfRange = Arrays.copyOfRange(objArr, i10, i11);
        nb.g.h(objArrCopyOfRange, "copyOfRange(this, fromIndex, toIndex)");
        return objArrCopyOfRange;
    }

    public static Map V() {
        EmptyMap emptyMap = EmptyMap.f29204a;
        nb.g.g(emptyMap, "null cannot be cast to non-null type kotlin.collections.Map<K of kotlin.collections.MapsKt__MapsKt.emptyMap, V of kotlin.collections.MapsKt__MapsKt.emptyMap>");
        return emptyMap;
    }

    public static ArrayList W(Object[] objArr) {
        ArrayList arrayList = new ArrayList();
        for (Object obj : objArr) {
            if (obj != null) {
                arrayList.add(obj);
            }
        }
        return arrayList;
    }

    public static Object X(Object[] objArr) {
        nb.g.i(objArr, "<this>");
        if (objArr.length != 0) {
            return objArr[0];
        }
        throw new NoSuchElementException("Array is empty.");
    }

    public static Object Y(Object obj, Map map) {
        nb.g.i(map, "<this>");
        if (map instanceof p) {
            return ((p) map).c();
        }
        Object obj2 = map.get(obj);
        if (obj2 != null || map.containsKey(obj)) {
            return obj2;
        }
        throw new NoSuchElementException("Key " + obj + " is missing in the map.");
    }

    public static String Z(Object[] objArr) {
        StringBuilder sb = new StringBuilder();
        sb.append((CharSequence) "");
        int i10 = 0;
        for (Object obj : objArr) {
            i10++;
            if (i10 > 1) {
                sb.append((CharSequence) ", ");
            }
            nb.g.b(sb, obj, null);
        }
        sb.append((CharSequence) "");
        String string = sb.toString();
        nb.g.h(string, "joinTo(StringBuilder(), …ed, transform).toString()");
        return string;
    }

    public static final void a0(LinkedHashMap linkedHashMap, Pair[] pairArr) {
        for (Pair pair : pairArr) {
            linkedHashMap.put(pair.getFirst(), pair.getSecond());
        }
    }

    public static char b0(char[] cArr) {
        nb.g.i(cArr, "<this>");
        int length = cArr.length;
        if (length == 0) {
            throw new NoSuchElementException("Array is empty.");
        }
        if (length == 1) {
            return cArr[0];
        }
        throw new IllegalArgumentException("Array has more than one element.");
    }

    public static List c0(Object[] objArr) {
        nb.g.i(objArr, "<this>");
        int length = objArr.length;
        return length != 0 ? length != 1 ? new ArrayList(new g(objArr, false)) : hb.a.l0(objArr[0]) : EmptyList.f29203a;
    }

    public static Map d0(ArrayList arrayList) {
        int size = arrayList.size();
        if (size == 0) {
            return V();
        }
        if (size != 1) {
            LinkedHashMap linkedHashMap = new LinkedHashMap(ua.b.D(arrayList.size()));
            f0(arrayList, linkedHashMap);
            return linkedHashMap;
        }
        Pair pair = (Pair) arrayList.get(0);
        nb.g.i(pair, "pair");
        Map mapSingletonMap = Collections.singletonMap(pair.c(), pair.d());
        nb.g.h(mapSingletonMap, "singletonMap(pair.first, pair.second)");
        return mapSingletonMap;
    }

    public static Map e0(Map map) {
        nb.g.i(map, "<this>");
        int size = map.size();
        return size != 0 ? size != 1 ? g0(map) : ua.b.L(map) : V();
    }

    public static final void f0(ArrayList arrayList, LinkedHashMap linkedHashMap) {
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            Pair pair = (Pair) it.next();
            linkedHashMap.put(pair.getFirst(), pair.getSecond());
        }
    }

    public static LinkedHashMap g0(Map map) {
        nb.g.i(map, "<this>");
        return new LinkedHashMap(map);
    }
}
