com.karneim.util.collection.set
public class SAutomaton extends Object
import com.karneim.util.collection.set.*;
public class Test {
public static void main(String[] args) {
SAutomaton automaton = new SAutomaton();
IStatePro s1 = automaton.addState(false);
IStatePro s2 = automaton.addState(true);
s1.addTransition(new CharSet("0123456789"),s2);
s2.addTransition(new CharSet("0123456789"),s2);
automaton.setStartState(s1);
}
}
final IStatePro startState = automaton.getStartState();
final StateProSet states = new StateProSet(startState);
final Iterator it = states.iterator();
for (IStatePro state=it.next(); state!=null; state=it.next()) {
IStatePro.ITransition[] transitions = state.getTransitions();
for (int i=0; i transitions.length; ++i) {
states.add(transitions[i].getToState());
System.out.println(
"from " + transitions[i].getFromState()
+ " through " + transitions[i].getCharSet()
+ " to " + transitions[i].getToState()
);
}
}
/**
* returns true if input is an existing path through automaton's states
* otherwise false.
*
public static boolean incompleteMatch(SAutomaton automaton,String input) {
IState current = automaton.getStartState().visit();
for (int i=0; i input.length(); ++i) {
current = current.next(input.charAt(i));
if (current == null) return false;
}
return true;
}
Version: 1.0
| Nested Class Summary | |
|---|---|
| interface | SAutomaton.IChangeListener
The listener interface for receiving change events of a SAutomaton.
|
| protected class | SAutomaton.State |
| protected class | SAutomaton.StatePro |
| protected class | SAutomaton.Transition |
| Field Summary | |
|---|---|
| protected AutomatonSet_String | automaton |
| protected Automaton.IChangedListener | automatonChangedListener |
| protected LinkedList | listeners |
| protected HashMap | state2wrapper |
| protected HashMap | transition2wrapper |
| Constructor Summary | |
|---|---|
| SAutomaton()
Creates a new empty automaton | |
| SAutomaton(FSAData data) | |
| SAutomaton(InputStream automatonDataStream) | |
| protected | SAutomaton(AutomatonSet_String automaton) |
| Method Summary | |
|---|---|
| void | addAll(SAutomaton automaton) |
| void | addChangeListener(SAutomaton.IChangeListener listener)
Adds the specified listener to receive change events from this automaton.
|
| IStatePro | addState()
Adds a new non final state to this automaton. |
| IStatePro | addState(boolean isFinal)
Adds a new final or non final state to this automaton. |
| void | clear()
Removes all states of this automaton. |
| void | complement() |
| protected Automaton.IChangedListener | getAutomatonChangedListener() |
| IStatePro | getStartState()
Returns the current start state of the automaton.
important: The result is null, if and only if the current start state is null |
| StateProSet | getStates()
Returns all states of this automaton whatever they are reachable through the current start state or not. |
| protected void | init(FSAData a) |
| boolean | isDeterministic() |
| void | minimize()
Minimizes this automaton as much as possible.
|
| void | removeAll(SAutomaton automaton) |
| boolean | removeChangeListener(SAutomaton.IChangeListener listener)
Removes the specified listener so that it no longer receives change events from this automaton.
|
| boolean | removeState(IStatePro state)
Removes the specified state from this automaton.
|
| void | retainAll(SAutomaton automaton) |
| void | setStartState(IStatePro state)
Sets the automaton's start state to the specified state.
|
| FSAData | toData() |
| void | toData(OutputStream automatonDataStream) |
| protected static FSAData | toFSAData(Object obj) |
| String | toString() |
Returns: a new state
Returns: a new state
Returns: the current start state of the automaton
Returns:
Parameters: listener
Returns: true if the listener was registered else false
UNKNOWN: IllegalArgumentException - if null is passed as listener
Parameters: state
Returns: true if this automaton owns the specified state else false
Parameters: state