package t8; import java.util.Arrays; import java.util.Iterator; import java.util.RandomAccess; /* loaded from: classes2.dex */ final class g0 extends c implements RandomAccess { /* renamed from: b, reason: collision with root package name */ private final Object[] f14432b; /* renamed from: c, reason: collision with root package name */ private final int f14433c; /* renamed from: d, reason: collision with root package name */ private int f14434d; /* renamed from: e, reason: collision with root package name */ private int f14435e; public static final class a extends b { /* renamed from: c, reason: collision with root package name */ private int f14436c; /* renamed from: d, reason: collision with root package name */ private int f14437d; a() { this.f14436c = g0.this.size(); this.f14437d = g0.this.f14434d; } @Override // t8.b protected void a() { if (this.f14436c == 0) { b(); return; } c(g0.this.f14432b[this.f14437d]); this.f14437d = (this.f14437d + 1) % g0.this.f14433c; this.f14436c--; } } public g0(Object[] objArr, int i10) { d9.j.e(objArr, "buffer"); this.f14432b = objArr; if (!(i10 >= 0)) { throw new IllegalArgumentException(("ring buffer filled size should not be negative but it is " + i10).toString()); } if (i10 <= objArr.length) { this.f14433c = objArr.length; this.f14435e = i10; return; } throw new IllegalArgumentException(("ring buffer filled size: " + i10 + " cannot be larger than the buffer size: " + objArr.length).toString()); } @Override // t8.a public int a() { return this.f14435e; } public final void e(Object obj) { if (g()) { throw new IllegalStateException("ring buffer is full"); } this.f14432b[(this.f14434d + size()) % this.f14433c] = obj; this.f14435e = size() + 1; } public final g0 f(int i10) { int c10; Object[] array; int i11 = this.f14433c; c10 = g9.f.c(i11 + (i11 >> 1) + 1, i10); if (this.f14434d == 0) { array = Arrays.copyOf(this.f14432b, c10); d9.j.d(array, "copyOf(this, newSize)"); } else { array = toArray(new Object[c10]); } return new g0(array, size()); } public final boolean g() { return size() == this.f14433c; } @Override // t8.c, java.util.List public Object get(int i10) { c.f14423a.a(i10, size()); return this.f14432b[(this.f14434d + i10) % this.f14433c]; } public final void h(int i10) { if (!(i10 >= 0)) { throw new IllegalArgumentException(("n shouldn't be negative but it is " + i10).toString()); } if (!(i10 <= size())) { throw new IllegalArgumentException(("n shouldn't be greater than the buffer size: n = " + i10 + ", size = " + size()).toString()); } if (i10 > 0) { int i11 = this.f14434d; int i12 = (i11 + i10) % this.f14433c; if (i11 > i12) { h.d(this.f14432b, null, i11, this.f14433c); h.d(this.f14432b, null, 0, i12); } else { h.d(this.f14432b, null, i11, i12); } this.f14434d = i12; this.f14435e = size() - i10; } } @Override // t8.c, java.util.Collection, java.lang.Iterable, java.util.List public Iterator iterator() { return new a(); } @Override // t8.a, java.util.Collection public Object[] toArray(Object[] objArr) { d9.j.e(objArr, "array"); if (objArr.length < size()) { objArr = Arrays.copyOf(objArr, size()); d9.j.d(objArr, "copyOf(this, newSize)"); } int size = size(); int i10 = 0; int i11 = 0; for (int i12 = this.f14434d; i11 < size && i12 < this.f14433c; i12++) { objArr[i11] = this.f14432b[i12]; i11++; } while (i11 < size) { objArr[i11] = this.f14432b[i10]; i11++; i10++; } if (objArr.length > size()) { objArr[size()] = null; } d9.j.c(objArr, "null cannot be cast to non-null type kotlin.Array"); return objArr; } public g0(int i10) { this(new Object[i10], 0); } @Override // t8.a, java.util.Collection public Object[] toArray() { return toArray(new Object[size()]); } }