package o;

import java.util.Arrays;
import java.util.Iterator;
import java.util.RandomAccess;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class V20 extends Q implements RandomAccess {
    public final Object[] l;
    public final int m;
    public int n;

    /* renamed from: o, reason: collision with root package name */
    public int f367o;

    public V20(int i, Object[] objArr) {
        this.l = objArr;
        if (i < 0) {
            throw new IllegalArgumentException(AbstractC0126Ew.j(i, "ring buffer filled size should not be negative but it is ").toString());
        }
        if (i <= objArr.length) {
            this.m = objArr.length;
            this.f367o = i;
        } else {
            StringBuilder sbO = AbstractC0126Ew.o(i, "ring buffer filled size: ", " cannot be larger than the buffer size: ");
            sbO.append(objArr.length);
            throw new IllegalArgumentException(sbO.toString().toString());
        }
    }

    @Override // o.AbstractC2864x
    public final int a() {
        return this.f367o;
    }

    public final void b() {
        if (50 > this.f367o) {
            throw new IllegalArgumentException(("n shouldn't be greater than the buffer size: n = 50, size = " + this.f367o).toString());
        }
        int i = this.n;
        int i2 = this.m;
        int i3 = (i + 50) % i2;
        Object[] objArr = this.l;
        if (i > i3) {
            Arrays.fill(objArr, i, i2, (Object) null);
            Arrays.fill(objArr, 0, i3, (Object) null);
        } else {
            Arrays.fill(objArr, i, i3, (Object) null);
        }
        this.n = i3;
        this.f367o -= 50;
    }

    @Override // java.util.List
    public final Object get(int i) {
        int iA = a();
        if (i < 0 || i >= iA) {
            throw new IndexOutOfBoundsException(AbstractC0126Ew.i(i, iA, "index: ", ", size: "));
        }
        return this.l[(this.n + i) % this.m];
    }

    @Override // o.Q, java.util.Collection, java.lang.Iterable, java.util.List
    public final Iterator iterator() {
        return new U20(this);
    }

    @Override // o.AbstractC2864x, java.util.Collection, java.util.List
    public final Object[] toArray() {
        return toArray(new Object[a()]);
    }

    @Override // o.AbstractC2864x, java.util.Collection, java.util.List
    public final Object[] toArray(Object[] objArr) {
        Object[] objArr2;
        int length = objArr.length;
        int i = this.f367o;
        if (length < i) {
            objArr = Arrays.copyOf(objArr, i);
        }
        int i2 = this.f367o;
        int i3 = this.n;
        int i4 = 0;
        int i5 = 0;
        while (true) {
            objArr2 = this.l;
            if (i5 >= i2 || i3 >= this.m) {
                break;
            }
            objArr[i5] = objArr2[i3];
            i5++;
            i3++;
        }
        while (i5 < i2) {
            objArr[i5] = objArr2[i4];
            i5++;
            i4++;
        }
        if (i2 < objArr.length) {
            objArr[i2] = null;
        }
        return objArr;
    }
}
