|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.zkoss.fsm.StateMachine<E,C,IN>
public abstract class 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.
Nested Class Summary | |
---|---|
static class |
StateMachine.StateMachineException
|
Field Summary | |
---|---|
protected E |
_current
|
protected boolean |
_debug
|
protected boolean |
_run
|
protected java.util.Map<E,StateCtx<E,C,IN>> |
_states
|
protected int |
_step
|
Constructor Summary | |
---|---|
StateMachine()
Construct a state machine |
Method Summary | |
---|---|
protected void |
afterStep(IN input,
C inputClass,
E origin,
E destination)
This method is called after executing a step |
protected void |
beforeStep(IN input,
C inputClass,
E origin)
This method is called before executing a step |
protected void |
doDebug(java.lang.String message)
Manually send a debug message |
protected void |
doReject(IN input)
Reject a character |
protected abstract C |
getClass(IN input)
Determines the class for an input character. |
E |
getCurrentState()
Return the current state |
protected abstract E |
getLandingState(IN input,
C inputClass)
Determines the initial state upon meeting the input character and class |
StateCtx<E,C,IN> |
getState(E token)
Get the state by token. |
StateCtx<E,C,IN> |
getState(E token,
boolean autoCreate)
Get the state by token. |
protected void |
init()
Called at the constructor of state machine |
boolean |
isSuspended()
Return true if the machine is suspended |
boolean |
isTerminated()
Return true if the machine is stopped |
protected void |
onDebug(java.lang.String message)
This method is call at certain situations when debug mode is on. |
protected void |
onReject(IN input)
This method is called when the machine rejects an input character |
protected void |
onReset()
This method is called at constructor and when reseting the machine. |
protected void |
onStart(IN input,
C inputClass,
E landing)
This method is called when the machine takes the first character. |
protected void |
onStop(boolean endOfInput)
This method is called when the machine stops |
StateCtx<E,C,IN> |
removeState(E token)
Remove the state by token. |
void |
run(IN input)
Feed the machine a single character |
void |
run(java.util.Iterator<IN> inputs)
Feed the machine a stream of characters |
StateMachine<E,C,IN> |
setDebugMode(boolean mode)
Set debug mode, where onDebug(String) is called at certain timing to
assist user develop the state machine |
StateCtx<E,C,IN> |
setState(E token,
StateCtx<E,C,IN> state)
Set the state by token |
void |
start(IN input)
Starts the machine with a single input character. |
void |
start(java.util.Iterator<IN> inputs)
Starts the machine with a stream of input characters. |
protected void |
suspend()
Suspend the machine |
void |
terminate()
Terminates the machine. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final java.util.Map<E,StateCtx<E,C,IN>> _states
protected E _current
protected boolean _run
protected int _step
protected boolean _debug
Constructor Detail |
---|
public StateMachine()
Method Detail |
---|
public StateMachine<E,C,IN> setDebugMode(boolean mode)
onDebug(String)
is called at certain timing to
assist user develop the state machine
public StateCtx<E,C,IN> setState(E token, StateCtx<E,C,IN> state)
public StateCtx<E,C,IN> removeState(E token)
public StateCtx<E,C,IN> getState(E token)
public StateCtx<E,C,IN> getState(E token, boolean autoCreate)
autoCreate
- if true, automatically creates one if it does not exist.protected void init()
protected abstract E getLandingState(IN input, C inputClass)
protected abstract C getClass(IN input)
protected void onReset()
protected void onStart(IN input, C inputClass, E landing)
protected void beforeStep(IN input, C inputClass, E origin)
protected void afterStep(IN input, C inputClass, E origin, E destination)
protected void onStop(boolean endOfInput)
endOfInput
- true if the machine stops due to end of inputprotected void onReject(IN input)
protected void onDebug(java.lang.String message)
setDebugMode(boolean)
public final void run(java.util.Iterator<IN> inputs)
public final void run(IN input)
public final void start(java.util.Iterator<IN> inputs)
public final void start(IN input)
public final void terminate()
public E getCurrentState()
public boolean isTerminated()
public boolean isSuspended()
protected final void suspend()
protected final void doReject(IN input)
protected final void doDebug(java.lang.String message)
onDebug(String)
,
setDebugMode(boolean)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |