package W6;

import A6.n;
import com.google.android.gms.internal.measurement.C1;
import java.util.Iterator;
import java.util.NoSuchElementException;

/* JADX INFO: loaded from: classes.dex */
public final class i implements Iterator, E6.d, Q6.a {

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

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

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

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public E6.d f7210t;

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

    @Override // E6.d
    public final E6.i h() {
        return E6.j.f2226q;
    }

    @Override // java.util.Iterator
    public final boolean hasNext() {
        while (true) {
            int i = this.f7207q;
            if (i != 0) {
                if (i != 1) {
                    if (i == 2 || i == 3) {
                        return true;
                    }
                    if (i == 4) {
                        return false;
                    }
                    throw a();
                }
                Iterator it = this.f7209s;
                P6.g.b(it);
                if (it.hasNext()) {
                    this.f7207q = 2;
                    return true;
                }
                this.f7209s = null;
            }
            this.f7207q = 5;
            E6.d dVar = this.f7210t;
            P6.g.b(dVar);
            this.f7210t = null;
            dVar.i(n.f457a);
        }
    }

    @Override // E6.d
    public final void i(Object obj) throws Throwable {
        C1.N(obj);
        this.f7207q = 4;
    }

    @Override // java.util.Iterator
    public final Object next() {
        int i = this.f7207q;
        if (i == 0 || i == 1) {
            if (hasNext()) {
                return next();
            }
            throw new NoSuchElementException();
        }
        if (i == 2) {
            this.f7207q = 1;
            Iterator it = this.f7209s;
            P6.g.b(it);
            return it.next();
        }
        if (i != 3) {
            throw a();
        }
        this.f7207q = 0;
        Object obj = this.f7208r;
        this.f7208r = null;
        return obj;
    }

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