public final class StateMachine extends Object
StateMachine.State
s. StateMachine is by default a linear model, until
addState(State, State)
is called. Each State has three status:
STATUS_ZERO, STATUS_INVOKED, STATUS_EXECUTED. We allow client to run a State, which will
put State in STATUS_INVOKED. A State will be executed when prior States are executed and
Precondition for this State is true, then the State will be marked as STATUS_EXECUTED.Modifier and Type | Class and Description |
---|---|
static class |
StateMachine.State |
Modifier and Type | Field and Description |
---|---|
static int |
STATUS_EXECUTED
Somebody wants to run the State and the State was executed.
|
static int |
STATUS_INVOKED
Somebody wants to run the state but not yet executed because either the condition is
false or lower States are not executed.
|
static int |
STATUS_ZERO
No request on the State
|
Constructor and Description |
---|
StateMachine() |
Modifier and Type | Method and Description |
---|---|
void |
addState(StateMachine.State state)
Add a State to StateMachine, ignore if it is already added.
|
void |
addState(StateMachine.State fromState,
StateMachine.State toState)
Add two States to StateMachine and create an edge between this two.
|
void |
resetStatus() |
void |
runPendingStates() |
void |
runState(StateMachine.State state) |
void |
sort()
StateMachine is by default a linear model, until
addState(State, State) is called. |
public static final int STATUS_ZERO
public static final int STATUS_INVOKED
public static final int STATUS_EXECUTED
public void addState(StateMachine.State state)
state
- The state to add.public void addState(StateMachine.State fromState, StateMachine.State toState)
addState(State, State)
is called.
sort() is required to sort the Direct acyclic graph.fromState
- The from state to add.toState
- The to state to add.public void runState(StateMachine.State state)
public void runPendingStates()
public void resetStatus()
public void sort()
addState(State, State)
is called.
sort() is required to sort the Direct acyclic graph.