package o;

import java.util.Iterator;
import java.util.NoSuchElementException;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class G60 implements Iterator, InterfaceC0220Im, InterfaceC2989yJ {
    public int l;
    public Object m;
    public InterfaceC0220Im n;

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

    public final void b(Object obj, G20 g20) {
        this.m = obj;
        this.l = 3;
        this.n = g20;
    }

    @Override // o.InterfaceC0220Im
    public final InterfaceC2747vn h() {
        return C0281Kv.l;
    }

    @Override // java.util.Iterator
    public final boolean hasNext() {
        int i;
        while (true) {
            i = this.l;
            if (i != 0) {
                break;
            }
            this.l = 5;
            InterfaceC0220Im interfaceC0220Im = this.n;
            this.n = null;
            interfaceC0220Im.resumeWith(Oh0.a);
        }
        if (i == 1) {
            throw null;
        }
        if (i == 2 || i == 3) {
            return true;
        }
        if (i == 4) {
            return false;
        }
        throw a();
    }

    @Override // java.util.Iterator
    public final Object next() {
        int i = this.l;
        if (i == 0 || i == 1) {
            if (hasNext()) {
                return next();
            }
            throw new NoSuchElementException();
        }
        if (i == 2) {
            this.l = 1;
            throw null;
        }
        if (i != 3) {
            throw a();
        }
        this.l = 0;
        Object obj = this.m;
        this.m = null;
        return obj;
    }

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

    @Override // o.InterfaceC0220Im
    public final void resumeWith(Object obj) {
        IJ.H(obj);
        this.l = 4;
    }
}
