package com.google.common.collect;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.RandomAccess;
import java.util.Set;
import java.util.SortedSet;
import tv.danmaku.ijk.media.player.IjkMediaMeta;
import xyz.stream.download.config.InnerConstant;

/* JADX INFO: loaded from: classes2.dex */
public abstract class z0 {
    public static String A(Map map) {
        int size = map.size();
        d(size, InnerConstant.Db.size);
        StringBuilder sb = new StringBuilder((int) Math.min(((long) size) * 8, IjkMediaMeta.AV_CH_STEREO_RIGHT));
        sb.append('{');
        boolean z10 = true;
        for (Map.Entry entry : map.entrySet()) {
            if (!z10) {
                sb.append(", ");
            }
            sb.append(entry.getKey());
            sb.append('=');
            sb.append(entry.getValue());
            z10 = false;
        }
        sb.append('}');
        return sb.toString();
    }

    public static AbstractList B(List list, com.google.common.base.e eVar) {
        return list instanceof RandomAccess ? new Lists$TransformingRandomAccessList(list, eVar) : new Lists$TransformingSequentialList(list, eVar);
    }

    public static g1 C() {
        NaturalOrdering naturalOrdering = NaturalOrdering.f23613a;
        naturalOrdering.getClass();
        return new g1(naturalOrdering);
    }

    public static void D(e1 e1Var, ObjectOutputStream objectOutputStream) throws IOException {
        objectOutputStream.writeInt(e1Var.b().size());
        for (Map.Entry entry : e1Var.b().entrySet()) {
            objectOutputStream.writeObject(entry.getKey());
            objectOutputStream.writeInt(((Collection) entry.getValue()).size());
            Iterator it = ((Collection) entry.getValue()).iterator();
            while (it.hasNext()) {
                objectOutputStream.writeObject(it.next());
            }
        }
    }

    public static int a(int i10) {
        if (i10 < 3) {
            d(i10, "expectedSize");
            return i10 + 1;
        }
        if (i10 < 1073741824) {
            return (int) Math.ceil(((double) i10) / 0.75d);
        }
        return Integer.MAX_VALUE;
    }

    public static void b(int i10, Object[] objArr) {
        for (int i11 = 0; i11 < i10; i11++) {
            if (objArr[i11] == null) {
                throw new NullPointerException(com.google.android.gms.measurement.internal.u1.g("at index ", i11));
            }
        }
    }

    public static void c(Object obj, Object obj2) {
        if (obj == null) {
            throw new NullPointerException("null key in entry: null=" + obj2);
        }
        if (obj2 != null) {
            return;
        }
        throw new NullPointerException("null value in entry: " + obj + "=null");
    }

    public static void d(int i10, String str) {
        if (i10 >= 0) {
            return;
        }
        throw new IllegalArgumentException(str + " cannot be negative but was: " + i10);
    }

    public static void e(Iterator it) {
        it.getClass();
        while (it.hasNext()) {
            it.next();
            it.remove();
        }
    }

    public static int f(int i10) {
        int iMax = Math.max(i10, 2);
        int iHighestOneBit = Integer.highestOneBit(iMax);
        if (iMax <= ((int) (1.0d * ((double) iHighestOneBit)))) {
            return iHighestOneBit;
        }
        int i11 = iHighestOneBit << 1;
        if (i11 > 0) {
            return i11;
        }
        return 1073741824;
    }

    public static boolean g(c1 c1Var, Object obj) {
        Iterator it = c1Var.f23715a;
        if (obj == null) {
            while (it.hasNext()) {
                if (c1Var.next() == null) {
                    return true;
                }
            }
            return false;
        }
        while (it.hasNext()) {
            if (obj.equals(c1Var.next())) {
                return true;
            }
        }
        return false;
    }

    public static Object i(int i10) {
        if (i10 < 2 || i10 > 1073741824 || Integer.highestOneBit(i10) != i10) {
            throw new IllegalArgumentException(com.google.android.gms.measurement.internal.u1.g("must be power of 2 between 2^1 and 2^30: ", i10));
        }
        return i10 <= 256 ? new byte[i10] : i10 <= 65536 ? new short[i10] : new int[i10];
    }

    public static boolean j(Set set, Object obj) {
        if (set == obj) {
            return true;
        }
        if (obj instanceof Set) {
            Set set2 = (Set) obj;
            try {
                if (set.size() == set2.size()) {
                    if (set.containsAll(set2)) {
                        return true;
                    }
                }
                return false;
            } catch (ClassCastException | NullPointerException unused) {
            }
        }
        return false;
    }

    public static o1 k(Set set, androidx.media3.datasource.e eVar) {
        if (!(set instanceof SortedSet)) {
            if (!(set instanceof o1)) {
                set.getClass();
                return new o1(set, eVar);
            }
            o1 o1Var = (o1) set;
            return new o1((Set) o1Var.f23706a, com.google.common.base.h.a(o1Var.f23707b, eVar));
        }
        Set set2 = (SortedSet) set;
        if (!(set2 instanceof o1)) {
            set2.getClass();
            return new p1(set2, eVar);
        }
        o1 o1Var2 = (o1) set2;
        return new p1((SortedSet) o1Var2.f23706a, com.google.common.base.h.a(o1Var2.f23707b, eVar));
    }

