001: /*
002: * 01/07/2003 - 15:19:32
003: *
004: * IStatePro.java -
005: * Copyright (C) 2003 Buero fuer Softwarearchitektur GbR
006: * ralf.meyer@karneim.com
007: * http://jrexx.sf.net
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
022: */
023: package com.tc.jrexx.set;
024:
025: import com.tc.jrexx.set.ISet_char;
026:
027: /**
028: * This interface represents a state of an automaton created via the automaton's addState method.
029: * <p>Copyright: Copyright (c) 2002</p>
030: * <p>Company: Büro für Softwarearchitektur www.karneim.com</p>
031: * @author Ralf Meyer
032: * @version 1.0
033: */
034: public interface IStatePro {
035: public interface ITransition {
036: public IStatePro getFromState();
037:
038: public ISet_char getCharSet();
039:
040: public IStatePro getToState();
041: }
042:
043: /**
044: * The listener interface for receiving visit events of an IStatePro.
045: * The class that is interested in processing a state's visit event implements this interface.
046: * A listener instance of that class is registered with the state using the state's addVisitListener method.
047: * <br>A state will be visited every time it is the destination state of a transition that has been visited.
048: * <br>A state that becomes visited, will then visit all its epsilon transitions
049: * and these transitions will visit all destination states and so on.
050: * <br>State visiting occurs using the methods
051: * <br>IStatePro.visit
052: * <br>IState.next
053: *
054: * <p>Copyright: Copyright (c) 2002</p>
055: * <p>Company: Büro für Softwarearchitektur www.karneim.com</p>
056: * @author Ralf Meyer
057: * @version 1.0
058: */
059: public interface IVisitListener {
060:
061: /**
062: * The state invokes this method on all registered listener if it is visited through an epsilon transition.
063: * @param state
064: */
065: public void stateVisited(IStatePro state);
066:
067: /**
068: * The state invokes this method on all registered listener if it is visited through an transition with char ch.
069: */
070: public void stateVisited(IStatePro state, char ch);
071:
072: public void stateUnVisited(IStatePro state);
073: }
074:
075: /**
076: * The listener interface for receiving change events of an IStatePro.
077: * The class that is interested in processing a state's change event implements this interface.
078: * A listener instance of that class is registered with the state using the state's addChangeListener method.
079: * <p>Copyright: Copyright (c) 2002</p>
080: * <p>Company: Büro für Softwarearchitektur www.karneim.com</p>
081: * @author Ralf Meyer
082: * @version 1.0
083: */
084: public interface IChangeListener {
085: /**
086: * The state invokes this method on all registered listener if a transition is added to the state
087: */
088: public void transitionAdded(IStatePro.ITransition transition);
089:
090: /**
091: * The state invokes this method on all registered listener if a transition is removed from the state
092: */
093: public void transitionRemoved(IStatePro.ITransition transition);
094:
095: /**
096: * The state invokes this method on all registered listener if it's final property is changed.
097: */
098: public void isFinalChanged(IStatePro state, boolean isFinal);
099: }
100:
101: public void addVisitListener(IStatePro.IVisitListener listener);
102:
103: public boolean removeVisitListener(IStatePro.IVisitListener listener);
104:
105: public void addChangeListener(IStatePro.IChangeListener listener);
106:
107: public boolean removeChangeListener(
108: IStatePro.IChangeListener listener);
109:
110: /**
111: * @return true if the state is a final state else false
112: */
113: public boolean isFinal();
114:
115: /**
116: * Makes this state final or non final.
117: */
118: public void setFinal(boolean isFinal);
119:
120: /**
121: * Adds a new transition to this state.
122: * The transition is defined by it's character set <CODE>charSet</CODE> and it's destionation
123: * state <CODE>toState</CODE>, so that you can transit from this state to the destination state
124: * only with a character contained in <CODE>charSet</CODE>. There is only one exception,
125: * if <CODE>charSet</CODE> is null, an epsilon transition will be added, which means that there
126: * are no chars needed to get to the destinationState <CODE>toState</CODE>; in other words a
127: * state that has an epsilon transition can get through this epsilon transition to the destination
128: * state <CODE>toState</CODE> without any char, so that we can say that <CODE>toState</CODE> melts
129: * into the state.
130: * @param charSet the characters for this transition
131: * @param toState the destination state where to transit to
132: * @return the new transition
133: */
134: public IStatePro.ITransition addTransition(ISet_char charSet,
135: IStatePro toState);
136:
137: /**
138: * Removes the specified transition from this state.
139: * <br>important: the specified transition must be a transition
140: * created via this state's addTransition method, otherwise an IllegalArgumentException is thrown
141: * @param transition
142: * @return true if transition was a transition of this state else false
143: */
144: public boolean removeTransition(IStatePro.ITransition transition);
145:
146: public void removeAllTransitions();
147:
148: public IStatePro.ITransition[] getTransitions();
149:
150: public IStatePro.ITransition[] getETransitions();
151:
152: public IStatePro.ITransition[] getAllTransitions();
153:
154: /**
155: * Returns all states that are reachable from this state through it's transitions and so on.
156: * <br>important: this state is only element of the returned set, if it is an element of a loop
157: * @return all reachable states as a set
158: */
159: public StateProSet getAllReachableStates();
160:
161: /**
162: * Visits this state with an epsilon transition and returns its epsilon closure.
163: * @return the epsilon closure of this state
164: */
165: public IState visit();
166:
167: public int getStateNumber();
168: }
|