Class TimeStateMachine
Simple StateMachine that is meant to be extended or decorated to achieve state dependent behavior where every state has a fixed duration.
The method logicLoop() must be periodically called to be able to let
the States check for its time to be up. For this cause, the
State must supply a State.getTimerTime() as well as a
State.getNextState().
- Author:
- Angelo Aracri
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StateTheState, theTimeStateMachineis currently in. -
Constructor Summary
ConstructorsConstructorDescriptionTimeStateMachine(State initialState) The constructor that initializes theTimeStateMachinewith a giveninitialState. -
Method Summary
Modifier and TypeMethodDescriptiongetState()Getter for theStatetheTimeStateMachineis currently the in.voidMethod that must be periodically called in order to check for theStatestime to be up.voidSwitches theStateto the next as specified byState.getNextState().protected voidMore specific version ofnextState()that enables for switching to a givenStatethat must not necessarily be specified by the currentStatesState.getNextState()or that can be used to alter theStatesbefore entering them..
-
Field Details
-
currentState
TheState, theTimeStateMachineis currently in.
-
-
Constructor Details
-
TimeStateMachine
The constructor that initializes theTimeStateMachinewith a giveninitialState.- Parameters:
initialState- the initialState.
-
-
Method Details
-
logicLoop
public void logicLoop()Method that must be periodically called in order to check for theStatestime to be up. -
nextState
public void nextState()Switches the
Stateto the next as specified byState.getNextState().Calls both the old
StatesState.leave()as well as the new onesState.enter(TimeStateMachine parent). -
nextState
More specific version of
nextState()that enables for switching to a givenStatethat must not necessarily be specified by the currentStatesState.getNextState()or that can be used to alter theStatesbefore entering them..- Parameters:
nextState- the newStateto enter.
-
getState
Getter for theStatetheTimeStateMachineis currently the in.- Returns:
- the current
State.
-