gate.fsm
Class State

java.lang.Object
  extended by gate.fsm.State
All Implemented Interfaces:
JapeConstants, Serializable

public class State
extends Object
implements JapeConstants

This class implements a Finite State Machine state.

See Also:
Serialized Form

Field Summary
protected  RightHandSide action
          The right hand side associated to the rule for which this state recognizes the lhs.
private static boolean DEBUG
          Debug flag
protected  int fileIndex
          The index in the definition file of the rule that was used for creating this state.
protected static int index
          The class data member used for generating unique indices for State instances.
private  int indexInRuleList
           
static int INITIAL_INDEX
           
static String INITIAL_RULE
           
protected  boolean isFinal
          Is this state a final one?
protected  int myIndex
          The unique index of this state.
protected  int priority
          The priority of the rule from which this state derived.
private  SimpleArraySet<Transition> transitions
          A set of objects of type gata.fsm.Transition representing the outgoing transitions.
static int UNKNOWN_INDEX
           
static String UNKNOWN_RULE
           
static int UNVISITED_INDEX
           
static String UNVISITED_RULE
           
static int VISITED_INDEX
           
 
Fields inherited from interface gate.jape.JapeConstants
ALL_STYLE, APPELT_STYLE, BRILL_STYLE, DEFAULT_PRIORITY, FIRST_STYLE, INDENT_PADDING, KLEENE_PLUS, KLEENE_QUERY, KLEENE_STAR, MULTI_SPAN_BINDING, NO_BINDING, NO_KLEENE_OP, ONCE_STYLE, SINGLE_SPAN_BINDING
 
Constructor Summary
State()
          Build a new state.
 
Method Summary
 void addTransition(Transition transition)
          Adds a new transition to the list of outgoing transitions for this state.
 RightHandSide getAction()
          Gets the action associated to this state.
 String getEdgesGML()
          Returns a GML (graph modelling language) representation for the edges corresponding to transitions departing from this state in the transition graph of the FSM to which this state belongs
(package private)  int getFileIndex()
          Returns the index in the definition file of the rule that generated this state.
 int getIndex()
          Gets the index of this state.
 int getIndexInRuleList()
           
(package private)  int getPriority()
          Returns the priority in the definition file of the rule that generated this state.
 int getRuleForState(HashMap<String,Integer> ruleNameToIndexMap, ArrayList<RuleTime> ruleTimes)
          Sets the index of the rule for this state.
 SimpleArraySet<Transition> getTransitions()
          Gets the set of transitions for this state.
 boolean isFinal()
          Reports if this state is a final one.
private  void propogateRuleForward(int ruleForThisState)
          This sets the rule index for every descendant of the current state Note that we only need to set the state for states whose rule is Unknown Rules whose state is "VISITED_INDEX" are my ancestors.
protected  void setAction(RightHandSide rhs)
          Sets the action associated to this FINAL state.
protected  void setFileIndex(int i)
          Sets the value for fileIndex.
(package private)  void setIndexInRuleList(int indexInRuleList)
          This should only need to be called by getRuleForState when the state is being initialized
protected  void setPriority(int i)
          Sets the value for priority.
 String toString()
          Returns a textual description of this state
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
Debug flag

See Also:
Constant Field Values

UNKNOWN_INDEX

public static final int UNKNOWN_INDEX
See Also:
Constant Field Values

VISITED_INDEX

public static final int VISITED_INDEX
See Also:
Constant Field Values

UNVISITED_INDEX

public static final int UNVISITED_INDEX
See Also:
Constant Field Values

INITIAL_INDEX

public static final int INITIAL_INDEX
See Also:
Constant Field Values

INITIAL_RULE

public static final String INITIAL_RULE
See Also:
Constant Field Values

UNKNOWN_RULE

public static final String UNKNOWN_RULE
See Also:
Constant Field Values

UNVISITED_RULE

public static final String UNVISITED_RULE
See Also:
Constant Field Values

