public abstract class FiniteStateMachine extends Object
#onEvent(com.codefactory.event.Event)
method to the user.Modifier and Type | Field and Description |
---|---|
static String |
FSM_EVENT_TYPE |
static String |
FSM_IS_IN_TERMINAL_STATE |
Constructor and Description |
---|
FiniteStateMachine()
Constructs the finite state machine in the terminal state, i.e. without
any particular current state.
|
FiniteStateMachine(Class<? extends State> stateClass)
Constructs the finite state machine in the state of the specified class.
|
FiniteStateMachine(State initialState)
Constructs the finite state machine in the specified state.
|
Modifier and Type | Method and Description |
---|---|
State |
getCurrentState()
Returns current state of the FSM.
|
abstract void |
onEvent(Event event)
Reacts to an event that occurs during processing of input.
|
void |
process(byte b)
Hands the byte to be processed with the current state.
|
void |
process(byte[] buffer)
Hands bytes from the buffer to be processed by the current state
sequentially.
|
void |
process(byte[] buffer,
int offset,
int length)
Hands bytes from the buffer to be processed by the current state
sequentially.
|
void |
transitTo(Class<? extends State> stateClass)
Transfers the FSM to the new state of the specified class.
|
void |
transitTo(State state)
Transfers the FSM to the new state.
|
public static final String FSM_EVENT_TYPE
public static final String FSM_IS_IN_TERMINAL_STATE
public FiniteStateMachine()
process(byte)
method invocation until a state will be set using
transitTo(org.firmata4j.fsm.State)
.public FiniteStateMachine(State initialState)
initialState
- initial state of the FSMpublic FiniteStateMachine(Class<? extends State> stateClass)
stateClass
- the class of initial state of the FSMIllegalArgumentException
- when creating of the state instance is
impossible (likely because of lack of the constructor taking the FSM as a
parameter)public void transitTo(State state)
state
- the new statepublic void transitTo(Class<? extends State> stateClass)
FiniteStateMachine
instance as a parameter. The
IllegalArgumentException
is thrown otherwise.stateClass
- the state classpublic State getCurrentState()
public void process(byte b)
b
- input bytepublic void process(byte[] buffer)
buffer
- the bytes to be processedpublic void process(byte[] buffer, int offset, int length)
buffer
- the bytes to be processedoffset
- the index of the first byte to processlength
- the number of the bytes to be processedpublic abstract void onEvent(Event event)
event
- the eventCopyright © 2017. All rights reserved.