package androidx.compose.runtime.snapshots;

import androidx.compose.runtime.internal.StabilityInferred;
import java.util.ConcurrentModificationException;
import java.util.Iterator;

/* JADX INFO: loaded from: classes.dex */
@StabilityInferred(parameters = 0)
public final class StateSetIterator<T> implements Iterator<T>, K4.a {
    public static final int $stable = 8;
    private T current;
    private final Iterator<T> iterator;
    private int modification;
    private T next;
    private final SnapshotStateSet<T> set;

    /* JADX WARN: Multi-variable type inference failed */
    public StateSetIterator(SnapshotStateSet<T> snapshotStateSet, Iterator<? extends T> it) {
        this.set = snapshotStateSet;
        this.iterator = it;
        this.modification = SnapshotStateSetKt.getModification(snapshotStateSet);
        advance();
    }

    private final void advance() {
        this.current = this.next;
        this.next = this.iterator.hasNext() ? this.iterator.next() : null;
    }

    public static /* synthetic */ void getNext$annotations() {
    }

    private final <T> T modify(J4.a aVar) {
        validateModification();
        T t6 = (T) aVar.invoke();
        this.modification = SnapshotStateSetKt.getModification(this.set);
        return t6;
    }

    private final void validateModification() {
        if (SnapshotStateSetKt.getModification(this.set) != this.modification) {
            throw new ConcurrentModificationException();
        }
    }

    public final T getCurrent() {
        return this.current;
    }

    public final Iterator<T> getIterator() {
        return this.iterator;
    }

    public final int getModification() {
        return this.modification;
    }

    public final T getNext() {
        return this.next;
    }

    public final SnapshotStateSet<T> getSet() {
        return this.set;
    }

    @Override // java.util.Iterator
    public boolean hasNext() {
        return this.next != null;
    }

    @Override // java.util.Iterator
    public T next() {
        validateModification();
        advance();
        T t6 = this.current;
        if (t6 != null) {
            return t6;
        }
        throw new IllegalStateException();
    }

    @Override // java.util.Iterator
    public void remove() {
        validateModification();
        T t6 = this.current;
        if (t6 == null) {
            throw new IllegalStateException();
        }
        this.set.remove(t6);
        this.current = null;
        this.modification = SnapshotStateSetKt.getModification(this.set);
    }

    public final void setCurrent(T t6) {
        this.current = t6;
    }

    public final void setModification(int i6) {
        this.modification = i6;
    }

    public final void setNext(T t6) {
        this.next = t6;
    }
}
