package g.c0;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;

/* JADX INFO: compiled from: _ArraysJvm.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public class g extends f {
    public static final <K, V> Map<K, V> A(Map<? extends K, ? extends V> map, Map<? extends K, ? extends V> map2) {
        g.h0.c.l.f(map, "<this>");
        g.h0.c.l.f(map2, "map");
        LinkedHashMap linkedHashMap = new LinkedHashMap(map);
        linkedHashMap.putAll(map2);
        return linkedHashMap;
    }

    public static final <K, V> void B(Map<? super K, ? super V> map, g.k<? extends K, ? extends V>[] kVarArr) {
        g.h0.c.l.f(map, "<this>");
        g.h0.c.l.f(kVarArr, "pairs");
        for (g.k<? extends K, ? extends V> kVar : kVarArr) {
            map.put((Object) kVar.f4139b, (Object) kVar.f4140e);
        }
    }

    public static final <T> T C(List<T> list) {
        g.h0.c.l.f(list, "<this>");
        if (list.isEmpty()) {
            throw new NoSuchElementException("List is empty.");
        }
        return list.remove(m(list));
    }

    public static final void D() {
        throw new ArithmeticException("Index overflow has happened.");
    }

    public static final <T, C extends Collection<? super T>> C E(Iterable<? extends T> iterable, C c2) {
        g.h0.c.l.f(iterable, "<this>");
        g.h0.c.l.f(c2, "destination");
        Iterator<? extends T> it = iterable.iterator();
        while (it.hasNext()) {
            c2.add(it.next());
        }
        return c2;
    }

    public static final <T> List<T> F(Iterable<? extends T> iterable) {
        g.h0.c.l.f(iterable, "<this>");
        if (!(iterable instanceof Collection)) {
            return y(J(iterable));
        }
        Collection collection = (Collection) iterable;
        int size = collection.size();
        if (size == 0) {
            return l.f4067b;
        }
        if (size != 1) {
            return K(collection);
        }
        return f.a.y.a.w0(iterable instanceof List ? ((List) iterable).get(0) : iterable.iterator().next());
    }

    public static final <K, V> Map<K, V> G(Iterable<? extends g.k<? extends K, ? extends V>> iterable) {
        g.h0.c.l.f(iterable, "<this>");
        Collection collection = (Collection) iterable;
        int size = collection.size();
        if (size == 0) {
            i();
            return m.f4068b;
        }
        if (size == 1) {
            return f.a.y.a.y0((g.k) ((List) iterable).get(0));
        }
        LinkedHashMap linkedHashMap = new LinkedHashMap(f.a.y.a.x0(collection.size()));
        H(iterable, linkedHashMap);
        return linkedHashMap;
    }

    public static final <K, V, M extends Map<? super K, ? super V>> M H(Iterable<? extends g.k<? extends K, ? extends V>> iterable, M m) {
        g.h0.c.l.f(iterable, "<this>");
        g.h0.c.l.f(m, "destination");
        g.h0.c.l.f(m, "<this>");
        g.h0.c.l.f(iterable, "pairs");
        for (g.k<? extends K, ? extends V> kVar : iterable) {
            m.put(kVar.f4139b, kVar.f4140e);
        }
        return m;
    }

    public static final <K, V> Map<K, V> I(Map<? extends K, ? extends V> map) {
        g.h0.c.l.f(map, "<this>");
        int size = map.size();
        if (size != 0) {
            return size != 1 ? L(map) : f.a.y.a.m1(map);
        }
        i();
        return m.f4068b;
    }

    public static final <T> List<T> J(Iterable<? extends T> iterable) {
        g.h0.c.l.f(iterable, "<this>");
        if (iterable instanceof Collection) {
            return K((Collection) iterable);
        }
        ArrayList arrayList = new ArrayList();
        E(iterable, arrayList);
        return arrayList;
    }

    public static final <T> List<T> K(Collection<? extends T> collection) {
        g.h0.c.l.f(collection, "<this>");
        return new ArrayList(collection);
    }

    public static final <K, V> Map<K, V> L(Map<? extends K, ? extends V> map) {
        g.h0.c.l.f(map, "<this>");
        return new LinkedHashMap(map);
    }

    public static final <T> Set<T> M(Iterable<? extends T> iterable) {
        g.h0.c.l.f(iterable, "<this>");
        if (!(iterable instanceof Collection)) {
            LinkedHashSet linkedHashSet = new LinkedHashSet();
            E(iterable, linkedHashSet);
            g.h0.c.l.f(linkedHashSet, "<this>");
            int size = linkedHashSet.size();
            return size != 0 ? size != 1 ? linkedHashSet : f.a.y.a.R0(linkedHashSet.iterator().next()) : n.f4069b;
        }
        Collection collection = (Collection) iterable;
        int size2 = collection.size();
        if (size2 == 0) {
            return n.f4069b;
        }
        if (size2 == 1) {
            return f.a.y.a.R0(iterable instanceof List ? ((List) iterable).get(0) : iterable.iterator().next());
        }
        LinkedHashSet linkedHashSet2 = new LinkedHashSet(f.a.y.a.x0(collection.size()));
        E(iterable, linkedHashSet2);
        return linkedHashSet2;
    }

    public static final <T> boolean a(Collection<? super T> collection, Iterable<? extends T> iterable) {
        g.h0.c.l.f(collection, "<this>");
        g.h0.c.l.f(iterable, "elements");
        if (iterable instanceof Collection) {
            return collection.addAll((Collection) iterable);
        }
        boolean z = false;
        Iterator<? extends T> it = iterable.iterator();
        while (it.hasNext()) {
            if (collection.add(it.next())) {
                z = true;
            }
        }
        return z;
    }

    public static final <T> ArrayList<T> b(T... tArr) {
        g.h0.c.l.f(tArr, "elements");
        return tArr.length == 0 ? new ArrayList<>() : new ArrayList<>(new d(tArr, true));
    }

    public static final <T> List<T> c(T[] tArr) {
        g.h0.c.l.f(tArr, "<this>");
        List<T> listAsList = Arrays.asList(tArr);
        g.h0.c.l.e(listAsList, "asList(this)");
        return listAsList;
    }

    public static final byte[] d(byte[] bArr, byte[] bArr2, int i2, int i3, int i4) {
        g.h0.c.l.f(bArr, "<this>");
        g.h0.c.l.f(bArr2, "destination");
        System.arraycopy(bArr, i3, bArr2, i2, i4 - i3);
        return bArr2;
    }

    public static final <T> T[] e(T[] tArr, T[] tArr2, int i2, int i3, int i4) {
        g.h0.c.l.f(tArr, "<this>");
        g.h0.c.l.f(tArr2, "destination");
        System.arraycopy(tArr, i3, tArr2, i2, i4 - i3);
        return tArr2;
    }

    public static /* synthetic */ byte[] f(byte[] bArr, byte[] bArr2, int i2, int i3, int i4, int i5) {
        if ((i5 & 2) != 0) {
            i2 = 0;
        }
        if ((i5 & 4) != 0) {
            i3 = 0;
        }
        if ((i5 & 8) != 0) {
            i4 = bArr.length;
        }
        d(bArr, bArr2, i2, i3, i4);
        return bArr2;
    }

    public static /* synthetic */ Object[] g(Object[] objArr, Object[] objArr2, int i2, int i3, int i4, int i5) {
        if ((i5 & 2) != 0) {
            i2 = 0;
        }
        if ((i5 & 4) != 0) {
            i3 = 0;
        }
        if ((i5 & 8) != 0) {
            i4 = objArr.length;
        }
        e(objArr, objArr2, i2, i3, i4);
        return objArr2;
    }

    public static final byte[] h(byte[] bArr, int i2, int i3) {
        g.h0.c.l.f(bArr, "<this>");
        int length = bArr.length;
        if (i3 <= length) {
            byte[] bArrCopyOfRange = Arrays.copyOfRange(bArr, i2, i3);
            g.h0.c.l.e(bArrCopyOfRange, "copyOfRange(this, fromIndex, toIndex)");
            return bArrCopyOfRange;
        }
        throw new IndexOutOfBoundsException("toIndex (" + i3 + ") is greater than size (" + length + ").");
    }

    public static final <K, V> Map<K, V> i() {
        m mVar = m.f4068b;
        g.h0.c.l.d(mVar, "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 mVar;
    }

    public static final <T> void j(T[] tArr, T t, int i2, int i3) {
        g.h0.c.l.f(tArr, "<this>");
        Arrays.fill(tArr, i2, i3, t);
    }

    public static final <T> T k(List<? extends T> list) {
        g.h0.c.l.f(list, "<this>");
        if (list.isEmpty()) {
            throw new NoSuchElementException("List is empty.");
        }
        return list.get(0);
    }

    public static final <T> T l(List<? extends T> list) {
        g.h0.c.l.f(list, "<this>");
        if (list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }

    public static final <T> int m(List<? extends T> list) {
        g.h0.c.l.f(list, "<this>");
        return list.size() - 1;
    }

    public static final <T> T n(List<? extends T> list, int i2) {
        g.h0.c.l.f(list, "<this>");
        if (i2 < 0 || i2 > m(list)) {
            return null;
        }
        return list.get(i2);
    }

    public static final <K, V> V o(Map<K, ? extends V> map, K k2) {
        g.h0.c.l.f(map, "<this>");
        g.h0.c.l.f(map, "<this>");
        if (map instanceof t) {
            return (V) ((t) map).a(k2);
        }
        V v = map.get(k2);
        if (v != null || map.containsKey(k2)) {
            return v;
        }
        throw new NoSuchElementException("Key " + k2 + " is missing in the map.");
    }

    public static final <T, A extends Appendable> A p(Iterable<? extends T> iterable, A a, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i2, CharSequence charSequence4, g.h0.b.l<? super T, ? extends CharSequence> lVar) throws IOException {
        g.h0.c.l.f(iterable, "<this>");
        g.h0.c.l.f(a, "buffer");
        g.h0.c.l.f(charSequence, "separator");
        g.h0.c.l.f(charSequence2, "prefix");
        g.h0.c.l.f(charSequence3, "postfix");
        g.h0.c.l.f(charSequence4, "truncated");
        a.append(charSequence2);
        int i3 = 0;
        for (T t : iterable) {
            i3++;
            if (i3 > 1) {
                a.append(charSequence);
            }
            if (i2 >= 0 && i3 > i2) {
                break;
            }
            f.a.y.a.n(a, t, lVar);
        }
        if (i2 >= 0 && i3 > i2) {
            a.append(charSequence4);
        }
        a.append(charSequence3);
        return a;
    }

    public static /* synthetic */ Appendable q(Iterable iterable, Appendable appendable, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i2, CharSequence charSequence4, g.h0.b.l lVar, int i3) throws IOException {
        int i4 = i3 & 64;
        p(iterable, appendable, (i3 & 2) != 0 ? ", " : charSequence, (i3 & 4) != 0 ? "" : null, (i3 & 8) != 0 ? "" : null, (i3 & 16) != 0 ? -1 : i2, (i3 & 32) != 0 ? "..." : null, null);
        return appendable;
    }

    public static String r(Iterable iterable, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i2, CharSequence charSequence4, g.h0.b.l lVar, int i3) throws IOException {
        if ((i3 & 1) != 0) {
            charSequence = ", ";
        }
        CharSequence charSequence5 = charSequence;
        CharSequence charSequence6 = (i3 & 2) != 0 ? "" : charSequence2;
        CharSequence charSequence7 = (i3 & 4) != 0 ? "" : charSequence3;
        if ((i3 & 8) != 0) {
            i2 = -1;
        }
        int i4 = i2;
        CharSequence charSequence8 = (i3 & 16) != 0 ? "..." : null;
        g.h0.b.l lVar2 = (i3 & 32) != 0 ? null : lVar;
        g.h0.c.l.f(iterable, "<this>");
        g.h0.c.l.f(charSequence5, "separator");
        g.h0.c.l.f(charSequence6, "prefix");
        g.h0.c.l.f(charSequence7, "postfix");
        g.h0.c.l.f(charSequence8, "truncated");
        StringBuilder sb = new StringBuilder();
        p(iterable, sb, charSequence5, charSequence6, charSequence7, i4, charSequence8, lVar2);
        String string = sb.toString();
        g.h0.c.l.e(string, "joinTo(StringBuilder(), …ed, transform).toString()");
        return string;
    }

    public static final <T> T s(Iterable<? extends T> iterable) {
        g.h0.c.l.f(iterable, "<this>");
        if (iterable instanceof List) {
            return (T) t((List) iterable);
        }
        Iterator<? extends T> it = iterable.iterator();
        if (!it.hasNext()) {
            throw new NoSuchElementException("Collection is empty.");
        }
        T next = it.next();
        while (it.hasNext()) {
            next = it.next();
        }
        return next;
    }

    public static final <T> T t(List<? extends T> list) {
        g.h0.c.l.f(list, "<this>");
        if (list.isEmpty()) {
            throw new NoSuchElementException("List is empty.");
        }
        return list.get(m(list));
    }

    public static final <T> List<T> u(T... tArr) {
        g.h0.c.l.f(tArr, "elements");
        return tArr.length > 0 ? c(tArr) : l.f4067b;
    }

    public static final <K, V> Map<K, V> v(g.k<? extends K, ? extends V>... kVarArr) {
        g.h0.c.l.f(kVarArr, "pairs");
        if (kVarArr.length <= 0) {
            i();
            return m.f4068b;
        }
        LinkedHashMap linkedHashMap = new LinkedHashMap(f.a.y.a.x0(kVarArr.length));
        g.h0.c.l.f(kVarArr, "<this>");
        g.h0.c.l.f(linkedHashMap, "destination");
        B(linkedHashMap, kVarArr);
        return linkedHashMap;
    }

    public static final <T> List<T> w(T... tArr) {
        g.h0.c.l.f(tArr, "elements");
        return tArr.length == 0 ? new ArrayList() : new ArrayList(new d(tArr, true));
    }

    public static final <K, V> Map<K, V> x(g.k<? extends K, ? extends V>... kVarArr) {
        g.h0.c.l.f(kVarArr, "pairs");
        LinkedHashMap linkedHashMap = new LinkedHashMap(f.a.y.a.x0(kVarArr.length));
        B(linkedHashMap, kVarArr);
        return linkedHashMap;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static final <T> List<T> y(List<? extends T> list) {
        g.h0.c.l.f(list, "<this>");
        int size = list.size();
        return size != 0 ? size != 1 ? list : f.a.y.a.w0(list.get(0)) : l.f4067b;
    }

    public static final <T> List<T> z(Collection<? extends T> collection, Iterable<? extends T> iterable) {
        g.h0.c.l.f(collection, "<this>");
        g.h0.c.l.f(iterable, "elements");
        if (!(iterable instanceof Collection)) {
            ArrayList arrayList = new ArrayList(collection);
            a(arrayList, iterable);
            return arrayList;
        }
        Collection collection2 = (Collection) iterable;
        ArrayList arrayList2 = new ArrayList(collection2.size() + collection.size());
        arrayList2.addAll(collection);
        arrayList2.addAll(collection2);
        return arrayList2;
    }
}
