package kotlin.sequences;

import java.util.Iterator;
import java.util.NoSuchElementException;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.EmptyCoroutineContext;

/* JADX INFO: loaded from: classes.dex */
public final class f extends g implements Iterator, Continuation, td.a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f29251a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Object f29252b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Iterator f29253c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Continuation f29254d;

    public final RuntimeException a() {
        int i10 = this.f29251a;
        if (i10 == 4) {
            return new NoSuchElementException();
        }
        if (i10 == 5) {
            return new IllegalStateException("Iterator has failed.");
        }
        return new IllegalStateException("Unexpected state of the iterator: " + this.f29251a);
    }

    @Override // kotlin.coroutines.Continuation
    public final kotlin.coroutines.h getContext() {
        return EmptyCoroutineContext.f29221a;
    }

    @Override // java.util.Iterator
    public final boolean hasNext() {
        while (true) {
            int i10 = this.f29251a;
            if (i10 != 0) {
                if (i10 != 1) {
                    if (i10 == 2 || i10 == 3) {
                        return true;
                    }
                    if (i10 == 4) {
                        return false;
                    }
                    throw a();
                }
                Iterator it = this.f29253c;
                nb.g.f(it);
                if (it.hasNext()) {
                    this.f29251a = 2;
                    return true;
                }
                this.f29253c = null;
            }
            this.f29251a = 5;
            Continuation continuation = this.f29254d;
            nb.g.f(continuation);
            this.f29254d = null;
            continuation.resumeWith(kd.e.f29109a);
        }
    }

    @Override // java.util.Iterator
    public final Object next() {
        int i10 = this.f29251a;
        if (i10 == 0 || i10 == 1) {
            if (hasNext()) {
                return next();
            }
            throw new NoSuchElementException();
        }
        if (i10 == 2) {
            this.f29251a = 1;
            Iterator it = this.f29253c;
            nb.g.f(it);
            return it.next();
        }
        if (i10 != 3) {
            throw a();
        }
        this.f29251a = 0;
        Object obj = this.f29252b;
        this.f29252b = null;
        return obj;
    }

    @Override // java.util.Iterator
    public final void remove() {
        throw new UnsupportedOperationException("Operation is not supported for read-only collection");
    }

    @Override // kotlin.coroutines.Continuation
    public final void resumeWith(Object obj) {
        kotlin.a.d(obj);
        this.f29251a = 4;
    }
}
