Package org.flasby.util.statemachine
Class StateMachine<State,Event>
java.lang.Object
org.flasby.util.statemachine.StateMachine<State,Event>
implements a Finite State Machine.
- Author:
- steve
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionStateMachine
(State initialState) creates a new FSM in the defined initialState.StateMachine
(State initialState, BiConsumer<State, Event> monitor) creates a new FSM in the defined initialState. -
Method Summary
Modifier and TypeMethodDescriptionaddGlobalTransition
(Event event, State to, BiConsumer<State, Event> enterStateAction) addGlobalTransition
(Event event, State to, BiConsumer<State, Event> enterStateAction, BiConsumer<State, Event> exitStateAction) addTransition
(State from, State to, Event event) addTransition
(State from, State to, Event event, BiConsumer<State, Event> enterStateAction) addTransition
(State from, State to, Event event, BiConsumer<State, Event> enterStateAction, BiConsumer<State, Event> exitStateAction) void
forceTransition
(State state, Event event) getState()
void
process the event and move from the current state to the next one if a transition is defined for the event.
-
Field Details
-
NULL_CONSUMER
-
-
Constructor Details
-
StateMachine
creates a new FSM in the defined initialState.- Parameters:
initialState
-
-
StateMachine
creates a new FSM in the defined initialState.- Parameters:
initialState
-
-
-
Method Details
-
process
process the event and move from the current state to the next one if a transition is defined for the event. If no such transition is found then call handleNoTransition(...) and remain in the current state. If a transition is found the the FSM: - invokes the exitStateAction on the transition if such is defined. - moves to the next state - invokes the enterStateAction on the transition if such is defined.- Parameters:
event
- The event to process
-
addTransition
-
addTransition
public StateMachine<State,Event> addTransition(State from, State to, Event event, BiConsumer<State, Event> enterStateAction) -
addTransition
public StateMachine<State,Event> addTransition(State from, State to, Event event, BiConsumer<State, Event> enterStateAction, BiConsumer<State, Event> exitStateAction) -
addGlobalTransition
public StateMachine<State,Event> addGlobalTransition(Event event, State to, BiConsumer<State, Event> enterStateAction) -
addGlobalTransition
public StateMachine<State,Event> addGlobalTransition(Event event, State to, BiConsumer<State, Event> enterStateAction, BiConsumer<State, Event> exitStateAction) -
getState
-
forceTransition
-