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.

@FunctionalInterface public interface TransitionAction
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 Details

    • execute

      void execute(StateMachineContext context, State from, State to)
      Executes the action.
      Parameters:
      context - the state machine context
      from - the source state
      to - the target state
    • noop

      static TransitionAction noop()
      Creates a no-op action.
      Returns:
      no-op action
    • andThen

      default TransitionAction andThen(TransitionAction after)
      Chains this action with another.
      Parameters:
      after - the action to run after this one
      Returns:
      combined action