datastructure
Class FiniteStateMachine

java.lang.Object
  extended by datastructure.FiniteStateMachine

public class FiniteStateMachine
extends java.lang.Object

This class represents a finite state machine FSM = where

As can be seen, the class is very similar to the mathematical construct, the only difference being the transitions and alphabet which are not globally defined in a transition function, but locally in the transitioning states themselves.

Author:
Leopold Haller

Constructor Summary
FiniteStateMachine()
           
 
Method Summary
 boolean accepts(java.lang.String... s)
          Checks whether the FSM accepts the given input.
 java.lang.Object clone()
          Makes a deep copy of the FSM
 FiniteStateMachine complement()
           
 State createState(java.lang.String name, StateType type)
          Creates a new State of the specified type in the fsm.
 java.util.ArrayList<State> getFinalStates()
           
 java.util.ArrayList<State> getInitialStates()
           
 java.util.ArrayList<State> getStates()
           
 FiniteStateMachine product(FiniteStateMachine fsm)
           
 boolean removeState(State s)
          Removes a state (also initial state and final state) from the FSM.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FiniteStateMachine

public FiniteStateMachine()
Method Detail

createState

public State createState(java.lang.String name,
                         StateType type)
Creates a new State of the specified type in the fsm. States implement comparable based on their name, no two states of the same name should be added.
BEWARE: For performance reasons this is not checked for at runtime, so this can lead to unexpected behaviour and a lot of methods will not work.

Parameters:
name - The name of the state to add, read BEWARE-information above
type - An enumeration giving the type of the State, either NORMAL_STATE,INITIAL_STATE,FINAL_STATE or INITIAL_FINAL_STATE
Returns:
The state that was created

removeState

public boolean removeState(State s)
Removes a state (also initial state and final state) from the FSM. States that were originally automatically added, because they were connected to the removed state are not removed.

Parameters:
s - The state to be removed. May not be null.
Returns:
True if s is a valid state.

getStates

public java.util.ArrayList<State> getStates()

getInitialStates

public java.util.ArrayList<State> getInitialStates()

getFinalStates

public java.util.ArrayList<State> getFinalStates()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

accepts

public boolean accepts(java.lang.String... s)
Checks whether the FSM accepts the given input.

Parameters:
s - the input
Returns:
True if the given sequence of transformations ends at a final state, false otherwise

product

public FiniteStateMachine product(FiniteStateMachine fsm)

complement

public FiniteStateMachine complement()

clone

public java.lang.Object clone()
Makes a deep copy of the FSM

Overrides:
clone in class java.lang.Object