package R4;

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

/* JADX INFO: loaded from: classes3.dex */
public final class f implements Iterator, K4.a {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Iterator f6093b;

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ k f6096e;

    public f(g gVar) {
        this.f6092a = 0;
        this.f6096e = gVar;
        this.f6093b = gVar.f6097a.iterator();
        this.f6094c = -1;
    }

    public void a() {
        Object next;
        g gVar;
        do {
            Iterator it = this.f6093b;
            if (!it.hasNext()) {
                this.f6094c = 0;
                return;
            } else {
                next = it.next();
                gVar = (g) this.f6096e;
            }
        } while (((Boolean) gVar.f6099c.invoke(next)).booleanValue() != gVar.f6098b);
        this.f6095d = next;
        this.f6094c = 1;
    }

    /* JADX WARN: Type inference failed for: r1v4, types: [J4.c, kotlin.jvm.internal.p] */
    public void b() {
        Iterator it = this.f6093b;
        if (it.hasNext()) {
            Object next = it.next();
            if (((Boolean) ((kotlin.jvm.internal.p) ((j) this.f6096e).f6109c).invoke(next)).booleanValue()) {
                this.f6094c = 1;
                this.f6095d = next;
                return;
            }
        }
        this.f6094c = 0;
    }

    public boolean c() {
        Iterator it;
        Iterator it2 = (Iterator) this.f6095d;
        if (it2 != null && it2.hasNext()) {
            this.f6094c = 1;
            return true;
        }
        do {
            Iterator it3 = this.f6093b;
            if (!it3.hasNext()) {
                this.f6094c = 2;
                this.f6095d = null;
                return false;
            }
            Object next = it3.next();
            h hVar = (h) this.f6096e;
            hVar.getClass();
            it = (Iterator) q.f6116a.invoke(hVar.f6102c.invoke(next));
        } while (!it.hasNext());
        this.f6095d = it;
        this.f6094c = 1;
        return true;
    }

    @Override // java.util.Iterator
    public final boolean hasNext() {
        switch (this.f6092a) {
            case 0:
                if (this.f6094c == -1) {
                    a();
                }
                return this.f6094c == 1;
            case 1:
                int i6 = this.f6094c;
                if (i6 == 1) {
                    return true;
                }
                if (i6 == 2) {
                    return false;
                }
                return c();
            default:
                if (this.f6094c == -1) {
                    b();
                }
                return this.f6094c == 1;
        }
    }

    @Override // java.util.Iterator
    public final Object next() {
        switch (this.f6092a) {
            case 0:
                if (this.f6094c == -1) {
                    a();
                }
                if (this.f6094c == 0) {
                    throw new NoSuchElementException();
                }
                Object obj = this.f6095d;
                this.f6095d = null;
                this.f6094c = -1;
                return obj;
            case 1:
                int i6 = this.f6094c;
                if (i6 == 2) {
                    throw new NoSuchElementException();
                }
                if (i6 == 0 && !c()) {
                    throw new NoSuchElementException();
                }
                this.f6094c = 0;
                Iterator it = (Iterator) this.f6095d;
                kotlin.jvm.internal.o.e(it);
                return it.next();
            default:
                if (this.f6094c == -1) {
                    b();
                }
                if (this.f6094c == 0) {
                    throw new NoSuchElementException();
                }
                Object obj2 = this.f6095d;
                this.f6095d = null;
                this.f6094c = -1;
                return obj2;
        }
    }

    @Override // java.util.Iterator
    public final void remove() {
        switch (this.f6092a) {
            case 0:
                throw new UnsupportedOperationException("Operation is not supported for read-only collection");
            case 1:
                throw new UnsupportedOperationException("Operation is not supported for read-only collection");
            default:
                throw new UnsupportedOperationException("Operation is not supported for read-only collection");
        }
    }

    public f(h hVar) {
        this.f6092a = 1;
        this.f6096e = hVar;
        this.f6093b = hVar.f6101b.iterator();
    }

    public f(j jVar) {
        this.f6092a = 2;
        this.f6096e = jVar;
        this.f6093b = ((k) jVar.f6108b).iterator();
        this.f6094c = -1;
    }
}
