public class Dfa
extends java.lang.Object
implements java.io.Serializable
Nfa
, objects of this class do not allow operations
which change the automaton structure. But only a Dfa
can be operated by a DfaRun
to filter text. This makes
sure that the automaton structure is not changed while a
DfaRun
is working with it.
A Dfa
can only be created by calling one of the
Nfa.compile()
methods. It can only be used for matching by
operating it in a DfaRun
object. To apply
automata-operations again, it is necessary to copy it into a
Nfa
again with toNfa()
.
Warning: The intention of separating
the data structure encapsulated in a Dfa
from the
machinery to run it, i.e. DfaRun
, is that
Dfa
objects shall be shareable between threads. For
this to work, however, make sure that each FaAction
used in
the Dfa
has either no internal state or is
synchronized. To pass data between actions, use DfaRun.clientData
.
Modifier and Type | Field and Description |
---|---|
long |
matchMax
maximum length a match can have.
|
Modifier and Type | Method and Description |
---|---|
DfaRun |
createRun()
convenience function to get a
DfaRun for this
automaton. |
FaAction |
match(CharSource in,
java.lang.StringBuilder out,
TextStore subMatches)
determine a matching prefix of
in and deliver
respective data. |
boolean |
matchesEmpty()
returns
true if this automaton can match the empty
string. |
void |
toDot(java.io.PrintStream out)
prints a graph representation of the Dfa in the
graphviz format. |
void |
toDot(java.lang.String filename) |
Nfa |
toNfa()
converts the
Dfa back into an Nfa in a way
that this is totally useless afterwards. |
public long matchMax
maximum length a match can have. If the value is greater zero,
no match found by this object will be longer. If
matchMax
is left at its default -1, the longest
match found will be no longer than 264 characters, which is probably long
after you ran out of memory.
public boolean matchesEmpty()
returns true
if this automaton can match the empty
string. If this
can match the empty string, it
should better not be used with a DfaRun
because many
methods of DfaRun
will be likely to enter an
infinite loop.
public DfaRun createRun()
convenience function to get a DfaRun
for this
automaton.
public Nfa toNfa()
converts the Dfa
back into an Nfa
in a way
that this
is totally useless afterwards. Make sure it is
not used somewhere else meanwhile. The approach was taken for efficiency
reasons. A deep copy operation is not implemented.
Nfa
containing all Dfa
nodes plus a
common stop state required by the Nfa
data
structure.public void toDot(java.io.PrintStream out)
graphviz
format.public void toDot(java.lang.String filename)
public FaAction match(CharSource in, java.lang.StringBuilder out, TextStore subMatches) throws java.io.IOException
determine a matching prefix of in
and deliver
respective data. If in
can be matched by the
Dfa
the matching text is appended to
out
and the associated action is returned. If
subMatches
is not null
, the submatches,
if any, are analyzed and provided in subMatches
after first clearing it.
subMatches
- may be null, if no submatch analysis is
requested.null
if no match was found.java.io.IOException