package h.x.d;

/* JADX INFO: compiled from: PrimitiveSpreadBuilders.kt */
/* JADX INFO: loaded from: classes.dex */
public abstract class q<T> {
    private final int a;
    private int b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final T[] f994c;

    public q(int i2) {
        this.a = i2;
        this.f994c = (T[]) new Object[i2];
    }

    public final void a(T t) {
        k.d(t, "spreadArgument");
        T[] tArr = this.f994c;
        int i2 = this.b;
        this.b = i2 + 1;
        tArr[i2] = t;
    }

    protected final int b() {
        return this.b;
    }

    protected abstract int c(T t);

    protected final void d(int i2) {
        this.b = i2;
    }

    protected final int e() {
        int i2 = this.a - 1;
        int iC = 0;
        if (i2 >= 0) {
            int i3 = 0;
            while (true) {
                T t = this.f994c[i3];
                iC += t != null ? c(t) : 1;
                if (i3 == i2) {
                    break;
                }
                i3++;
            }
        }
        return iC;
    }

    protected final T f(T t, T t2) {
        int i2;
        k.d(t, "values");
        k.d(t2, "result");
        int i3 = this.a - 1;
        int i4 = 0;
        if (i3 >= 0) {
            int i5 = 0;
            int i6 = 0;
            i2 = 0;
            while (true) {
                T t3 = this.f994c[i5];
                if (t3 != null) {
                    if (i6 < i5) {
                        int i7 = i5 - i6;
                        System.arraycopy(t, i6, t2, i2, i7);
                        i2 += i7;
                    }
                    int iC = c(t3);
                    System.arraycopy(t3, 0, t2, i2, iC);
                    i2 += iC;
                    i6 = i5 + 1;
                }
                if (i5 == i3) {
                    break;
                }
                i5++;
            }
            i4 = i6;
        } else {
            i2 = 0;
        }
        int i8 = this.a;
        if (i4 < i8) {
            System.arraycopy(t, i4, t2, i2, i8 - i4);
        }
        return t2;
    }
}
