public class Condition<I,O> extends CoroutineStep<I,O>
Coroutine
step that test a logical expression in the form of a
Predicate
or BiPredicate
and executes certain steps (which
may be a subroutines) based on the boolean result.Constructor and Description |
---|
Condition(java.util.function.BiPredicate<? super I,Continuation<?>> pCondition,
CoroutineStep<I,O> rRunIfTrue,
CoroutineStep<I,O> rRunIfFalse)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
static <I,O> Condition<I,O> |
doIf(java.util.function.BiPredicate<? super I,Continuation<?>> fCondition,
CoroutineStep<I,O> rRunIfTrue)
Tests a logical condition and executes a certain step if the condition is
TRUE.
|
static <I,O> Condition<I,O> |
doIf(java.util.function.Predicate<? super I> fCondition,
CoroutineStep<I,O> rRunIfTrue)
Tests a logical condition and executes a certain step if the condition is
TRUE.
|
static <I,O> Condition<I,O> |
doIfElse(java.util.function.BiPredicate<? super I,Continuation<?>> fCondition,
CoroutineStep<I,O> rRunIfTrue,
CoroutineStep<I,O> rRunIfFalse)
Tests a logical condition and executes certain steps if the condition is
either TRUE or FALSE.
|
static <I,O> Condition<I,O> |
doIfElse(java.util.function.Predicate<? super I> fCondition,
CoroutineStep<I,O> rRunIfTrue,
CoroutineStep<I,O> rRunIfFalse)
Tests a logical condition and executes certain steps if the condition is
either TRUE or FALSE.
|
protected O |
execute(I rInput,
Continuation<?> rContinuation)
This method must be implemented by subclasses to provide the actual
functionality of this step.
|
Condition<I,O> |
orElse(CoroutineStep<I,O> rRunIfFalse)
Returns a new instance with the condition and TRUE step of this and a
certain step to execute if the condition is FALSE.
|
void |
runAsync(java.util.concurrent.CompletableFuture<I> fPreviousExecution,
CoroutineStep<O,?> rNextStep,
Continuation<?> rContinuation)
Runs this execution step asynchronously as a continuation of a previous
code execution in a
CompletableFuture and proceeds to the next
step afterwards. |
fail, runBlocking, terminateCoroutine, toString
deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public Condition(java.util.function.BiPredicate<? super I,Continuation<?>> pCondition, CoroutineStep<I,O> rRunIfTrue, CoroutineStep<I,O> rRunIfFalse)
pCondition
- The condition to testrRunIfTrue
- The step to run if the condition is TRUErRunIfFalse
- The step to run if the condition is FALSEpublic static <I,O> Condition<I,O> doIf(java.util.function.Predicate<? super I> fCondition, CoroutineStep<I,O> rRunIfTrue)
orElse(CoroutineStep)
or the
alternative method doIfElse(Predicate, CoroutineStep,
CoroutineStep)
can be used. If no 'else' step is set the coroutine will
terminate if the condition is not met.
This variant expects a unary predicate that only receives the input
value. If the Continuation
needs to be tested too the method
doIf(BiPredicate, CoroutineStep)
can be used instead.
fCondition
- The condition to testrRunIfTrue
- The step to run if the condition is TRUEpublic static <I,O> Condition<I,O> doIf(java.util.function.BiPredicate<? super I,Continuation<?>> fCondition, CoroutineStep<I,O> rRunIfTrue)
orElse(CoroutineStep)
or the
alternative method doIfElse(Predicate, CoroutineStep,
CoroutineStep)
can be used. If no 'else' step is set the coroutine will
terminate if the condition is not met.
This variant expects a binary predicate that also receives the current
Continuation
. If a test of the input value is sufficient the
method doIf(Predicate, CoroutineStep)
can be used instead.
fCondition
- The condition to testrRunIfTrue
- The step to run if the condition is TRUEpublic static <I,O> Condition<I,O> doIfElse(java.util.function.BiPredicate<? super I,Continuation<?>> fCondition, CoroutineStep<I,O> rRunIfTrue, CoroutineStep<I,O> rRunIfFalse)
doIf(BiPredicate, CoroutineStep)
in conjunction with the instance
method orElse(CoroutineStep)
.
This variant expects a binary predicate that also receives the current
Continuation
. If a test of the input value is sufficient the
method doIfElse(Predicate, CoroutineStep, CoroutineStep)
can be
used instead.
fCondition
- The condition to testrRunIfTrue
- The step to run if the condition is TRUErRunIfFalse
- The step to run if the condition is FALSEpublic static <I,O> Condition<I,O> doIfElse(java.util.function.Predicate<? super I> fCondition, CoroutineStep<I,O> rRunIfTrue, CoroutineStep<I,O> rRunIfFalse)
doIf(BiPredicate, CoroutineStep)
in conjunction with the instance
method orElse(CoroutineStep)
.
This variant expects a unary predicate that only receives the input
value. If the Continuation
needs to be tested too the method
doIf(BiPredicate, CoroutineStep)
can be used instead.
fCondition
- The condition to testrRunIfTrue
- The step to run if the condition is TRUErRunIfFalse
- The step to run if the condition is FALSEpublic Condition<I,O> orElse(CoroutineStep<I,O> rRunIfFalse)
doIfElse(BiPredicate, CoroutineStep,
CoroutineStep)
.rRunIfFalse
- The step to run if the condition is FALSEpublic void runAsync(java.util.concurrent.CompletableFuture<I> fPreviousExecution, CoroutineStep<O,?> rNextStep, Continuation<?> rContinuation)
CompletableFuture
and proceeds to the next
step afterwards.
Subclasses that need to suspend the invocation of the next step until
some condition is met (e.g. sending or receiving data has finished) need
to override this method and create a Suspension
by invoking
Continuation.suspend(CoroutineStep, CoroutineStep)
on the next
step. If the condition that caused the suspension resolves the coroutine
execution can be resumed by calling Suspension.resume(Object)
.
Subclasses that override this method also need to handle errors by
terminating any further execution (i.e. not resuming a suspension if such
exists) and forwarding the causing exception to Continuation.fail(Throwable)
.
runAsync
in class CoroutineStep<I,O>
fPreviousExecution
- The future of the previous code executionrNextStep
- The next step to execute or NULL for nonerContinuation
- The continuation of the executionprotected O execute(I rInput, Continuation<?> rContinuation)
execute
in class CoroutineStep<I,O>
rInput
- The input valuerContinuation
- The continuation of the execution