package o;

import java.util.ConcurrentModificationException;
import java.util.NoSuchElementException;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class PW extends S {
    public final NW n;

    /* renamed from: o, reason: collision with root package name */
    public int f285o;
    public Zg0 p;
    public int q;

    public PW(NW nw, int i) {
        super(i, nw.s);
        this.n = nw;
        this.f285o = nw.e();
        this.q = -1;
        b();
    }

    public final void a() {
        if (this.f285o != this.n.e()) {
            throw new ConcurrentModificationException();
        }
    }

    @Override // o.S, java.util.ListIterator
    public final void add(Object obj) {
        a();
        int i = this.l;
        NW nw = this.n;
        nw.add(i, obj);
        this.l++;
        this.m = nw.a();
        this.f285o = nw.e();
        this.q = -1;
        b();
    }

    /* JADX WARN: Type inference failed for: r6v2 */
    /* JADX WARN: Type inference failed for: r6v3, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r6v4 */
    public final void b() {
        NW nw = this.n;
        Object[] objArr = nw.q;
        if (objArr == null) {
            this.p = null;
            return;
        }
        int i = (nw.s - 1) & (-32);
        int i2 = this.l;
        if (i2 > i) {
            i2 = i;
        }
        int i3 = (nw.f257o / 5) + 1;
        Zg0 zg0 = this.p;
        if (zg0 == null) {
            this.p = new Zg0(objArr, i2, i, i3);
            return;
        }
        zg0.l = i2;
        zg0.m = i;
        zg0.n = i3;
        if (zg0.f439o.length < i3) {
            zg0.f439o = new Object[i3];
        }
        zg0.f439o[0] = objArr;
        ?? r6 = i2 == i ? 1 : 0;
        zg0.p = r6;
        zg0.b(i2 - r6, 1);
    }

    @Override // java.util.ListIterator, java.util.Iterator
    public final Object next() {
        a();
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        int i = this.l;
        this.q = i;
        Zg0 zg0 = this.p;
        NW nw = this.n;
        if (zg0 == null) {
            Object[] objArr = nw.r;
            this.l = i + 1;
            return objArr[i];
        }
        if (zg0.hasNext()) {
            this.l++;
            return zg0.next();
        }
        Object[] objArr2 = nw.r;
        int i2 = this.l;
        this.l = i2 + 1;
        return objArr2[i2 - zg0.m];
    }

    @Override // java.util.ListIterator
    public final Object previous() {
        a();
        if (!hasPrevious()) {
            throw new NoSuchElementException();
        }
        int i = this.l;
        this.q = i - 1;
        Zg0 zg0 = this.p;
        NW nw = this.n;
        if (zg0 == null) {
            Object[] objArr = nw.r;
            int i2 = i - 1;
            this.l = i2;
            return objArr[i2];
        }
        int i3 = zg0.m;
        if (i <= i3) {
            this.l = i - 1;
            return zg0.previous();
        }
        Object[] objArr2 = nw.r;
        int i4 = i - 1;
        this.l = i4;
        return objArr2[i4 - i3];
    }

    @Override // o.S, java.util.ListIterator, java.util.Iterator
    public final void remove() {
        a();
        int i = this.q;
        if (i == -1) {
            throw new IllegalStateException();
        }
        NW nw = this.n;
        nw.b(i);
        int i2 = this.q;
        if (i2 < this.l) {
            this.l = i2;
        }
        this.m = nw.a();
        this.f285o = nw.e();
        this.q = -1;
        b();
    }

    @Override // o.S, java.util.ListIterator
    public final void set(Object obj) {
        a();
        int i = this.q;
        if (i == -1) {
            throw new IllegalStateException();
        }
        NW nw = this.n;
        nw.set(i, obj);
        this.f285o = nw.e();
        b();
    }
}
