package j1;

import java.util.ConcurrentModificationException;
import java.util.ListIterator;

/* loaded from: classes.dex */
final class w implements ListIterator, en.a {

    /* renamed from: p, reason: collision with root package name */
    private final r f23575p;

    /* renamed from: q, reason: collision with root package name */
    private int f23576q;

    /* renamed from: r, reason: collision with root package name */
    private int f23577r = -1;

    /* renamed from: s, reason: collision with root package name */
    private int f23578s;

    public w(r rVar, int i10) {
        this.f23575p = rVar;
        this.f23576q = i10 - 1;
        this.f23578s = rVar.x();
    }

    private final void a() {
        if (this.f23575p.x() != this.f23578s) {
            throw new ConcurrentModificationException();
        }
    }

    @Override // java.util.ListIterator
    public void add(Object obj) {
        a();
        this.f23575p.add(this.f23576q + 1, obj);
        this.f23577r = -1;
        this.f23576q++;
        this.f23578s = this.f23575p.x();
    }

    @Override // java.util.ListIterator, java.util.Iterator
    public boolean hasNext() {
        return this.f23576q < this.f23575p.size() - 1;
    }

    @Override // java.util.ListIterator
    public boolean hasPrevious() {
        return this.f23576q >= 0;
    }

    @Override // java.util.ListIterator, java.util.Iterator
    public Object next() {
        a();
        int i10 = this.f23576q + 1;
        this.f23577r = i10;
        s.g(i10, this.f23575p.size());
        Object obj = this.f23575p.get(i10);
        this.f23576q = i10;
        return obj;
    }

    @Override // java.util.ListIterator
    public int nextIndex() {
        return this.f23576q + 1;
    }

    @Override // java.util.ListIterator
    public Object previous() {
        a();
        s.g(this.f23576q, this.f23575p.size());
        int i10 = this.f23576q;
        this.f23577r = i10;
        this.f23576q--;
        return this.f23575p.get(i10);
    }

    @Override // java.util.ListIterator
    public int previousIndex() {
        return this.f23576q;
    }

    @Override // java.util.ListIterator, java.util.Iterator
    public void remove() {
        a();
        this.f23575p.remove(this.f23576q);
        this.f23576q--;
        this.f23577r = -1;
        this.f23578s = this.f23575p.x();
    }

    @Override // java.util.ListIterator
    public void set(Object obj) {
        a();
        int i10 = this.f23577r;
        if (i10 < 0) {
            s.e();
            throw new rm.k();
        }
        this.f23575p.set(i10, obj);
        this.f23578s = this.f23575p.x();
    }
}
