Package org.incendo.cloud.state
Interface Stateful<S extends State>
- Type Parameters:
S- the state type
- All Known Implementing Classes:
CommandManager
A simple state machine.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidrequireState(@NonNull S expected) Requires that the currentstate()is equal to theexpectedstate, and fails exceptionally if the states are different.state()Returns the current state.booleantransitionIfPossible(@NonNull S in, @NonNull S out) Transitions from theinstate to theoutstate, unless the currentstate()is identical to theoutstate.default voidtransitionOrThrow(@NonNull S in, @NonNull S out) Transitions from theinstate to theoutstate, unless the currentstate()is identical to theoutstate.
-
Method Details
-
state
Returns the current state.- Returns:
- the current state
-
transitionIfPossible
Transitions from theinstate to theoutstate, unless the currentstate()is identical to theoutstate.- Parameters:
in- the starting stateout- the ending state- Returns:
trueif the state transition was successful, or the current state is identical to theoutstate
-
requireState
Requires that the currentstate()is equal to theexpectedstate, and fails exceptionally if the states are different.- Parameters:
expected- the expected state- Throws:
IllegalStateException- if the currentstate()is different from theexpectedstate
-
transitionOrThrow
Transitions from theinstate to theoutstate, unless the currentstate()is identical to theoutstate.- Parameters:
in- the starting stateout- the ending state- Throws:
IllegalStateException- if state transition is not possible
-