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

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

/* JADX INFO: loaded from: classes2.dex */
public abstract class zr1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public Object[] f19374a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f19375b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f19376c;

    public zr1(int i10) {
        ih1.c0(i10, "initialCapacity");
        this.f19374a = new Object[i10];
        this.f19375b = 0;
    }

    public static int d(int i10, int i11) {
        if (i11 < 0) {
            throw new IllegalArgumentException("cannot store more than Integer.MAX_VALUE elements");
        }
        if (i11 <= i10) {
            return i10;
        }
        int i12 = i10 + (i10 >> 1) + 1;
        if (i12 < i11) {
            int iHighestOneBit = Integer.highestOneBit(i11 - 1);
            i12 = iHighestOneBit + iHighestOneBit;
        }
        if (i12 < 0) {
            return Integer.MAX_VALUE;
        }
        return i12;
    }

    public final void a(Object obj) {
        obj.getClass();
        e(1);
        Object[] objArr = this.f19374a;
        int i10 = this.f19375b;
        this.f19375b = i10 + 1;
        objArr[i10] = obj;
    }

    public final void b(Iterable iterable) {
        if (iterable instanceof Collection) {
            Collection collection = (Collection) iterable;
            e(collection.size());
            if (collection instanceof zzgub) {
                this.f19375b = ((zzgub) collection).k(this.f19375b, this.f19374a);
                return;
            }
        }
        Iterator it = iterable.iterator();
        while (it.hasNext()) {
            c(it.next());
        }
    }

    public abstract zr1 c(Object obj);

    public final void e(int i10) {
        int length = this.f19374a.length;
        int iD = d(length, this.f19375b + i10);
        if (iD > length || this.f19376c) {
            this.f19374a = Arrays.copyOf(this.f19374a, iD);
            this.f19376c = false;
        }
    }

    public void f(Object obj) {
        a(obj);
    }
}
