|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.cuni.amis.fsm.FSM<SYMBOL,CONTEXT>
SYMBOL
- CONTEXT
- public class FSM<SYMBOL,CONTEXT>
Context aware FSM implementation.
FSM = Finite State Machine, also called FSA = Finite State Automaton, more info at http://en.wikipedia.org/wiki/Finite_state_machine
This FSM is based upon the annotations FSMState, FSMTransition, FSMInitialState and FSMTerminalState.
Every class annotated with FSMState may be inserted to the FSM (in constructor) as FSM state. The annotation always contains the transitions that leads from the state to other states.
Unlike many other implementations of the FSMs there is out there in the wild, this one isn't driven by integers. It works with whole objects instead treating their classes as the symbols. Generic parameter SYMBOL should the common ancestor of all symbols you will want to pass to the FSM. This allows you (for instance) to implement protocols based upon real messages (where every message has it's own class!).
Note that every action of FSM's states and transitions have "context" parameter. Use this object to pass the common interface you will need during the state/transition work (stateEntering(), stateSymbol(), stateLeaving(), stepped()).
Pros of this implementation:
Nested Class Summary | |
---|---|
protected static class |
FSM.StateWrapper<SYMBOL,CONTEXT>
|
protected static class |
FSM.TransitionWrapper<SYMBOL,CONTEXT>
|
Constructor Summary | |
---|---|
FSM(CONTEXT context,
java.lang.Class<? extends IFSMState<SYMBOL,CONTEXT>> state,
java.util.logging.Logger log)
FSM constructor that tries to instantiate all states / transitions for itself. |
|
FSM(CONTEXT context,
IFSMState<SYMBOL,CONTEXT>[] states,
IFSMTransition[] transitions,
java.util.logging.Logger log)
Note that this constructor will use "states" and "transitions" to instantiate the FSM but you may omit those states/transitions that contains implicite constructor (parameter-less). |
|
FSM(CONTEXT context,
IFSMState<SYMBOL,CONTEXT> state,
java.util.logging.Logger log)
FSM constructor that tries to instantiate all (but first "state") states / transitions for itself. |
Method Summary | |
---|---|
static IFSMState |
getState(java.lang.Class<? extends IFSMState> state,
java.util.logging.Logger log)
Construct and returns IFSMState of the given class, parameter-less constructor is sought. |
protected java.util.Collection<FSM.StateWrapper<SYMBOL,CONTEXT>> |
getStates()
|
protected static IFSMTransition |
getTransition(java.lang.Class<? extends IFSMTransition> transition,
java.util.logging.Logger log)
Constructs and returns IFSMTransition of the given class, parameter-less constructor is sought. |
java.util.Collection<IFSMTransition<SYMBOL,CONTEXT>> |
getTransitions()
|
boolean |
isTerminal()
|
void |
push(CONTEXT context,
SYMBOL symbol)
|
void |
restart(CONTEXT context)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FSM(CONTEXT context, java.lang.Class<? extends IFSMState<SYMBOL,CONTEXT>> state, java.util.logging.Logger log)
First state to try is "state".
context
- state
- log
- may be nullpublic FSM(CONTEXT context, IFSMState<SYMBOL,CONTEXT> state, java.util.logging.Logger log)
First state to try is "state".
context
- state
- log
- may be nullpublic FSM(CONTEXT context, IFSMState<SYMBOL,CONTEXT>[] states, IFSMTransition[] transitions, java.util.logging.Logger log)
context
- states
- transitions
- log
- may be nullMethod Detail |
---|
protected java.util.Collection<FSM.StateWrapper<SYMBOL,CONTEXT>> getStates()
public java.util.Collection<IFSMTransition<SYMBOL,CONTEXT>> getTransitions()
public static IFSMState getState(java.lang.Class<? extends IFSMState> state, java.util.logging.Logger log)
Throws FSMBuildException if constructor not found.
state
- log
- may be null
protected static IFSMTransition getTransition(java.lang.Class<? extends IFSMTransition> transition, java.util.logging.Logger log)
Throws FSMBuildException if constructor not found.
state
- log
- may be null
public boolean isTerminal()
isTerminal
in interface IFSM<SYMBOL,CONTEXT>
public void push(CONTEXT context, SYMBOL symbol)
push
in interface IFSM<SYMBOL,CONTEXT>
public void restart(CONTEXT context)
restart
in interface IFSM<SYMBOL,CONTEXT>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |