Package dk.brics.automaton
Class RunAutomaton
- java.lang.Object
-
- dk.brics.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
-
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean[]
accept
(package private) int[]
classmap
(package private) int
initial
(package private) char[]
points
(package private) static long
serialVersionUID
(package private) int
size
(package private) int[]
transitions
-
Constructor Summary
Constructors Modifier Constructor Description private
RunAutomaton()
RunAutomaton(Automaton a)
Constructs a newRunAutomaton
from a deterministicAutomaton
.RunAutomaton(Automaton a, boolean tableize)
Constructs a newRunAutomaton
from a deterministicAutomaton
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) int
getCharClass(char c)
Gets character class of given char.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 serializedRunAutomaton
from a stream.static RunAutomaton
load(java.net.URL url)
Retrieves a serializedRunAutomaton
located by a URL.AutomatonMatcher
newMatcher(java.lang.CharSequence s)
Creates a new automaton matcher for the given input.AutomatonMatcher
newMatcher(java.lang.CharSequence s, int startOffset, int endOffset)
Creates a new automaton matcher for the given input.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.(package private) void
setAlphabet()
Sets alphabet table for optimal run performance.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 thisRunAutomaton
to the given stream.java.lang.String
toString()
Returns a string representation of this automaton.
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
- See Also:
- Constant Field Values
-
size
int size
-
accept
boolean[] accept
-
initial
int initial
-
transitions
int[] transitions
-
points
char[] points
-
classmap
int[] classmap
-
-
Constructor Detail
-
RunAutomaton
private RunAutomaton()
-
RunAutomaton
public RunAutomaton(Automaton a)
Constructs a newRunAutomaton
from a deterministicAutomaton
. Same asRunAutomaton(a, true)
.- Parameters:
a
- an automaton
-
RunAutomaton
public RunAutomaton(Automaton a, boolean tableize)
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 Detail
-
setAlphabet
void setAlphabet()
Sets alphabet table for optimal run performance.
-
toString
public java.lang.String toString()
Returns a string representation of this automaton.- Overrides:
toString
in classjava.lang.Object
-
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.
-
getCharClass
int getCharClass(char c)
Gets character class of given char.
-
load
public static RunAutomaton load(java.net.URL url) throws java.io.IOException, java.lang.ClassCastException, java.lang.ClassNotFoundException
Retrieves a serializedRunAutomaton
located by a URL.- Parameters:
url
- URL of serialized automaton- Throws:
java.io.IOException
- if input/output related exception occursjava.lang.ClassCastException
- if the data is not a serializedRunAutomaton
java.lang.ClassNotFoundException
- if the class of the serialized object cannot be found
-
load
public static RunAutomaton load(java.io.InputStream stream) throws java.io.IOException, java.lang.ClassCastException, java.lang.ClassNotFoundException
Retrieves a serializedRunAutomaton
from a stream.- Parameters:
stream
- input stream with serialized automaton- Throws:
java.io.IOException
- if input/output related exception occursjava.lang.ClassCastException
- if the data is not a serializedRunAutomaton
java.lang.ClassNotFoundException
- if the class of the serialized object cannot be found
-
store
public void store(java.io.OutputStream stream) throws java.io.IOException
Writes thisRunAutomaton
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 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
public boolean run(java.lang.String s)
Returns true if the given string is accepted by this automaton.
-
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 stringoffset
- offset intos
where the run starts- Returns:
- length of the longest accepted run, -1 if no run is accepted
-
newMatcher
public AutomatonMatcher newMatcher(java.lang.CharSequence s)
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
public AutomatonMatcher newMatcher(java.lang.CharSequence s, int startOffset, int endOffset)
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
-
-