T_State
- public abstract class StateEngine<T_State extends StateEngine>
extends java.lang.Object
StateEngine
is an abstract class that is used in code generation by annotation processor
for creating concrete StateEngine
implementations for StateMachine
s. All concrete
state classes are derived from the code generated implemetation of StateEngine
.Modifier and Type | Class and Description |
---|---|
static class |
StateEngine.Error
Error defines error types and messages for StateEngine . |
Modifier and Type | Field and Description |
---|---|
protected T_State |
currentState
The current state among the substates of this state.
|
protected java.lang.Class<? extends T_State> |
initialStateClass
A
Class specifying the initial state among the substates of this state. |
protected java.util.HashMap<java.lang.Class<?>,T_State> |
stateCache
A
HashMap used for caching state instances. |
protected T_State |
stateEngine
The reference to an instance of
StateEngine that represents a state machine. |
protected java.util.HashSet<T_State> |
subStates
A
HashMap containing either 1) the substates of a state if this instance of StateEngine
represents a state or 2) the top-level states if this instance of StateEngine
represents a state machine. |
protected T_State |
superState
The super state of the state represented by this instance of
StateEngine . |
protected java.lang.Class<? extends T_State> |
superStateClass
The class of the super state of the state represented by this instance of
StateEngine . |
Modifier | Constructor and Description |
---|---|
protected |
StateEngine(java.lang.Class<? extends T_State> initialStateClass)
This constructor is to be used by a concrete implementation of
StateEngine . |
protected |
StateEngine(java.lang.Class<? extends T_State> superStateClass,
java.lang.Class<? extends T_State> initialStateClass)
This constructor is to be used by all actual state classes which are extended from the concrete
implementation of this
StateEngine . |
Modifier and Type | Method and Description |
---|---|
protected T_State |
dispatch()
Selects a state that should receive the trigger event.
|
protected void |
dispose()
Disposes this
StateEngine and the all state objects contained by it. |
protected T_State |
enter(int entryPoint)
Enters the represented by this instance of
StateEngine . |
protected T_State |
enterDeepHistory()
Enters a deep history point.
|
protected T_State |
enterEntryPoint(int entryPoint)
Enters the specified entry point.
|
protected T_State |
enterShallowHistory()
Enters a shallow history point.
|
protected void |
exit(T_State newState)
Invoked to exit the state represented by this instance of
StateEngine . |
<T extends StateEngine> |
getCurrentState()
Gets the current state of this
StateEngine or state. |
StateEngineObserver |
getObserver()
Gets the
StateEngineObserver assigned for this StateEngine . |
protected T_State |
getState(java.lang.Class<? extends T_State> stateClass)
Gets an instance of the specified state.
|
protected T_State |
getStateEngine()
Gets the reference to a
StateEngine . |
protected <T extends T_State> |
getSuperState()
Gets the super state of this state.
|
boolean |
hasSuperState()
Tests if this the state represented by this instance of
StateEngine has a super state
that is not StateEngine . |
boolean |
hasSuperState(java.lang.Class<? extends StateEngine<?>> stateClass)
Tests if this state is the same state or a direct or
an indirect substate state of the specified state.
|
protected boolean |
isStateEngine()
Tests if this instance of
StateEngine represents a state machine and not a state
that belongs into it. |
boolean |
isSuperState(T_State state)
Tests if the given state object is a direct or an indirect super state of the state
represented by this instance of
StateEngine . |
protected boolean |
isSuperStateFor(T_State state)
Tests if the state object represented by this instance of
StateEngine is a direct or
an indirect super state of the given state. |
protected void |
onDisposeState()
Invoked by
dispose() for an instance of StateEngine that
represents a state of a state machine. |
protected void |
onDisposeStateEngine()
Invoked by
dispose() for an instance of StateEngine that
represents a state machine. |
protected void |
onEnter()
Invoked by
enter(int) . |
protected void |
onError(T_State state,
StateEngine.Error error)
Invoked when the specified error has occurred while in the given state.
|
protected void |
onError(T_State state,
StateEngine.Error error,
java.lang.String eventName)
/**
Invoked when the specified error has occurred while in the named event has been received in
the given state.
|
protected void |
onExit()
Invoked by
exit(StateEngine) . |
protected void |
onUnhandledEvent(java.lang.String eventName) |
void |
reset()
Resets this
StateEngine . |
protected void |
setCurrentState(T_State state)
Sets the current state of this
StateEngine or state. |
void |
setObserver(StateEngineObserver observer)
Sets the
StateEngineObserver assigned for this StateEngine . |
void |
start()
Starts this
StateEngine . |
void |
stop()
Stops this
StateEngine . |
protected T_State |
toHistoryState(java.lang.Class<? extends T_State> stateClass,
boolean deepHistory)
Causes transition from the current state to the specified history state via a deep or
shallow history point.
|
java.lang.String |
toString()
A
String representation of this StateEngine is simply the name of the class
implementing abstract class StateEngine . |
protected T_State |
transitTo(java.lang.Class<? extends T_State> stateClass)
Causes transition from the current state to the specified state.
|
protected T_State |
transitTo(java.lang.Class<? extends T_State> stateClass,
int entryPoint)
Causes transition from the current state to the specified state optionally via an entry point
|
protected final java.util.HashSet<T_State extends StateEngine> subStates
HashMap
containing either 1) the substates of a state if this instance of StateEngine
represents a state or 2) the top-level states if this instance of StateEngine
represents a state machine.protected T_State extends StateEngine currentState
protected java.lang.Class<? extends T_State extends StateEngine> initialStateClass
Class
specifying the initial state among the substates of this state.protected java.util.HashMap<java.lang.Class<?>,T_State extends StateEngine> stateCache
HashMap
used for caching state instances. The Class
es of states can be used
as keys to the HashMap
, because each state object has its own Class
.protected T_State extends StateEngine stateEngine
StateEngine
that represents a state machine. All
instances of concrete implementations of StateEngine
that represent individual
states have a reference to the state machine.protected java.lang.Class<? extends T_State extends StateEngine> superStateClass
StateEngine
.
If this instance of StateEngine
is a state machine, then this field has null
value.protected T_State extends StateEngine superState
StateEngine
. If this
instance of StateEngine
is a state machine, then this field has null
value.protected StateEngine(java.lang.Class<? extends T_State> initialStateClass)
StateEngine
.initialStateClass
- The Class
of a state that is the initial state to be entered
at top-level when the represented state machine is started.protected StateEngine(java.lang.Class<? extends T_State> superStateClass, java.lang.Class<? extends T_State> initialStateClass)
StateEngine
.superStateClass
- The Class
of a state that is the super state of the state using
this constructor.initialStateClass
- The Class
of a state that is the initial state to be entered
at top-level when the represented state machine is started.public StateEngineObserver getObserver()
StateEngineObserver
assigned for this StateEngine
.StateEngineObserver
.public final void setObserver(StateEngineObserver observer)
StateEngineObserver
assigned for this StateEngine
.observer
- A StateEngineObserver
.protected final <T extends T_State> T getSuperState()
T
- A type parameter for the state type.public final <T extends StateEngine> T getCurrentState()
StateEngine
or state.T
- A type parameter for the state type.protected final void setCurrentState(T_State state)
StateEngine
or state.state
- A state object representing the new current state.protected final T_State getStateEngine()
StateEngine
.StateEngine
.protected final boolean isStateEngine()
StateEngine
represents a state machine and not a state
that belongs into it.boolean
value.protected final T_State getState(java.lang.Class<? extends T_State> stateClass)
stateClass
- A state object Class
.null
.protected T_State dispatch()
T_State
.protected final T_State transitTo(java.lang.Class<? extends T_State> stateClass)
stateClass
- A Class
specifying the target state for the state transition.T_State
.protected final T_State transitTo(java.lang.Class<? extends T_State> stateClass, int entryPoint)
stateClass
- A Class
specifying the target state for the state transition.entryPoint
- A int
value specifying if the optional entry point. Value zero
represents a non entry point.protected final T_State toHistoryState(java.lang.Class<? extends T_State> stateClass, boolean deepHistory)
stateClass
- A Class
specifying the target state for the state transition.deepHistory
- A boolean
value specifying if the state is entered via a deep
history point instead of shallow history point.protected final T_State enter(int entryPoint)
StateEngine
. If the state is entered via
an entry point the index of the entry point has to be given and it has to be greater than zero.entryPoint
- The index of the entry point to be entered. Value zero represents a non
entry point.protected void onExit()
exit(StateEngine)
.protected void onEnter()
enter(int)
.protected T_State enterEntryPoint(int entryPoint)
entryPoint
- The index of the entry point to be entered.protected final T_State enterDeepHistory()
protected final T_State enterShallowHistory()
protected final void exit(T_State newState)
StateEngine
. The state
machine will enter the given new target state.newState
- A new target state.protected final void onError(T_State state, StateEngine.Error error)
state
- A state object.error
- An StateEngine.Error
value specifying the occurred error.protected final void onError(T_State state, StateEngine.Error error, java.lang.String eventName)
state
- A state object.error
- An StateEngine.Error
value specifying the occurred error.eventName
- The name of an event.protected void onUnhandledEvent(java.lang.String eventName)
protected void onDisposeStateEngine()
dispose()
for an instance of StateEngine
that
represents a state machine.protected void onDisposeState()
dispose()
for an instance of StateEngine
that
represents a state of a state machine.protected final void dispose()
StateEngine
and the all state objects contained by it. The method is
recursively invoked to all substates of a each state.public final void start()
StateEngine
. When started, the top-level initial state is entered.public final void reset()
StateEngine
. Resetting clear the cache of state machines. A state machine
has to be started again after resetting.public final void stop()
StateEngine
. Stopping causes the state machine and all of its state to be
disposed.public boolean hasSuperState()
StateEngine
has a super state
that is not StateEngine
.boolean
value.public boolean hasSuperState(java.lang.Class<? extends StateEngine<?>> stateClass)
stateClass
- A Class
specifying the state.boolean value
.public final boolean isSuperState(T_State state)
StateEngine
.state
- A state object to be tested.boolean
value.protected final boolean isSuperStateFor(T_State state)
StateEngine
is a direct or
an indirect super state of the given state.state
- A state object to be tested.boolean
value.public java.lang.String toString()
String
representation of this StateEngine
is simply the name of the class
implementing abstract class StateEngine
.toString
in class java.lang.Object
String