package com.google.common.collect;

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

/* JADX INFO: loaded from: classes2.dex */
public abstract class k0 extends l0 {

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

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

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

    public k0(int i10) {
        z0.d(i10, "initialCapacity");
        this.f23687a = new Object[i10];
        this.f23688b = 0;
    }

    public final void c(Object obj) {
        obj.getClass();
        h(1);
        Object[] objArr = this.f23687a;
        int i10 = this.f23688b;
        this.f23688b = i10 + 1;
        objArr[i10] = obj;
    }

    public final void d(Object... objArr) {
        int length = objArr.length;
        z0.b(length, objArr);
        h(length);
        System.arraycopy(objArr, 0, this.f23687a, this.f23688b, length);
        this.f23688b += length;
    }

    public void e(Object obj) {
        c(obj);
    }

    public final k0 f(List list) {
        if (list instanceof Collection) {
            List list2 = list;
            h(list2.size());
            if (list2 instanceof ImmutableCollection) {
                this.f23688b = ((ImmutableCollection) list2).f(this.f23688b, this.f23687a);
                return this;
            }
        }
        Iterator it = list.iterator();
        while (it.hasNext()) {
            a(it.next());
        }
        return this;
    }

    public void g(ImmutableList immutableList) {
        f(immutableList);
    }

    public final void h(int i10) {
        Object[] objArr = this.f23687a;
        int iB = l0.b(objArr.length, this.f23688b + i10);
        if (iB > objArr.length || this.f23689c) {
            this.f23687a = Arrays.copyOf(this.f23687a, iB);
            this.f23689c = false;
        }
    }
}
