scanner
Class State

java.lang.Object
  extended byscanner.State
All Implemented Interfaces:
java.lang.Cloneable

public class State
extends java.lang.Object
implements java.lang.Cloneable

This class defines states used in finale state automata.


Constructor Summary
State(TokenType type, boolean isTokenStateValue)
          Constructs a new state.
 
Method Summary
 void addTransition(Transition transition)
          Adds a transition to this state.
 java.lang.Object clone()
           
 int countTransitions()
          Returns the number of transitions from this state.
 Transition getTransitionFor(char character)
          Returns the transition that can be activated for the specified character.
 Transition[] getTransitions()
          Returns an array containing transitions from this state.
 TokenType getType()
          Returns the type of this state.
 boolean hasSelfTransitions()
          Returns true if this state has self transitions.
 boolean isTokenState()
          Returns true if this state is a token state.
 boolean removeTransition(Transition transition)
          Removes the given transition.
 void setTokenState(boolean isToken)
          Sets if this state is a token state or not.
 void setType(TokenType type)
          Sets the type of this state.
 java.lang.String toString()
           
 State union(State state)
          Performs an union between this state and the given one.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

State

public State(TokenType type,
             boolean isTokenStateValue)
Constructs a new state.

Parameters:
type - The type of the state.
isTokenStateValue - true if the state is a token state, falsew otherwise.
Method Detail

getType

public TokenType getType()
Returns the type of this state.

Returns:
The type of this state.

getTransitions

public Transition[] getTransitions()
Returns an array containing transitions from this state.

Returns:
an array containing transitions from this state.

getTransitionFor

public Transition getTransitionFor(char character)
Returns the transition that can be activated for the specified character.

Parameters:
character - A character.
Returns:
The transition that can be activated for the specified character. null is returned if no transition is specified from this state for the given character.

hasSelfTransitions

public boolean hasSelfTransitions()
Returns true if this state has self transitions. A self transition is a transition whose target state is equals to the source state.

Returns:
true if this state has self transitions, false otherwise.

countTransitions

public int countTransitions()
Returns the number of transitions from this state.

Returns:
the number of transitions from this state.

setType

public void setType(TokenType type)
Sets the type of this state.

Parameters:
type - The new type of this state.

setTokenState

public void setTokenState(boolean isToken)
Sets if this state is a token state or not.

Parameters:
isToken - true if this state is a token state, false otherwise.

isTokenState

public boolean isTokenState()
Returns true if this state is a token state.

Returns:
true if this state is a token state, false otherwise.

addTransition

public void addTransition(Transition transition)
Adds a transition to this state.

Parameters:
transition - The transition to be added to this state.
See Also:
removeTransition(scanner.Transition)

removeTransition

public boolean removeTransition(Transition transition)
Removes the given transition.

Parameters:
transition - The transition to be removed.
Returns:
true if the given transition was one of this state's transition, false otherwise.
See Also:
addTransition(scanner.Transition)

union

public State union(State state)
Performs an union between this state and the given one. Union between a token state and a non token state will give a token state. Union between 2 non token states will give a non token state. Union between 2 token states is possible only if only one of them has self transitions. Union between 2 token states that both have self transitions will throw a runtime exception. Union between 2 token states that both haven't any self transition will return the state given as paremeter

Parameters:
state - a State
Returns:
State The resulting union from this state and the given one.

clone

public java.lang.Object clone()

toString

public java.lang.String toString()