S - The type of the machine's states.I - The type of the inputs.O - The type of the outputs.public interface StateMachine<S,I,O>
| Modifier and Type | Method and Description |
|---|---|
Transition<S,O> |
apply(S state,
I input)
Apply the given input to the given state, returning a transition to a new state with 0 or more outputs.
|
static <S,I,O> StateMachine<S,I,O> |
create(java.util.function.Supplier<S> initialState,
java.util.function.BiFunction<S,I,Transition<S,O>> transitionFunction)
Use the given transition function to create a state machine that never terminates, and releases no final outputs at the end of processing.
|
static <S,I,O> StateMachine<S,I,O> |
create(java.util.function.Supplier<S> initialState,
java.util.function.BiFunction<S,I,Transition<S,O>> transitionFunction,
java.util.function.Predicate<S> isTerminal)
Use the given transition function to create a state machine that terminates if the terminating condition is met, but releases no final outputs at the end of processing.
|
static <S,I,O> StateMachine<S,I,O> |
create(java.util.function.Supplier<S> initialState,
java.util.function.BiFunction<S,I,Transition<S,O>> transitionFunction,
java.util.function.Predicate<S> isTerminal,
java.util.function.Function<S,java.util.stream.Stream<O>> finisher)
Use the given transition function to create a state machine that terminates if the terminating condition is met, and may release final outputs at the end of processing.
|
default java.util.stream.Stream<O> |
finish(S finalState)
Based on the final state (if non-terminal), obtain any "left-over" outputs when the end of the stream is reached.
|
S |
getInitialState() |
default boolean |
isTerminal(S state)
Test whether a given state is terminal and stream traversal should stop.
|
default StateMachineRunner<S,I,O> |
runner() |
default StateMachineRunner<S,I,O> |
runnerWith(S initialState) |
static <S,I,O> StateMachine<S,I,O> create(java.util.function.Supplier<S> initialState, java.util.function.BiFunction<S,I,Transition<S,O>> transitionFunction)
S - The type of the machine's states.I - The type of the inputs.O - The type of the outputs.initialState - The initial state of the state machine.transitionFunction - The transition function to use.static <S,I,O> StateMachine<S,I,O> create(java.util.function.Supplier<S> initialState, java.util.function.BiFunction<S,I,Transition<S,O>> transitionFunction, java.util.function.Predicate<S> isTerminal)
S - The type of the machine's states.I - The type of the inputs.O - The type of the outputs.initialState - The initial state of the state machine.transitionFunction - The transition function to use.isTerminal - The condition that determines when a state is terminal.static <S,I,O> StateMachine<S,I,O> create(java.util.function.Supplier<S> initialState, java.util.function.BiFunction<S,I,Transition<S,O>> transitionFunction, java.util.function.Predicate<S> isTerminal, java.util.function.Function<S,java.util.stream.Stream<O>> finisher)
S - The type of the machine's states.I - The type of the inputs.O - The type of the outputs.initialState - The initial state of the state machine.transitionFunction - The transition function to use.isTerminal - The condition that determines when a state is terminal.finisher - The function that releases final outputs at the end of processing.Transition<S,O> apply(S state, I input)
state - The state to transition from.input - The input to apply to the state.default boolean isTerminal(S state)
state - The state to test.default java.util.stream.Stream<O> finish(S finalState)
finalState - The state at the end of the stream.S getInitialState()
default StateMachineRunner<S,I,O> runner()
default StateMachineRunner<S,I,O> runnerWith(S initialState)
Copyright © 2020. All rights reserved.