package kotlinx.coroutines.o2;

/* JADX INFO: compiled from: ArrayQueue.kt */
/* JADX INFO: loaded from: classes.dex */
public class a<T> {
    private Object[] a = new Object[16];
    private int b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private int f1103c;

    private final void b() {
        Object[] objArr = this.a;
        int length = objArr.length;
        Object[] objArr2 = new Object[length << 1];
        h.s.d.f(objArr, objArr2, 0, this.b, 0, 10, null);
        Object[] objArr3 = this.a;
        int length2 = objArr3.length;
        int i2 = this.b;
        h.s.d.f(objArr3, objArr2, length2 - i2, 0, i2, 4, null);
        this.a = objArr2;
        this.b = 0;
        this.f1103c = length;
    }

    public final void a(T t) {
        Object[] objArr = this.a;
        int i2 = this.f1103c;
        objArr[i2] = t;
        int length = (objArr.length - 1) & (i2 + 1);
        this.f1103c = length;
        if (length == this.b) {
            b();
        }
    }

    public final boolean c() {
        return this.b == this.f1103c;
    }

    public final T d() {
        int i2 = this.b;
        if (i2 == this.f1103c) {
            return null;
        }
        Object[] objArr = this.a;
        T t = (T) objArr[i2];
        objArr[i2] = null;
        this.b = (i2 + 1) & (objArr.length - 1);
        if (t != null) {
            return t;
        }
        throw new NullPointerException("null cannot be cast to non-null type T of kotlinx.coroutines.internal.ArrayQueue");
    }
}
