package com.google.android.gms.internal.measurement;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.RandomAccess;

/* JADX INFO: loaded from: classes.dex */
public abstract class M1 {
    protected int zza;

    public static void b(Iterable iterable, List list) {
        Charset charset = AbstractC0644h2.f9868a;
        iterable.getClass();
        if (iterable instanceof InterfaceC0718w2) {
            list.addAll((Collection) iterable);
            return;
        }
        if (iterable instanceof Collection) {
            int size = ((Collection) iterable).size();
            if (list instanceof ArrayList) {
                ((ArrayList) list).ensureCapacity(list.size() + size);
            } else if (list instanceof C0728y2) {
                C0728y2 c0728y2 = (C0728y2) list;
                int i = ((C0728y2) list).f10081s + size;
                int length = c0728y2.f10080r.length;
                if (i > length) {
                    if (length != 0) {
                        while (length < i) {
                            length = Math.max(((length * 3) / 2) + 1, 10);
                        }
                        c0728y2.f10080r = Arrays.copyOf(c0728y2.f10080r, length);
                    } else {
                        c0728y2.f10080r = new Object[Math.max(i, 10)];
                    }
                }
            }
        }
        int size2 = list.size();
        if (!(iterable instanceof List) || !(iterable instanceof RandomAccess)) {
            for (Object obj : iterable) {
                if (obj == null) {
                    Z1.c(size2, list);
                    throw null;
                }
                list.add(obj);
            }
            return;
        }
        List list2 = (List) iterable;
        int size3 = list2.size();
        for (int i5 = 0; i5 < size3; i5++) {
            Object obj2 = list2.get(i5);
            if (obj2 == null) {
                Z1.c(size2, list);
                throw null;
            }
            list.add(obj2);
        }
    }

    public abstract int a(A2 a22);

    public final byte[] c() {
        try {
            AbstractC0609a2 abstractC0609a2 = (AbstractC0609a2) this;
            int iD = abstractC0609a2.d();
            byte[] bArr = new byte[iD];
            T1 t12 = new T1(iD, bArr);
            A2 a2A = C0723x2.f10064c.a(abstractC0609a2.getClass());
            C0674n2 c0674n2 = t12.f9679v;
            if (c0674n2 == null) {
                c0674n2 = new C0674n2(t12);
            }
            a2A.i(abstractC0609a2, c0674n2);
            if (iD - t12.f9682y == 0) {
                return bArr;
            }
            throw new IllegalStateException("Did not write as much data as expected.");
        } catch (IOException e8) {
            throw new RuntimeException(I1.a.p("Serializing ", getClass().getName(), " to a byte array threw an IOException (should never happen)."), e8);
        }
    }
}
