Package dev.prozilla.pine.core.state
Class StateMachine<Context,State extends State<Context>>
java.lang.Object
dev.prozilla.pine.core.state.StateMachine<Context,State>
- All Implemented Interfaces:
StateProvider<Context,
State>
public class StateMachine<Context,State extends State<Context>>
extends Object
implements StateProvider<Context,State>
Utility class for managing a finite-state machine (FSM).
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionStateMachine
(State initialState, Context context) Creates a state machine for a given context and enters its initial state. -
Method Summary
Modifier and TypeMethodDescriptionvoid
changeState
(State newState) Exits the current state and enters a new state, unless both are equal.void
changeState
(State from, State to) Changes the state of this state machine, only if the current state matches a given state.protected Logger
getState()
boolean
Checks whether the state machine is in a given state.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.prozilla.pine.core.state.StateProvider
isAnyState
-
Field Details
-
currentState
-
context
-
-
Constructor Details
-
StateMachine
Creates a state machine for a given context and enters its initial state.- Parameters:
initialState
- The initial state of the state machinecontext
- The context of the state
-
-
Method Details
-
changeState
Changes the state of this state machine, only if the current state matches a given state.- Parameters:
from
- Determines what the current state must be in order for this change to be performed.to
- The new state
-
changeState
Exits the current state and enters a new state, unless both are equal.- Parameters:
newState
- The new state to enter
-
getState
-
isState
Description copied from interface:StateProvider
Checks whether the state machine is in a given state. -
getLogger
-