package kotlin.sequences; import java.util.Iterator; import java.util.NoSuchElementException; import kotlin.Result; import kotlin.ResultKt; import kotlin.Unit; import kotlin.coroutines.Continuation; import kotlin.coroutines.CoroutineContext; import kotlin.coroutines.EmptyCoroutineContext; import kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsKt; import kotlin.coroutines.jvm.internal.DebugProbesKt; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.markers.KMappedMarker; /* loaded from: classes5.dex */ public final class SequenceBuilderIterator extends SequenceScope implements Iterator, Continuation, KMappedMarker { public Iterator nextIterator; public Continuation nextStep; public Object nextValue; public int state; @Override // java.util.Iterator public void remove() { throw new UnsupportedOperationException("Operation is not supported for read-only collection"); } public final void setNextStep(Continuation continuation) { this.nextStep = continuation; } @Override // java.util.Iterator public boolean hasNext() { while (true) { int i = this.state; if (i != 0) { if (i != 1) { if (i == 2 || i == 3) { return true; } if (i == 4) { return false; } throw exceptionalState(); } Iterator it = this.nextIterator; Intrinsics.checkNotNull(it); if (it.hasNext()) { this.state = 2; return true; } this.nextIterator = null; } this.state = 5; Continuation continuation = this.nextStep; Intrinsics.checkNotNull(continuation); this.nextStep = null; Result.Companion companion = Result.Companion; continuation.resumeWith(Result.m4060constructorimpl(Unit.INSTANCE)); } } @Override // java.util.Iterator public Object next() { int i = this.state; if (i == 0 || i == 1) { return nextNotReady(); } if (i == 2) { this.state = 1; Iterator it = this.nextIterator; Intrinsics.checkNotNull(it); return it.next(); } if (i != 3) { throw exceptionalState(); } this.state = 0; Object obj = this.nextValue; this.nextValue = null; return obj; } public final Object nextNotReady() { if (hasNext()) { return next(); } throw new NoSuchElementException(); } public final Throwable exceptionalState() { int i = this.state; if (i == 4) { return new NoSuchElementException(); } if (i == 5) { return new IllegalStateException("Iterator has failed."); } return new IllegalStateException("Unexpected state of the iterator: " + this.state); } @Override // kotlin.sequences.SequenceScope public Object yield(Object obj, Continuation continuation) { Object coroutine_suspended; Object coroutine_suspended2; Object coroutine_suspended3; this.nextValue = obj; this.state = 3; this.nextStep = continuation; coroutine_suspended = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); coroutine_suspended2 = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); if (coroutine_suspended == coroutine_suspended2) { DebugProbesKt.probeCoroutineSuspended(continuation); } coroutine_suspended3 = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); return coroutine_suspended == coroutine_suspended3 ? coroutine_suspended : Unit.INSTANCE; } @Override // kotlin.sequences.SequenceScope public Object yieldAll(Iterator it, Continuation continuation) { Object coroutine_suspended; Object coroutine_suspended2; Object coroutine_suspended3; if (!it.hasNext()) { return Unit.INSTANCE; } this.nextIterator = it; this.state = 2; this.nextStep = continuation; coroutine_suspended = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); coroutine_suspended2 = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); if (coroutine_suspended == coroutine_suspended2) { DebugProbesKt.probeCoroutineSuspended(continuation); } coroutine_suspended3 = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); return coroutine_suspended == coroutine_suspended3 ? coroutine_suspended : Unit.INSTANCE; } @Override // kotlin.coroutines.Continuation public void resumeWith(Object obj) { ResultKt.throwOnFailure(obj); this.state = 4; } @Override // kotlin.coroutines.Continuation public CoroutineContext getContext() { return EmptyCoroutineContext.INSTANCE; } }