org.jscience.computing.automaton
Class RunAutomaton

java.lang.Object
  extended by org.jscience.computing.automaton.RunAutomaton
All Implemented Interfaces:
java.io.Serializable

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

Finite-state automaton with fast run operation.

See Also:
Serialized Form

Constructor Summary
RunAutomaton(Automaton a)
          Constructs a new RunAutomaton from a deterministic Automaton.
RunAutomaton(Automaton a, boolean tableize)
          Constructs a new RunAutomaton from a deterministic Automaton.
 
Method Summary
 char[] getCharIntervals()
          Returns array of character class interval start points.
 int getInitialState()
          Returns initial state.
 int getSize()
          Returns number of states in automaton.
 boolean isAccept(int state)
          Returns acceptance status for given state.
static RunAutomaton load(java.io.InputStream stream)
          Retrieves a serialized RunAutomaton from a stream.
static RunAutomaton load(java.net.URL url)
          Retrieves a serialized RunAutomaton located by a URL.
 boolean run(java.lang.String s)
          Returns true if the given string is accepted by this automaton.
 int run(java.lang.String s, int offset)
          Returns the length of the longest accepted run of the given string starting at the given offset.
 int step(int state, char c)
          Returns the state obtained by reading the given char from the given state.
 void store(java.io.OutputStream stream)
          Writes this RunAutomaton to the given stream.
 java.lang.String toString()
          Returns a string representation of this automaton.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RunAutomaton

public RunAutomaton(Automaton a)
Constructs a new RunAutomaton from a deterministic Automaton. Same as RunAutomaton(a, true).

Parameters:
a - an automaton

RunAutomaton

public RunAutomaton(Automaton a,
                    boolean tableize)
Constructs a new RunAutomaton from a deterministic Automaton. If the given automaton is not deterministic, it is determinized first.

Parameters:
a - an automaton
tableize - if true, a transition table is created which makes the run method faster in return of a higher memory usage
Method Detail

toString

public java.lang.String toString()
Returns a string representation of this automaton.

Overrides:
toString in class java.lang.Object
Returns:
DOCUMENT ME!

getSize

public int getSize()
Returns number of states in automaton.

Returns:
DOCUMENT ME!

isAccept

public boolean isAccept(int state)
Returns acceptance status for given state.

Parameters:
state - DOCUMENT ME!
Returns:
DOCUMENT ME!

getInitialState

public int getInitialState()
Returns initial state.

Returns:
DOCUMENT ME!

getCharIntervals

public char[] getCharIntervals()
Returns array of character class interval start points. The array should not be modified by the caller.

Returns:
DOCUMENT ME!

load

public static RunAutomaton load(java.net.URL url)
                         throws java.io.IOException,
                                java.io.OptionalDataException,
                                java.lang.ClassCastException,
                                java.lang.ClassNotFoundException,
                                java.io.InvalidClassException
Retrieves a serialized RunAutomaton located by a URL.

Parameters:
url - URL of serialized automaton
Returns:
DOCUMENT ME!
Throws:
java.io.IOException - if input/output related exception occurs
java.io.OptionalDataException - if the data is not a serialized object
java.lang.ClassCastException - if the data is not a serialized RunAutomaton
java.lang.ClassNotFoundException - if the class of the serialized object cannot be found
java.io.InvalidClassException - if the class serial number does not match

load

public static RunAutomaton load(java.io.InputStream stream)
                         throws java.io.IOException,
                                java.io.OptionalDataException,
                                java.lang.ClassCastException,
                                java.lang.ClassNotFoundException,
                                java.io.InvalidClassException
Retrieves a serialized RunAutomaton from a stream.

Parameters:
stream - input stream with serialized automaton
Returns:
DOCUMENT ME!
Throws:
java.io.IOException - if input/output related exception occurs
java.io.OptionalDataException - if the data is not a serialized object
java.lang.ClassCastException - if the data is not a serialized RunAutomaton
java.lang.ClassNotFoundException - if the class of the serialized object cannot be found
java.io.InvalidClassException - if the class serial number does not match

store

public void store(java.io.OutputStream stream)
           throws java.io.IOException
Writes this RunAutomaton to the given stream.

Parameters:
stream - output stream for serialized automaton
Throws:
java.io.IOException - if input/output related exception occurs

step

public int step(int state,
                char c)
Returns the state obtained by reading the given char from the given state. Returns -1 if not obtaining any such state. (If the original Automaton had no dead states, -1 is returned here if and only if a dead state is entered in an equivalent automaton with a total transition function.)

Parameters:
state - DOCUMENT ME!
c - DOCUMENT ME!
Returns:
DOCUMENT ME!

run

public boolean run(java.lang.String s)
Returns true if the given string is accepted by this automaton.

Parameters:
s - DOCUMENT ME!
Returns:
DOCUMENT ME!

run

public int run(java.lang.String s,
               int offset)
Returns the length of the longest accepted run of the given string starting at the given offset.

Parameters:
s - the string
offset - offset into s where the run starts
Returns:
length of the longest accepted run, -1 if no run is accepted