package h.s;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.NoSuchElementException;

/* JADX INFO: Access modifiers changed from: package-private */
/* JADX INFO: compiled from: _Arrays.kt */
/* JADX INFO: loaded from: classes.dex */
public class h extends g {
    public static <T> List<T> A(T[] tArr) {
        h.x.d.k.d(tArr, "<this>");
        int length = tArr.length;
        return length != 0 ? length != 1 ? B(tArr) : l.b(tArr[0]) : m.f();
    }

    public static <T> List<T> B(T[] tArr) {
        h.x.d.k.d(tArr, "<this>");
        return new ArrayList(m.c(tArr));
    }

    public static boolean o(char[] cArr, char c2) {
        h.x.d.k.d(cArr, "<this>");
        return u(cArr, c2) >= 0;
    }

    public static final <T> boolean p(T[] tArr, T t) {
        h.x.d.k.d(tArr, "<this>");
        return v(tArr, t) >= 0;
    }

    public static final <T> List<T> q(T[] tArr) {
        h.x.d.k.d(tArr, "<this>");
        ArrayList arrayList = new ArrayList();
        r(tArr, arrayList);
        return arrayList;
    }

    public static final <C extends Collection<? super T>, T> C r(T[] tArr, C c2) {
        h.x.d.k.d(tArr, "<this>");
        h.x.d.k.d(c2, "destination");
        for (T t : tArr) {
            if (t != null) {
                c2.add(t);
            }
        }
        return c2;
    }

    public static <T> h.z.h s(T[] tArr) {
        h.x.d.k.d(tArr, "<this>");
        return new h.z.h(0, t(tArr));
    }

    public static <T> int t(T[] tArr) {
        h.x.d.k.d(tArr, "<this>");
        return tArr.length - 1;
    }

    public static final int u(char[] cArr, char c2) {
        h.x.d.k.d(cArr, "<this>");
        int length = cArr.length;
        for (int i2 = 0; i2 < length; i2++) {
            if (c2 == cArr[i2]) {
                return i2;
            }
        }
        return -1;
    }

    public static final <T> int v(T[] tArr, T t) {
        h.x.d.k.d(tArr, "<this>");
        int i2 = 0;
        if (t == null) {
            int length = tArr.length;
            while (i2 < length) {
                if (tArr[i2] == null) {
                    return i2;
                }
                i2++;
            }
            return -1;
        }
        int length2 = tArr.length;
        while (i2 < length2) {
            if (h.x.d.k.a(t, tArr[i2])) {
                return i2;
            }
            i2++;
        }
        return -1;
    }

    public static char w(char[] cArr) {
        h.x.d.k.d(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 <T> T x(T[] tArr) {
        h.x.d.k.d(tArr, "<this>");
        if (tArr.length == 1) {
            return tArr[0];
        }
        return null;
    }

    public static final <T> T[] y(T[] tArr, Comparator<? super T> comparator) {
        h.x.d.k.d(tArr, "<this>");
        h.x.d.k.d(comparator, "comparator");
        if (tArr.length == 0) {
            return tArr;
        }
        T[] tArr2 = (T[]) Arrays.copyOf(tArr, tArr.length);
        h.x.d.k.c(tArr2, "copyOf(this, size)");
        g.n(tArr2, comparator);
        return tArr2;
    }

    public static <T> List<T> z(T[] tArr, Comparator<? super T> comparator) {
        h.x.d.k.d(tArr, "<this>");
        h.x.d.k.d(comparator, "comparator");
        return g.b(y(tArr, comparator));
    }
}
