Package dk.brics.automaton
Class RunAutomaton
java.lang.Object
dk.brics.automaton.RunAutomaton
- All Implemented Interfaces:
Serializable
Finite-state automaton with fast run operation.
- Author:
- Anders Møller <amoeller@cs.au.dk>
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newRunAutomaton
from a deterministicAutomaton
.RunAutomaton
(Automaton a, boolean tableize) Constructs a newRunAutomaton
from a deterministicAutomaton
. -
Method Summary
Modifier and TypeMethodDescriptionchar[]
Returns array of character class interval start points.int
Returns initial state.int
getSize()
Returns number of states in automaton.boolean
isAccept
(int state) Returns acceptance status for given state.static RunAutomaton
load
(InputStream stream) Retrieves a serializedRunAutomaton
from a stream.static RunAutomaton
Retrieves a serializedRunAutomaton
located by a URL.Creates a new automaton matcher for the given input.newMatcher
(CharSequence s, int startOffset, int endOffset) Creates a new automaton matcher for the given input.boolean
Returns true if the given string is accepted by this automaton.int
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
(OutputStream stream) Writes thisRunAutomaton
to the given stream.toString()
Returns a string representation of this automaton.
-
Constructor Details
-
RunAutomaton
Constructs a newRunAutomaton
from a deterministicAutomaton
. Same asRunAutomaton(a, true)
.- Parameters:
a
- an automaton
-
RunAutomaton
Constructs a newRunAutomaton
from a deterministicAutomaton
. If the given automaton is not deterministic, it is determinized first.- Parameters:
a
- an automatontableize
- if true, a transition table is created which makes therun
method faster in return of a higher memory usage
-
-
Method Details
-
toString
Returns a string representation of this automaton. -
getSize
public int getSize()Returns number of states in automaton. -
isAccept
public boolean isAccept(int state) Returns acceptance status for given state. -
getInitialState
public int getInitialState()Returns initial state. -
getCharIntervals
public char[] getCharIntervals()Returns array of character class interval start points. The array should not be modified by the caller. -
load
public static RunAutomaton load(URL url) throws IOException, OptionalDataException, ClassCastException, ClassNotFoundException, InvalidClassException Retrieves a serializedRunAutomaton
located by a URL.- Parameters:
url
- URL of serialized automaton- Throws:
IOException
- if input/output related exception occursOptionalDataException
- if the data is not a serialized objectInvalidClassException
- if the class serial number does not matchClassCastException
- if the data is not a serializedRunAutomaton
ClassNotFoundException
- if the class of the serialized object cannot be found
-
load
public static RunAutomaton load(InputStream stream) throws IOException, OptionalDataException, ClassCastException, ClassNotFoundException, InvalidClassException Retrieves a serializedRunAutomaton
from a stream.- Parameters:
stream
- input stream with serialized automaton- Throws:
IOException
- if input/output related exception occursOptionalDataException
- if the data is not a serialized objectInvalidClassException
- if the class serial number does not matchClassCastException
- if the data is not a serializedRunAutomaton
ClassNotFoundException
- if the class of the serialized object cannot be found
-
store
Writes thisRunAutomaton
to the given stream.- Parameters:
stream
- output stream for serialized automaton- Throws:
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 originalAutomaton
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.) -
run
Returns true if the given string is accepted by this automaton. -
run
Returns the length of the longest accepted run of the given string starting at the given offset.- Parameters:
s
- the stringoffset
- offset intos
where the run starts- Returns:
- length of the longest accepted run, -1 if no run is accepted
-
newMatcher
Creates a new automaton matcher for the given input.- Parameters:
s
- the CharSequence to search- Returns:
- A new automaton matcher for the given input
-
newMatcher
Creates a new automaton matcher for the given input.- Parameters:
s
- the CharSequence to searchstartOffset
- the starting offset of the given character sequenceendOffset
- the ending offset of the given character sequence- Returns:
- A new automaton matcher for the given input
-