Package com.tnsai.fsm
Interface TransitionAction
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Functional interface for transition actions.
Actions are executed during a state transition, after leaving the source state and before entering the target state.
Usage
TransitionAction logTransition = (ctx, from, to) -> {
System.out.println("Transitioning from " + from.getName() + " to " + to.getName());
};
TransitionAction updateMetrics = (ctx, from, to) -> {
int count = ctx.getOrDefault("transitionCount", 0);
ctx.set("transitionCount", count + 1);
};
-
Method Summary
Modifier and TypeMethodDescriptiondefault TransitionActionandThen(TransitionAction after) Chains this action with another.voidexecute(StateMachineContext context, State from, State to) Executes the action.static TransitionActionnoop()Creates a no-op action.
-
Method Details
-
execute
Executes the action.- Parameters:
context- the state machine contextfrom- the source stateto- the target state
-
noop
Creates a no-op action.- Returns:
- no-op action
-
andThen
Chains this action with another.- Parameters:
after- the action to run after this one- Returns:
- combined action
-