net.sourceforge.aqueduct
Class StateMachineDescription<S extends State<I>,I extends InputSource>

java.lang.Object
  extended by net.sourceforge.aqueduct.StateMachineDescription<S,I>
Type Parameters:
I - The type of InputSource object used by States in this object to find the next transition name.

public class StateMachineDescription<S extends State<I>,I extends InputSource>
extends java.lang.Object

Contains State objects and the transitions between them. Intended to be an immutable data structure. The notion of current state is maintained by a separate StateMachine object which references a StateMachineDescription; this allows multiple instances of the state machine to run concurrently.

For best results, State objects should themselves be defined as immutable.

Author:
keith

Nested Class Summary
static class StateMachineDescription.Builder<S extends State<I>,I extends InputSource>
          Convenience class that simplifies the code required to create a StateMachineDescription.
 
Constructor Summary
StateMachineDescription(S initialState, java.util.Map<S,java.util.Map<java.lang.String,S>> transitions, boolean setStateByIdAllowed)
           
 
Method Summary
 S findNextState(S state, java.lang.String transitionValue)
          Given a State and a transition name, returns the corresponding State that would be transitioned to.
 S findStateById(java.lang.String id)
          Returns the State object with the provided id value.
 S getInitialState()
          Returns the starting State described by this StateMachineDescription.
 boolean isGoToStateByIdAllowed()
          Returns true if StateMachine objects based on this StateMachineDescription may be set directly to a state by providing a state id.
 StateMachine<S,I> newStateMachine(I inputSource)
          Creates a new StateMachine instance that uses this StateMachineDescription to define its states and transitions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateMachineDescription

public StateMachineDescription(S initialState,
                               java.util.Map<S,java.util.Map<java.lang.String,S>> transitions,
                               boolean setStateByIdAllowed)
Method Detail

getInitialState

public S getInitialState()
Returns the starting State described by this StateMachineDescription. When a StateMachine object based on this StateMachineDescription is created, its current state is set to this State.

Returns:

isGoToStateByIdAllowed

public boolean isGoToStateByIdAllowed()
Returns true if StateMachine objects based on this StateMachineDescription may be set directly to a state by providing a state id. If false, attempts to set a StateMachine's current state in that manner will throw an exception.

Returns:

findNextState

public S findNextState(S state,
                       java.lang.String transitionValue)
Given a State and a transition name, returns the corresponding State that would be transitioned to. If the transition is not defined in this StateMachineDescription, null is returned.

Parameters:
state -
transitionValue -
Returns:

findStateById

public S findStateById(java.lang.String id)
Returns the State object with the provided id value. If no matching State is found, null is returned.

Parameters:
id -
Returns:

newStateMachine

public StateMachine<S,I> newStateMachine(I inputSource)
Creates a new StateMachine instance that uses this StateMachineDescription to define its states and transitions. The new StateMachine uses the provided InputSource object to determine the state transition path.

Parameters:
inputSource -
Returns:


Copyright © 2008. All Rights Reserved.