S - The type used to represent the statesT - The type used to represent the triggers that cause state transitionspublic class StateMachine<S,T>
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected StateMachineConfig<S,T> |
config |
protected Func<S> |
stateAccessor |
protected Action1<S> |
stateMutator |
protected Action2<S,T> |
unhandledTriggerAction |
| Constructor and Description |
|---|
StateMachine(S intialState)
Construct a state machine
|
StateMachine(S initialState,
Func<S> stateAccessor,
Action1<S> stateMutator,
StateMachineConfig<S,T> config)
Construct a state machine with external state storage.
|
StateMachine(S initialState,
StateMachineConfig<S,T> config)
Construct a state machine
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canFire(T trigger)
Returns true if
trigger can be fired in the current state |
StateConfiguration<S,T> |
configure(S state) |
void |
fire(T trigger)
Transition from the current state via the specified trigger.
|
<TArg0> void |
fire(TriggerWithParameters1<TArg0,S,T> trigger,
TArg0 arg0)
Transition from the current state via the specified trigger.
|
<TArg0,TArg1> |
fire(TriggerWithParameters2<TArg0,TArg1,S,T> trigger,
TArg0 arg0,
TArg1 arg1)
Transition from the current state via the specified trigger.
|
<TArg0,TArg1,TArg2> |
fire(TriggerWithParameters3<TArg0,TArg1,TArg2,S,T> trigger,
TArg0 arg0,
TArg1 arg1,
TArg2 arg2)
Transition from the current state via the specified trigger.
|
java.util.List<T> |
getPermittedTriggers()
The currently-permissible trigger values
|
S |
getState()
The current state
|
boolean |
isInState(S state)
Determine if the state machine is in the supplied state
|
void |
onUnhandledTrigger(Action2<S,T> unhandledTriggerAction)
Override the default behaviour of throwing an exception when an unhandled trigger is fired
|
protected void |
publicFire(T trigger,
java.lang.Object... args) |
java.lang.String |
toString()
A human-readable representation of the state machine
|
protected final StateMachineConfig<S,T> config
public StateMachine(S intialState)
intialState - The initial statepublic StateMachine(S initialState, StateMachineConfig<S,T> config)
initialState - The initial stateconfig - State machine configurationpublic StateConfiguration<S,T> configure(S state)
public S getState()
public java.util.List<T> getPermittedTriggers()
public void fire(T trigger)
trigger - The trigger to firepublic <TArg0> void fire(TriggerWithParameters1<TArg0,S,T> trigger, TArg0 arg0)
TArg0 - Type of the first trigger argumenttrigger - The trigger to firearg0 - The first argumentpublic <TArg0,TArg1> void fire(TriggerWithParameters2<TArg0,TArg1,S,T> trigger, TArg0 arg0, TArg1 arg1)
TArg0 - Type of the first trigger argumentTArg1 - Type of the second trigger argumenttrigger - The trigger to firearg0 - The first argumentarg1 - The second argumentpublic <TArg0,TArg1,TArg2> void fire(TriggerWithParameters3<TArg0,TArg1,TArg2,S,T> trigger, TArg0 arg0, TArg1 arg1, TArg2 arg2)
TArg0 - Type of the first trigger argumentTArg1 - Type of the second trigger argumentTArg2 - Type of the third trigger argumenttrigger - The trigger to firearg0 - The first argumentarg1 - The second argumentarg2 - The third argumentprotected void publicFire(T trigger, java.lang.Object... args)
public void onUnhandledTrigger(Action2<S,T> unhandledTriggerAction)
unhandledTriggerAction - An action to call when an unhandled trigger is firedpublic boolean isInState(S state)
state - The state to test forpublic boolean canFire(T trigger)
trigger can be fired in the current statetrigger - Trigger to testpublic java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2014. All Rights Reserved.