    public static xyz.stream.utils.f0 l(Class cls, String str) {
        try {
            return new xyz.stream.utils.f0(cls.getDeclaredField(str), 0);
        } catch (NoSuchFieldException e10) {
            throw new AssertionError(e10);
        }
    }

    public static Object m(Collection collection, String str) {
        Iterator it = collection.iterator();
        return it.hasNext() ? it.next() : str;
    }

    public static Object n(Iterable iterable) {
        Object next;
        if (iterable instanceof List) {
            List list = (List) iterable;
            if (list.isEmpty()) {
                throw new NoSuchElementException();
            }
            return defpackage.e.c(list, 1);
        }
        Iterator it = iterable.iterator();
        do {
            next = it.next();
        } while (it.hasNext());
        return next;
    }

    public static Object o(List list) {
        Object next = null;
        if (list instanceof Collection) {
            if (list.isEmpty()) {
                return null;
            }
            if (list instanceof List) {
                return defpackage.e.c(list, 1);
            }
        }
        Iterator it = list.iterator();
        if (it.hasNext()) {
            do {
                next = it.next();
            } while (it.hasNext());
        }
        return next;
    }

    public static Object p(Iterable iterable) {
        Iterator it = iterable.iterator();
        Object next = it.next();
        if (!it.hasNext()) {
            return next;
        }
        StringBuilder sb = new StringBuilder("expected one element but was: <");
        sb.append(next);
        for (int i10 = 0; i10 < 4 && it.hasNext(); i10++) {
            sb.append(", ");
            sb.append(it.next());
        }
        if (it.hasNext()) {
            sb.append(", ...");
        }
        sb.append('>');
        throw new IllegalArgumentException(sb.toString());
    }

    public static int q(Set set) {
        Iterator it = set.iterator();
        int i10 = 0;
        while (it.hasNext()) {
            Object next = it.next();
            i10 = ~(~(i10 + (next != null ? next.hashCode() : 0)));
        }
        return i10;
    }

    public static n1 r(ImmutableSet immutableSet, ImmutableSet immutableSet2) {
        if (immutableSet == null) {
            throw new NullPointerException("set1");
        }
        if (immutableSet2 != null) {
            return new n1(immutableSet, immutableSet2, 1);
        }
        throw new NullPointerException("set2");
    }

    public static int s(int i10, int i11, int i12) {
        return (i10 & (~i12)) | (i11 & i12);
    }

    public static ArrayList t(Object... objArr) {
        int length = objArr.length;
        d(length, "arraySize");
        ArrayList arrayList = new ArrayList(com.google.common.primitives.a.h(((long) length) + 5 + ((long) (length / 10))));
        Collections.addAll(arrayList, objArr);
        return arrayList;
    }

    public static int u(Object obj, Object obj2, int i10, Object obj3, int[] iArr, Object[] objArr, Object[] objArr2) {
        int i11;
        int i12;
        int iX = x(obj);
        int i13 = iX & i10;
        int iY = y(i13, obj3);
        if (iY == 0) {
            return -1;
        }
        int i14 = ~i10;
        int i15 = iX & i14;
        int i16 = -1;
        while (true) {
            i11 = iY - 1;
            i12 = iArr[i11];
            if ((i12 & i14) == i15 && com.google.common.base.h.j(obj, objArr[i11]) && (objArr2 == null || com.google.common.base.h.j(obj2, objArr2[i11]))) {
                break;
            }
            int i17 = i12 & i10;
            if (i17 == 0) {
                return -1;
            }
            i16 = i11;
            iY = i17;
        }
        int i18 = i12 & i10;
        if (i16 == -1) {
            z(i13, i18, obj3);
        } else {
            iArr[i16] = s(iArr[i16], i18, i10);
        }
        return i11;
    }

    public static void v(List list, com.google.common.base.g gVar, int i10, int i11) {
        for (int size = list.size() - 1; size > i11; size--) {
            if (gVar.apply(list.get(size))) {
                list.remove(size);
            }
        }
        for (int i12 = i11 - 1; i12 >= i10; i12--) {
            list.remove(i12);
        }
    }

    public static int w(int i10) {
        return (int) (((long) Integer.rotateLeft((int) (((long) i10) * (-862048943)), 15)) * 461845907);
    }

    public static int x(Object obj) {
        return w(obj == null ? 0 : obj.hashCode());
    }

    public static int y(int i10, Object obj) {
        return obj instanceof byte[] ? ((byte[]) obj)[i10] & 255 : obj instanceof short[] ? ((short[]) obj)[i10] & 65535 : ((int[]) obj)[i10];
    }

    public static void z(int i10, int i11, Object obj) {
        if (obj instanceof byte[]) {
            ((byte[]) obj)[i10] = (byte) i11;
        } else if (obj instanceof short[]) {
            ((short[]) obj)[i10] = (short) i11;
        } else {
            ((int[]) obj)[i10] = i11;
        }
    }

    public abstract Map h();
}
