Package com.koralix.stepfn
Class StepFunction<T,V,R>  
java.lang.Object
com.koralix.stepfn.StepFunction<T,V,R>  
- Type Parameters:
- T- the type of the input to the function
- V- the type of the internal result of the function
- R- the type of the external result of the function
- All Implemented Interfaces:
- Function<T,- R> 
- Direct Known Subclasses:
- AsyncStepFunction,- SyncStepFunction
A 
StepFunction is a Function that is composed of Steps.
 Example:
 
 Step<String, Integer> step1 = new Step<>() {
     @Override
     public Integer apply(String input) {
         return input.length();
     }
     @Override
     public boolean isComplete() {
         return true;
     }
 };
 Step<Integer, Boolean> step2 = new Step<>() {
     @Override
     public Integer apply(Integer input) {
         return input > 5;
     }
     @Override
     public boolean isComplete() {
         return true;
     }
 };
 StepFunction<String, ?, Boolean> lengthCheck = new SyncStepFunction<>(step1);
 lengthCheck.addTransition(
         step1,
         step2,
         input -> true
 );
 lengthCheck.apply("Hello World"); // true
 lengthCheck.apply("Hello"); // false
 
 - Since:
- 1.0.0
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionStepFunction(Step<T, ?> initialStep) Creates a newStepFunctionwith the given initialStep.StepFunction(Step<T, ?> initialStep, Map<Step<?, ?>, Set<Transition<?, ?>>> transitions) Deprecated.
- 
Method SummaryModifier and TypeMethodDescription<A> voidaddTransition(Step<?, A> from, Step<A, ?> to, Function<A, Boolean> predicate) <A,B> void Adds aTransitionfrom the first givenStepto the second givenStepwith the given predicate and mapper.protected <A,B> void apply(Step<A, B> step, Step<?, ?> from, A input, CompletableFuture<V> future) Recursive method that applies the givenStepto the given input.Returns the initialStepof thisStepFunction.protected abstract <A,B> Optional<CompletableFuture<B>> Computes the result of the givenStepwith the given input.protected <A,B> Set<Transition<A, B>> transitions(Step<?, A> step) Returns theTransitions that transition from the givenStep.
- 
Constructor Details- 
StepFunction@Deprecated public StepFunction(Step<T, ?> initialStep, Map<Step<?, ?>, Set<Transition<?, ?>>> transitions) Deprecated.useStepFunction(Step)instead - this constructor will be removed in 1.2.0- Parameters:
- initialStep- the initial step
- transitions- the transitions
- Since:
- 1.0.0
 
- 
StepFunctionCreates a newStepFunctionwith the given initialStep.- Parameters:
- initialStep- the initial step
- Since:
- 1.0.0
 
 
- 
- 
Method Details- 
addTransitionpublic <A,B> void addTransition(Step<?, A> from, Step<B, ?> to, Function<A, Boolean> predicate, Function<A, B> mapper) Adds aTransitionfrom the first givenStepto the second givenStepwith the given predicate and mapper.- Type Parameters:
- A- the output type of the from step
- B- the input type of the to step
- Parameters:
- from- the step to transition from
- to- the step to transition to
- predicate- the predicate to determine if the transition is applicable
- mapper- the mapper to map the input to the next step
- Since:
- 1.1.0
 
- 
addTransition- Type Parameters:
- A- the output type of the from step
- Parameters:
- from- the step to transition from
- to- the step to transition to
- predicate- the predicate to determine if the transition is applicable
- Since:
- 1.0.0
 
- 
applyRecursive method that applies the givenStepto the given input.This method implements the logic for aggregating the inputs of the Steps and applying completeSteps.After the Stephas been applied, the method will complete theCompletableFuturewith the result of theStep.- Type Parameters:
- A- the input type of the step
- B- the output type of the step
- Parameters:
- step- the step to apply
- from- the step that the input is coming from
- input- the input
- future- the future to complete
- Since:
- 1.0.0
 
- 
stepprotected abstract <A,B> Optional<CompletableFuture<B>> step(Step<A, B> step, Step<?, ?> from, A input) Computes the result of the givenStepwith the given input.If the given Stepis not complete the input is stored in theStepfor aggregation and the result is empty.- Type Parameters:
- A- the input type of the step
- B- the output type of the step
- Parameters:
- step- the step to execute
- from- the step that the input is coming from
- input- the input
- Returns:
- the result of the step
- Since:
- 1.0.0
 
- 
firstStepReturns the initialStepof thisStepFunction.- Returns:
- the initial step
- Since:
- 1.0.0
 
- 
transitionsReturns theTransitions that transition from the givenStep.- Type Parameters:
- A- the output type of the step
- B- the output type of the transitions
- Parameters:
- step- the step
- Returns:
- the transitions
- Since:
- 1.0.0
 
 
- 
StepFunction(Step)instead - this constructor will be removed in 1.2.0