E - the type of the entity owning this state machineS - the type of the states of this state machinepublic class StackStateMachine<E,S extends State<E>> extends DefaultStateMachine<E,S>
StateMachine implementation that keeps track of all previous States via a stack. This makes sense for example
in case of a hierarchical menu structure where each menu screen is one state and one wants to navigate back to the main menu
anytime, via revertToPreviousState().currentState, globalState, owner, previousState| Constructor and Description |
|---|
StackStateMachine()
Creates a
StackStateMachine with no owner, initial state and global state. |
StackStateMachine(E owner)
Creates a
StackStateMachine for the specified owner. |
StackStateMachine(E owner,
S initialState)
Creates a
StackStateMachine for the specified owner and initial state. |
StackStateMachine(E owner,
S initialState,
S globalState)
Creates a
StackStateMachine for the specified owner, initial state and global state. |
| Modifier and Type | Method and Description |
|---|---|
void |
changeState(S newState)
Performs a transition to the specified state.
|
S |
getCurrentState()
Returns the current state of this state machine.
|
S |
getPreviousState()
Returns the last state of this state machine.
|
boolean |
revertToPreviousState()
Changes the Change state back to the previous state.
|
void |
setInitialState(S state)
Sets the initial state of this state machine.
|
getGlobalState, getOwner, handleMessage, isInState, setGlobalState, setOwner, updatepublic StackStateMachine()
StackStateMachine with no owner, initial state and global state.public StackStateMachine(E owner)
StackStateMachine for the specified owner.owner - the owner of the state machinepublic StackStateMachine(E owner, S initialState)
StackStateMachine for the specified owner and initial state.owner - the owner of the state machineinitialState - the initial statepublic void setInitialState(S state)
StateMachinesetInitialState in interface StateMachine<E,S extends State<E>>setInitialState in class DefaultStateMachine<E,S extends State<E>>state - the initial state.public S getCurrentState()
StateMachinegetCurrentState in interface StateMachine<E,S extends State<E>>getCurrentState in class DefaultStateMachine<E,S extends State<E>>public S getPreviousState()
getPreviousState in interface StateMachine<E,S extends State<E>>getPreviousState in class DefaultStateMachine<E,S extends State<E>>public void changeState(S newState)
StateMachinechangeState in interface StateMachine<E,S extends State<E>>changeState in class DefaultStateMachine<E,S extends State<E>>newState - the state to transition topublic boolean revertToPreviousState()
revertToPreviousState in interface StateMachine<E,S extends State<E>>revertToPreviousState in class DefaultStateMachine<E,S extends State<E>>True in case there was a previous state that we were able to revert to. In case there is no previous state,
no state change occurs and false will be returned.Copyright © 2017. All rights reserved.