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 TypeMethodDescriptionvoidchangeState(State newState) Exits the current state and enters a new state, unless both are equal.voidchangeState(State from, State to) Changes the state of this state machine, only if the current state matches a given state.protected LoggergetState()booleanChecks 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, waitMethods 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:StateProviderChecks whether the state machine is in a given state. -
getLogger
-