org.jscience.computing.automaton.machines
Class FSM.State

java.lang.Object
  extended by org.jscience.computing.automaton.machines.FSM.State
Direct Known Subclasses:
TuringMachine.Transition
Enclosing class:
FSM

public static class FSM.State
extends java.lang.Object

The FSM states. The default FSM State simply stores a hash table with transitions along with a state name.


Field Summary
protected  double positionX
          The X-position of the state.
protected  double positionY
          The Y-position of the state.
protected  boolean selfReferring
          Specifies whether this FSM node is self-referential.
protected  java.lang.String stateName
          The name of the state.
protected  java.util.Hashtable transitionHash
          The hash table that stores the transitions.
 
Constructor Summary
FSM.State()
          Create a new instance of State.
FSM.State(java.lang.String name)
          Create a new instance of State, with the state name.
FSM.State(java.lang.String name, double x, double y)
          Create a new instance of the State with name and positional information.
 
Method Summary
 void addTransition(int transition, FSM.State endState)
          Add a transition to the state.
 double getPositionX()
          Retrieve the x-position of the state.
 double getPositionY()
          Retrieve the y-position of the state.
 boolean isSelfReferring()
          Is this node self-referential?
 void render(java.awt.Graphics g, int width, int height, int size)
          Renders the state.
 void renderConnections(java.awt.Graphics g, int width, int height, int size)
          Render the connections from this state.
 void setName(java.lang.String name)
          Set the name of the state post-construction.
 void setPosition(double x, double y)
          Set the position of the state.
 void setSelfReferring(boolean sr)
          Sets whether the node is self-referential or not.
 java.lang.String toString()
          Returns the name of the state.
 FSM.State transition(int transition)
          Transition this state given the transition identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

stateName

protected java.lang.String stateName
The name of the state.


transitionHash

protected java.util.Hashtable transitionHash
The hash table that stores the transitions.


positionX

protected double positionX
The X-position of the state.


positionY

protected double positionY
The Y-position of the state.


selfReferring

protected boolean selfReferring
Specifies whether this FSM node is self-referential. This is required for rendering purposes only.

Constructor Detail

FSM.State

public FSM.State()
Create a new instance of State. Set the name to an empty string.


FSM.State

public FSM.State(java.lang.String name)
Create a new instance of State, with the state name.

Parameters:
name - the state name.

FSM.State

public FSM.State(java.lang.String name,
                 double x,
                 double y)
Create a new instance of the State with name and positional information.

Parameters:
name - the state name.
x - the x-position of the state.
y - the y-position of the state.
Method Detail

setName

public void setName(java.lang.String name)
Set the name of the state post-construction.

Parameters:
name - the name of the state.

isSelfReferring

public boolean isSelfReferring()
Is this node self-referential?

Returns:
Return whether the node is self-referential.

setSelfReferring

public void setSelfReferring(boolean sr)
Sets whether the node is self-referential or not.

Parameters:
sr - true if self-referential, otherwise false.

addTransition

public void addTransition(int transition,
                          FSM.State endState)
Add a transition to the state.

Parameters:
transition - the transition identifier.
endState - the end state.

transition

public FSM.State transition(int transition)
Transition this state given the transition identifier. Note that the state itself does not make any sort of transition, but returns the new state for the FSM to handle. If the given transition is not defined, null is returned.

Parameters:
transition - the transition identifier.
Returns:
the resultant state.

toString

public java.lang.String toString()
Returns the name of the state.

Overrides:
toString in class java.lang.Object
Returns:
the name of the state.

setPosition

public void setPosition(double x,
                        double y)
Set the position of the state. An IllegalArgumentException will be thrown if either position is less than 0.0 or greater than 1.0.

Parameters:
x - the x-position of the state.
y - the y-position of the state.
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

getPositionX

public double getPositionX()
Retrieve the x-position of the state.

Returns:
the x-position.

getPositionY

public double getPositionY()
Retrieve the y-position of the state.

Returns:
the y-position.

renderConnections

public void renderConnections(java.awt.Graphics g,
                              int width,
                              int height,
                              int size)
Render the connections from this state.

Parameters:
g - the graphics context.
width - the width of the context.
height - the height of the context.
size - the size of the states.

render

public void render(java.awt.Graphics g,
                   int width,
                   int height,
                   int size)
Renders the state. State positions must be specified in the construction of the state or by setPosition. Positions are specified using a double between 0.0 and 1.0 (for example, setPosition(0.5, 0.5) will render the state in the centre of the graphics context).

Parameters:
g - the graphics context.
width - the width of the context.
height - the height of the context.
size - the size of the state.