package c1;

import java.util.ConcurrentModificationException;
import jn.o;
import kotlin.jvm.internal.t;

/* loaded from: classes.dex */
public final class h extends a {

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

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

    /* renamed from: t, reason: collision with root package name */
    private k f7364t;

    /* renamed from: u, reason: collision with root package name */
    private int f7365u;

    public h(f fVar, int i10) {
        super(i10, fVar.size());
        this.f7362r = fVar;
        this.f7363s = fVar.r();
        this.f7365u = -1;
        m();
    }

    private final void g() {
        if (this.f7363s != this.f7362r.r()) {
            throw new ConcurrentModificationException();
        }
    }

    private final void h() {
        if (this.f7365u == -1) {
            throw new IllegalStateException();
        }
    }

    private final void i() {
        f(this.f7362r.size());
        this.f7363s = this.f7362r.r();
        this.f7365u = -1;
        m();
    }

    private final void m() {
        int g10;
        Object[] x10 = this.f7362r.x();
        if (x10 == null) {
            this.f7364t = null;
            return;
        }
        int d10 = l.d(this.f7362r.size());
        g10 = o.g(c(), d10);
        int z10 = (this.f7362r.z() / 5) + 1;
        k kVar = this.f7364t;
        if (kVar == null) {
            this.f7364t = new k(x10, g10, d10, z10);
        } else {
            t.d(kVar);
            kVar.m(x10, g10, d10, z10);
        }
    }

    @Override // c1.a, java.util.ListIterator
    public void add(Object obj) {
        g();
        this.f7362r.add(c(), obj);
        e(c() + 1);
        i();
    }

    @Override // java.util.ListIterator, java.util.Iterator
    public Object next() {
        g();
        a();
        this.f7365u = c();
        k kVar = this.f7364t;
        if (kVar == null) {
            Object[] B = this.f7362r.B();
            int c10 = c();
            e(c10 + 1);
            return B[c10];
        }
        if (kVar.hasNext()) {
            e(c() + 1);
            return kVar.next();
        }
        Object[] B2 = this.f7362r.B();
        int c11 = c();
        e(c11 + 1);
        return B2[c11 - kVar.d()];
    }

    @Override // java.util.ListIterator
    public Object previous() {
        g();
        b();
        this.f7365u = c() - 1;
        k kVar = this.f7364t;
        if (kVar == null) {
            Object[] B = this.f7362r.B();
            e(c() - 1);
            return B[c()];
        }
        if (c() <= kVar.d()) {
            e(c() - 1);
            return kVar.previous();
        }
        Object[] B2 = this.f7362r.B();
        e(c() - 1);
        return B2[c() - kVar.d()];
    }

    @Override // c1.a, java.util.ListIterator, java.util.Iterator
    public void remove() {
        g();
        h();
        this.f7362r.remove(this.f7365u);
        if (this.f7365u < c()) {
            e(this.f7365u);
        }
        i();
    }

    @Override // c1.a, java.util.ListIterator
    public void set(Object obj) {
        g();
        h();
        this.f7362r.set(this.f7365u, obj);
        this.f7363s = this.f7362r.r();
        m();
    }
}
