|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.progeeks.fsm.FiniteStateMachine
public class FiniteStateMachine
Provides simple and fast state based processing of message events. FiniteStateMachine implements StateHandler because technically there's no reason that they can't be nested. I don't see a good use-case for it, but it's certainly possible.
Constructor Summary | |
---|---|
FiniteStateMachine(int stateCount,
int messageTypeCount)
Creates a new finite state machine that can process information using the specified number of states and message types. |
Method Summary | |
---|---|
StateHandler |
getStateHandler(int state,
int message)
Returns the state handler for the specified state and message. |
int |
handleMessage(int state,
int message,
java.lang.Object stateInfo)
Handles the specified message information by looking up the appropriate handler. |
void |
initializeMessageType(int messageType,
StateHandler handler)
Sets the specified handler to process all messages of the specified type no matter to which state they arrive. |
void |
initializeState(int state,
StateHandler handler)
Sets the specified handler to process all messages for the specified state. |
void |
initializeStateMachine(StateHandler handler)
Initializes all states and message types to the specified handler. |
void |
setStateHandler(int state,
int message,
StateHandler handler)
Sets the specified handler to process messages for the specified state and message type. |
void |
setStateHandlers(int[] states,
int[] messages,
StateHandler handler)
Sets the specified handler to process messages for the specified states and message types. |
void |
setStateHandlers(int[] states,
int message,
StateHandler handler)
Sets the specified handler to process messages for the specified states and message type. |
void |
setStateHandlers(int state,
int[] messages,
StateHandler handler)
Sets the specified handler to process messages for the specified state and message types. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FiniteStateMachine(int stateCount, int messageTypeCount)
Method Detail |
---|
public int handleMessage(int state, int message, java.lang.Object stateInfo)
handleMessage
in interface StateHandler
state
- The current state the called this handler.message
- The numeric message to be handled.stateInfo
- The application specific data on which the handler
can operate if necessary.public StateHandler getStateHandler(int state, int message)
public void setStateHandler(int state, int message, StateHandler handler)
public void setStateHandlers(int[] states, int message, StateHandler handler)
public void setStateHandlers(int state, int[] messages, StateHandler handler)
public void setStateHandlers(int[] states, int[] messages, StateHandler handler)
public void initializeStateMachine(StateHandler handler)
public void initializeState(int state, StateHandler handler)
public void initializeMessageType(int messageType, StateHandler handler)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |