Package org.zkoss.fsm
Class StateMachine<E,C,IN>
java.lang.Object
org.zkoss.fsm.StateMachine<E,C,IN>
A Finite State Machine implementation. This state machine is callback based,
which differs from the standard FSM from textbook. Easier to use and faster
to develop and debug.
- Since:
- 6.0.0
- Author:
- simonpai
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidThis method is called after executing a stepprotected voidbeforeStep(IN input, C inputClass, E origin) This method is called before executing a stepprotected final voidManually send a debug messageprotected final voidReject a characterprotected abstract CDetermines the class for an input character.Return the current stateprotected abstract EgetLandingState(IN input, C inputClass) Determines the initial state upon meeting the input character and classGet the state by token.Get the state by token.protected voidinit()Called at the constructor of state machinebooleanReturn true if the machine is suspendedbooleanReturn true if the machine is stoppedprotected voidThis method is call at certain situations when debug mode is on.protected voidThis method is called when the machine rejects an input characterprotected voidonReset()This method is called at constructor and when reseting the machine.protected voidThis method is called when the machine takes the first character.protected voidonStop(boolean endOfInput) This method is called when the machine stopsremoveState(E token) Remove the state by token.final voidFeed the machine a single characterfinal voidFeed the machine a stream of charactersStateMachine<E,C, IN> setDebugMode(boolean mode) Set debug mode, whereonDebug(String)is called at certain timing to assist user develop the state machineSet the state by tokenfinal voidStarts the machine with a single input character.final voidStarts the machine with a stream of input characters.protected final voidsuspend()Suspend the machinefinal voidTerminates the machine.
-
Field Details
-
_states
-
_current
-
_run
protected boolean _run -
_step
protected int _step -
_debug
protected boolean _debug
-
-
Constructor Details
-
StateMachine
public StateMachine()Construct a state machine
-
-
Method Details
-
setDebugMode
Set debug mode, whereonDebug(String)is called at certain timing to assist user develop the state machine -
setState
Set the state by token- Returns:
- the state
-
removeState
Remove the state by token.- Returns:
- the removed state
-
getState
Get the state by token. Automatically creates one if it does not exist. -
getState
Get the state by token.- Parameters:
autoCreate- if true, automatically creates one if it does not exist.
-
init
protected void init()Called at the constructor of state machine -
getLandingState
Determines the initial state upon meeting the input character and class -
getClass
Determines the class for an input character. -
onReset
protected void onReset()This method is called at constructor and when reseting the machine. -
onStart
This method is called when the machine takes the first character. -
beforeStep
This method is called before executing a step -
afterStep
This method is called after executing a step -
onStop
protected void onStop(boolean endOfInput) This method is called when the machine stops- Parameters:
endOfInput- true if the machine stops due to end of input
-
onReject
This method is called when the machine rejects an input character -
onDebug
This method is call at certain situations when debug mode is on.- See Also:
-
run
Feed the machine a stream of characters -
run
Feed the machine a single character -
start
Starts the machine with a stream of input characters. -
start
Starts the machine with a single input character. -
terminate
public final void terminate()Terminates the machine. -
getCurrentState
Return the current state -
isTerminated
public boolean isTerminated()Return true if the machine is stopped -
isSuspended
public boolean isSuspended()Return true if the machine is suspended -
suspend
protected final void suspend()Suspend the machine -
doReject
Reject a character -
doDebug
Manually send a debug message- See Also:
-