public class Automaton extends Object implements Cloneable
Class invariants:
State
and
Transition
objects) or with a singleton string (see
getSingleton()
and expandSingleton()
) in case the automaton
is known to accept exactly one string. (Implicitly, all states and
transitions of an automaton are reachable from its initial state.)
reduce()
) and have no
transitions to dead states (see removeDeadTransitions()
).
isDeterministic()
returns false (but the converse is not required).
If the states or transitions are manipulated manually, the
restoreInvariant()
and setDeterministic(boolean)
methods
should be used afterwards to restore representation invariants that are
assumed by the built-in automata operations.
Note: This class has internal mutable state and is not thread safe. It is
the caller's responsibility to ensure any necessary synchronization if you
wish to use the same Automaton from multiple threads. In general it is instead
recommended to use a RunAutomaton
for multithreaded matching: it is immutable,
thread safe, and much faster.
Modifier and Type | Field and Description |
---|---|
static int |
MINIMIZE_HOPCROFT
Minimize using Hopcroft's O(n log n) algorithm.
|
Constructor and Description |
---|
Automaton() |
Automaton(State initial)
Constructs a new automaton that accepts the empty language.
|
Modifier and Type | Method and Description |
---|---|
void |
clearNumberedStates() |
Automaton |
clone()
Returns a clone of this automaton.
|
Automaton |
complement()
|
Automaton |
concatenate(Automaton a)
|
static Automaton |
concatenate(List<Automaton> l)
|
void |
determinize()
|
boolean |
equals(Object obj) |
void |
expandSingleton()
Expands singleton representation to normal representation.
|
Set<State> |
getAcceptStates()
Returns the set of reachable accept states.
|
Object |
getInfo()
Returns extra information associated with this automaton.
|
State |
getInitialState()
Gets initial state.
|
State[] |
getNumberedStates() |
int |
getNumberOfStates()
Returns the number of states in this automaton.
|
int |
getNumberOfTransitions()
Returns the number of transitions in this automaton.
|
String |
getSingleton()
Returns the singleton string for this automaton.
|
Transition[][] |
getSortedTransitions()
Returns a sorted array of transitions for each state (and sets state
numbers).
|
int |
hashCode() |
Automaton |
intersection(Automaton a)
|
boolean |
isDeterministic()
Returns deterministic flag for this automaton.
|
boolean |
isEmptyString()
|
static Automaton |
minimize(Automaton a)
|
Automaton |
minus(Automaton a)
|
Automaton |
optional()
|
void |
reduce()
Reduces this automaton.
|
void |
removeDeadTransitions()
Removes transitions to dead states and calls
reduce() . |
Automaton |
repeat()
|
Automaton |
repeat(int min)
|
Automaton |
repeat(int min,
int max)
|
void |
restoreInvariant()
Restores representation invariant.
|
static boolean |
setAllowMutate(boolean flag)
Sets or resets allow mutate flag.
|
void |
setDeterministic(boolean deterministic)
Sets deterministic flag for this automaton.
|
void |
setInfo(Object info)
Associates extra information with this automaton.
|
static void |
setMinimization(int algorithm)
Selects minimization algorithm (default:
MINIMIZE_HOPCROFT ). |
static void |
setMinimizeAlways(boolean flag)
Sets or resets minimize always flag.
|
void |
setNumberedStates(State[] states) |
void |
setNumberedStates(State[] states,
int count) |
boolean |
subsetOf(Automaton a)
|
String |
toDot()
Returns Graphviz Dot representation of this automaton.
|
String |
toString()
Returns a string representation of this automaton.
|
Automaton |
union(Automaton a)
|
static Automaton |
union(Collection<Automaton> l)
|
public static final int MINIMIZE_HOPCROFT
setMinimization(int)
,
Constant Field Valuespublic Automaton(State initial)
State
and
Transition
objects.State
,
Transition
public Automaton()
public static void setMinimization(int algorithm)
MINIMIZE_HOPCROFT
).algorithm
- minimization algorithmpublic static void setMinimizeAlways(boolean flag)
MinimizationOperations.minimize(Automaton)
will automatically be
invoked after all operations that otherwise may produce non-minimal
automata. By default, the flag is not set.flag
- if true, the flag is setpublic static boolean setAllowMutate(boolean flag)
flag
- if true, the flag is setpublic String getSingleton()
public State getInitialState()
public boolean isDeterministic()
public void setDeterministic(boolean deterministic)
deterministic
- true if the automaton is definitely deterministic,
false if the automaton may be nondeterministicpublic void setInfo(Object info)
info
- extra informationpublic Object getInfo()
setInfo(Object)
public State[] getNumberedStates()
public void setNumberedStates(State[] states)
public void setNumberedStates(State[] states, int count)
public void clearNumberedStates()
public Set<State> getAcceptStates()
State
objectspublic void restoreInvariant()
setDeterministic(boolean)
public void reduce()
public void removeDeadTransitions()
reduce()
.
(A state is "dead" if no accept state is
reachable from it.)public Transition[][] getSortedTransitions()
public void expandSingleton()
public int getNumberOfStates()
public int getNumberOfTransitions()
public String toString()
public String toDot()
public Automaton optional()
public Automaton repeat()
public Automaton repeat(int min)
public Automaton repeat(int min, int max)
public Automaton complement()
public boolean subsetOf(Automaton a)
public static Automaton union(Collection<Automaton> l)
public void determinize()
public boolean isEmptyString()
public static Automaton minimize(Automaton a)
MinimizationOperations.minimize(Automaton)
. Returns the
automaton being given as argument.Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.