net.openai.util.fsm
Class Machine

java.lang.Object
  |
  +--net.openai.util.fsm.Machine
All Implemented Interfaces:
java.io.Serializable

public class Machine
extends java.lang.Object
implements java.io.Serializable

The controlling Machine class for the Finite State Machine

See Also:
Serialized Form

Constructor Summary
Machine()
          Constructs a new Machine object with no start state.
Machine(State startState)
          Constructs a new Machine object.
 
Method Summary
 void addMachineListener(MachineListener listener)
          Adds a MachineListener to this Machine that we will deliver events to.
 State getCurrentState()
          Returns the current state of this machine.
 State getStartState()
          Returns a handle to the starting state for this machine.
 void input(boolean condition)
          Convenience method to handle the boolean primitive as an input condition.
 void input(byte condition)
          Convenience method to handle the byte primitive type as an input condition.
 void input(char condition)
          Convience method to handle the char primitive type as an input condition.
 void input(double condition)
          Convience method to handle the double primitive type as an input condition.
 void input(float condition)
          Convience method to handle the float primitive type as an input condition.
 void input(int condition)
          Convience method to handle the int primitive type as an input condition.
 void input(long condition)
          Convience method to handle the long primitive type as an input condition.
 void input(java.lang.Object condition)
          Takes input and passes it to the current State.
 void input(short condition)
          Convience method to handle the Short primitive type as an input condition.
 void removeMachineListener(MachineListener listener)
          Removes a MachineListener from this Machine.
 void reset()
          Resets this machine so that its current State is the start state.
 void reset(boolean asTransition, boolean nullifyInput)
          Resets this machine so that its current State is the start state.
protected  void setCurrentState(State state)
          Forcibly sets the current state of this machine.
 void setStartState(State state)
          Sets the start state for this machine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Machine

public Machine()
Constructs a new Machine object with no start state.


Machine

public Machine(State startState)
Constructs a new Machine object.

Parameters:
startState - The State object to begin on. This must be non-null.
Method Detail

addMachineListener

public final void addMachineListener(MachineListener listener)
Adds a MachineListener to this Machine that we will deliver events to.

Parameters:
listener - The MachineListener to add.

removeMachineListener

public final void removeMachineListener(MachineListener listener)
Removes a MachineListener from this Machine.

Parameters:
listener - The MachineListener to remove.

setStartState

public final void setStartState(State state)
Sets the start state for this machine.

Parameters:
state - The new start state for this machine.

getStartState

public final State getStartState()
Returns a handle to the starting state for this machine.

Returns:
The starting state for this machine or null if one is not set.

setCurrentState

protected final void setCurrentState(State state)
Forcibly sets the current state of this machine.

NOTE: This is NOT recommended for use in general, but it is provided in case there is a need for it. No checking is done as to whether or not the state can be reached though valid transitions and any state listeners, and state IO is not performed.

Parameters:
state - The new current state.

getCurrentState

public final State getCurrentState()
Returns the current state of this machine.

Returns:
The current state of this machine.

input

public final void input(java.lang.Object condition)
                 throws UnhandledConditionException
Takes input and passes it to the current State. If the condition is met by one of the Conditions of the State, then the new current State will be that returned by the input method of the present State.

Parameters:
condition - The input to pass to the current State.
Throws:
UnhandledConditionException - If the current State returns null for its input method, then a condition has arisen that is not handled.

input

public final void input(boolean condition)
                 throws UnhandledConditionException
Convenience method to handle the boolean primitive as an input condition.

Parameters:
condition - The value to input.
UnhandledConditionException

input

public final void input(byte condition)
                 throws UnhandledConditionException
Convenience method to handle the byte primitive type as an input condition.

Parameters:
condition - The value to input.
UnhandledConditionException

input

public final void input(char condition)
                 throws UnhandledConditionException
Convience method to handle the char primitive type as an input condition.

Parameters:
condition - The value to input.
UnhandledConditionException

input

public final void input(double condition)
                 throws UnhandledConditionException
Convience method to handle the double primitive type as an input condition.

Parameters:
condition - The value to input.
UnhandledConditionException

input

public final void input(float condition)
                 throws UnhandledConditionException
Convience method to handle the float primitive type as an input condition.

Parameters:
condition - The value to input.
UnhandledConditionException

input

public final void input(int condition)
                 throws UnhandledConditionException
Convience method to handle the int primitive type as an input condition.

Parameters:
condition - The value to input.
UnhandledConditionException

input

public final void input(long condition)
                 throws UnhandledConditionException
Convience method to handle the long primitive type as an input condition.

Parameters:
condition - The value to input.
UnhandledConditionException

input

public final void input(short condition)
                 throws UnhandledConditionException
Convience method to handle the Short primitive type as an input condition.

Parameters:
condition - The value to input.
UnhandledConditionException

reset

public final void reset()
Resets this machine so that its current State is the start state. No state transitions will be fired. This is the same as calling reset(false, false).


reset

public final void reset(boolean asTransition,
                        boolean nullifyInput)
Resets this machine so that its current State is the start state. If asTransition is true then the output of the current state (if it exists) will be input into the start state and the start state will be the new current state. If it is false then the current state will simply be set to be the start state.

Parameters:
asTransition - If true then the current state and the start state will act as if there is a transition between them.
nullifyInput - If true then null will be fed into the start state instead of the output of the current state.


Copyright - 2001 OpenAI Labs. All Rights Reserved.