package j.k0;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;

/* JADX INFO: Access modifiers changed from: package-private */
/* JADX INFO: compiled from: _Arrays.kt */
/* JADX INFO: loaded from: classes.dex */
public class j extends i {

    /* JADX INFO: Add missing generic type declarations: [T] */
    /* JADX INFO: compiled from: _Arrays.kt */
    static final class a<T> extends j.p0.d.s implements j.p0.c.a<Iterator<? extends T>> {
        final /* synthetic */ T[] b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(T[] tArr) {
            super(0);
            this.b = tArr;
        }

        @Override // j.p0.c.a
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Iterator<T> invoke() {
            return j.p0.d.b.a(this.b);
        }
    }

    public static <T> int A(T[] tArr, T t) {
        j.p0.d.r.f(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 (j.p0.d.r.a(t, tArr[i2])) {
                return i2;
            }
            i2++;
        }
        return -1;
    }

    public static final int B(short[] sArr, short s) {
        j.p0.d.r.f(sArr, "<this>");
        int length = sArr.length;
        for (int i2 = 0; i2 < length; i2++) {
            if (s == sArr[i2]) {
                return i2;
            }
        }
        return -1;
    }

    public static char C(char[] cArr) {
        j.p0.d.r.f(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 D(T[] tArr) {
        j.p0.d.r.f(tArr, "<this>");
        if (tArr.length == 1) {
            return tArr[0];
        }
        return null;
    }

    public static final <T, C extends Collection<? super T>> C E(T[] tArr, C c) {
        j.p0.d.r.f(tArr, "<this>");
        j.p0.d.r.f(c, "destination");
        for (T t : tArr) {
            c.add(t);
        }
        return c;
    }

    public static <T> List<T> F(T[] tArr) {
        j.p0.d.r.f(tArr, "<this>");
        int length = tArr.length;
        return length != 0 ? length != 1 ? G(tArr) : n.b(tArr[0]) : o.g();
    }

    public static <T> List<T> G(T[] tArr) {
        j.p0.d.r.f(tArr, "<this>");
        return new ArrayList(o.d(tArr));
    }

    public static final <T> Set<T> H(T[] tArr) {
        j.p0.d.r.f(tArr, "<this>");
        int length = tArr.length;
        if (length == 0) {
            return p0.b();
        }
        if (length == 1) {
            return o0.a(tArr[0]);
        }
        LinkedHashSet linkedHashSet = new LinkedHashSet(j0.b(tArr.length));
        E(tArr, linkedHashSet);
        return linkedHashSet;
    }

    public static <T> Iterable<b0<T>> I(T[] tArr) {
        j.p0.d.r.f(tArr, "<this>");
        return new c0(new a(tArr));
    }

    public static boolean n(byte[] bArr, byte b) {
        j.p0.d.r.f(bArr, "<this>");
        return x(bArr, b) >= 0;
    }

    public static boolean o(int[] iArr, int i2) {
        j.p0.d.r.f(iArr, "<this>");
        return y(iArr, i2) >= 0;
    }

    public static boolean p(long[] jArr, long j2) {
        j.p0.d.r.f(jArr, "<this>");
        return z(jArr, j2) >= 0;
    }

    public static final <T> boolean q(T[] tArr, T t) {
        j.p0.d.r.f(tArr, "<this>");
        return A(tArr, t) >= 0;
    }

    public static boolean r(short[] sArr, short s) {
        j.p0.d.r.f(sArr, "<this>");
        return B(sArr, s) >= 0;
    }

    public static final <T> List<T> s(T[] tArr) {
        j.p0.d.r.f(tArr, "<this>");
        ArrayList arrayList = new ArrayList();
        t(tArr, arrayList);
        return arrayList;
    }

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

    public static <T> T u(T[] tArr) {
        j.p0.d.r.f(tArr, "<this>");
        if (tArr.length == 0) {
            throw new NoSuchElementException("Array is empty.");
        }
        return tArr[0];
    }

    public static int v(long[] jArr) {
        j.p0.d.r.f(jArr, "<this>");
        return jArr.length - 1;
    }

    public static <T> int w(T[] tArr) {
        j.p0.d.r.f(tArr, "<this>");
        return tArr.length - 1;
    }

    public static final int x(byte[] bArr, byte b) {
        j.p0.d.r.f(bArr, "<this>");
        int length = bArr.length;
        for (int i2 = 0; i2 < length; i2++) {
            if (b == bArr[i2]) {
                return i2;
            }
        }
        return -1;
    }

    public static final int y(int[] iArr, int i2) {
        j.p0.d.r.f(iArr, "<this>");
        int length = iArr.length;
        for (int i3 = 0; i3 < length; i3++) {
            if (i2 == iArr[i3]) {
                return i3;
            }
        }
        return -1;
    }

    public static final int z(long[] jArr, long j2) {
        j.p0.d.r.f(jArr, "<this>");
        int length = jArr.length;
        for (int i2 = 0; i2 < length; i2++) {
            if (j2 == jArr[i2]) {
                return i2;
            }
        }
        return -1;
    }
}
