package l1;

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 e extends d {
    public static <T> List<T> e(T[] tArr) {
        w1.g.e(tArr, "<this>");
        return (List) f(tArr, new ArrayList());
    }

    public static final <C extends Collection<? super T>, T> C f(T[] tArr, C c3) {
        w1.g.e(tArr, "<this>");
        w1.g.e(c3, "destination");
        for (T t2 : tArr) {
            if (t2 != null) {
                c3.add(t2);
            }
        }
        return c3;
    }

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

    public static final <T> T[] i(T[] tArr, Comparator<? super T> comparator) {
        w1.g.e(tArr, "<this>");
        w1.g.e(comparator, "comparator");
        if (tArr.length == 0) {
            return tArr;
        }
        T[] tArr2 = (T[]) Arrays.copyOf(tArr, tArr.length);
        w1.g.d(tArr2, "copyOf(this, size)");
        d.d(tArr2, comparator);
        return tArr2;
    }

    public static <T> List<T> j(T[] tArr, Comparator<? super T> comparator) {
        w1.g.e(tArr, "<this>");
        w1.g.e(comparator, "comparator");
        return d.a(i(tArr, comparator));
    }
}