indexInRuleList

private int indexInRuleList

transitions

private SimpleArraySet<Transition> transitions
A set of objects of type gata.fsm.Transition representing the outgoing transitions.


isFinal

protected boolean isFinal
Is this state a final one?


action

protected RightHandSide action
The right hand side associated to the rule for which this state recognizes the lhs.


myIndex

protected int myIndex
The unique index of this state.


index

protected static int index
The class data member used for generating unique indices for State instances.


fileIndex

protected int fileIndex
The index in the definition file of the rule that was used for creating this state. NOTE: this member is consistent only for FINAL STATES!


priority

protected int priority
The priority of the rule from which this state derived.

Constructor Detail

State

public State()
Build a new state.

Method Detail

getIndexInRuleList

public int getIndexInRuleList()
Returns:
The index of the rule in the ruleTimes ArrayList held in the FSM

setIndexInRuleList

void setIndexInRuleList(int indexInRuleList)
This should only need to be called by getRuleForState when the state is being initialized

Parameters:
indexInRuleList -

getRuleForState

public int getRuleForState(HashMap<String,Integer> ruleNameToIndexMap,
                           ArrayList<RuleTime> ruleTimes)
Sets the index of the rule for this state. Determines the appropriate rule by recursively searching this state's outbound transitions until we reach a final state. Record this state in the ruleTimes and ruleNameToIndexMap structures

Parameters:
ruleNameToIndexMap -
ruleTimes -
Returns:

propogateRuleForward

private void propogateRuleForward(int ruleForThisState)
This sets the rule index for every descendant of the current state Note that we only need to set the state for states whose rule is Unknown Rules whose state is "VISITED_INDEX" are my ancestors. Their states will be set when the recursion backs out. Rules whose index is something other than VISITED_INDEX or UNKNOWN_RULE are finished and we know that all of their descendants have been set, by the properties of this algorithm

Parameters:
ruleForThisState - The rule to be associated with this state

isFinal

public boolean isFinal()
Reports if this state is a final one. Note: A state has an associated action if and only if it is final.


getTransitions

public SimpleArraySet<Transition> getTransitions()
Gets the set of transitions for this state.

Returns:
a Set contining objects of type gate.fsm.Transition

setAction

protected void setAction(RightHandSide rhs)
Sets the action associated to this FINAL state. An action is actually a gate.jape.RightHandSide object. NOTE: only a final state has an associated action so after a call to this method this state will be a final one.


setFileIndex

protected void setFileIndex(int i)
Sets the value for fileIndex. File index is the index in the jape definition file of the rule that contains as right hand side the action associated to this state. This value is only intended for final states.


setPriority

protected void setPriority(int i)
Sets the value for priority. Priority is the priority in the jape definition file of the rule that contains as right hand side the action associated to this state. This value is only intended for final states.


getAction

public RightHandSide getAction()
Gets the action associated to this state.

Returns:
a RightHandSide object

getFileIndex

int getFileIndex()
Returns the index in the definition file of the rule that generated this state. The value for fileIndex is correct only on final states!


getPriority

int getPriority()
Returns the priority in the definition file of the rule that generated this state. This value is correct only on final states!


addTransition

public void addTransition(Transition transition)
Adds a new transition to the list of outgoing transitions for this state.

Parameters:
transition - the transition to be added

getIndex

public int getIndex()
Gets the index of this state. Each state has a unique index (a int value). This value is not actually used by any of the algorithms. It is useful only as a way of refering to states in string representations so it is used by toString and GML related methods.

Returns:
the index associated to this state

getEdgesGML

public String getEdgesGML()
Returns a GML (graph modelling language) representation for the edges corresponding to transitions departing from this state in the transition graph of the FSM to which this state belongs

Returns:
a string value contining the GML text

toString

public String toString()
Returns a textual description of this state

Overrides:
toString in class Object
Returns:
a String value.