KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > jrexx > set > IStatePro


1 /*
2 * 01/07/2003 - 15:19:32
3 *
4 * IStatePro.java -
5 * Copyright (C) 2003 Buero fuer Softwarearchitektur GbR
6 * ralf.meyer@karneim.com
7 * http://jrexx.sf.net
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */

23 package com.tc.jrexx.set;
24
25 import com.tc.jrexx.set.ISet_char;
26
27 /**
28  * This interface represents a state of an automaton created via the automaton's addState method.
29  * <p>Copyright: Copyright (c) 2002</p>
30  * <p>Company: Büro für Softwarearchitektur www.karneim.com</p>
31  * @author Ralf Meyer
32  * @version 1.0
33  */

34 public interface IStatePro {
35   public interface ITransition {
36     public IStatePro getFromState();
37     public ISet_char getCharSet();
38     public IStatePro getToState();
39   }
40
41
42   /**
43    * The listener interface for receiving visit events of an IStatePro.
44    * The class that is interested in processing a state's visit event implements this interface.
45    * A listener instance of that class is registered with the state using the state's addVisitListener method.
46    * <br>A state will be visited every time it is the destination state of a transition that has been visited.
47    * <br>A state that becomes visited, will then visit all its epsilon transitions
48    * and these transitions will visit all destination states and so on.
49    * <br>State visiting occurs using the methods
50    * <br>IStatePro.visit
51    * <br>IState.next
52    *
53    * <p>Copyright: Copyright (c) 2002</p>
54    * <p>Company: Büro für Softwarearchitektur www.karneim.com</p>
55    * @author Ralf Meyer
56    * @version 1.0
57    */

58   public interface IVisitListener {
59
60     /**
61      * The state invokes this method on all registered listener if it is visited through an epsilon transition.
62      * @param state
63      */

64     public void stateVisited(IStatePro state);
65     /**
66      * The state invokes this method on all registered listener if it is visited through an transition with char ch.
67      */

68     public void stateVisited(IStatePro state,char ch);
69
70     public void stateUnVisited(IStatePro state);
71   }
72
73   /**
74    * The listener interface for receiving change events of an IStatePro.
75    * The class that is interested in processing a state's change event implements this interface.
76    * A listener instance of that class is registered with the state using the state's addChangeListener method.
77    * <p>Copyright: Copyright (c) 2002</p>
78    * <p>Company: Büro für Softwarearchitektur www.karneim.com</p>
79    * @author Ralf Meyer
80    * @version 1.0
81    */

82   public interface IChangeListener {
83     /**
84      * The state invokes this method on all registered listener if a transition is added to the state
85      */

86     public void transitionAdded(IStatePro.ITransition transition);
87     /**
88      * The state invokes this method on all registered listener if a transition is removed from the state
89      */

90     public void transitionRemoved(IStatePro.ITransition transition);
91     /**
92      * The state invokes this method on all registered listener if it's final property is changed.
93      */

94     public void isFinalChanged(IStatePro state,boolean isFinal);
95   }
96
97   public void addVisitListener(IStatePro.IVisitListener listener);
98   public boolean removeVisitListener(IStatePro.IVisitListener listener);
99
100   public void addChangeListener(IStatePro.IChangeListener listener);
101   public boolean removeChangeListener(IStatePro.IChangeListener listener);
102
103   /**
104    * @return true if the state is a final state else false
105    */

106   public boolean isFinal();
107
108   /**
109    * Makes this state final or non final.
110    */

111   public void setFinal(boolean isFinal);
112
113   /**
114    * Adds a new transition to this state.
115    * The transition is defined by it's character set <CODE>charSet</CODE> and it's destionation
116    * state <CODE>toState</CODE>, so that you can transit from this state to the destination state
117    * only with a character contained in <CODE>charSet</CODE>. There is only one exception,
118    * if <CODE>charSet</CODE> is null, an epsilon transition will be added, which means that there
119    * are no chars needed to get to the destinationState <CODE>toState</CODE>; in other words a
120    * state that has an epsilon transition can get through this epsilon transition to the destination
121    * state <CODE>toState</CODE> without any char, so that we can say that <CODE>toState</CODE> melts
122    * into the state.
123    * @param charSet the characters for this transition
124    * @param toState the destination state where to transit to
125    * @return the new transition
126    */

127   public IStatePro.ITransition addTransition(ISet_char charSet,IStatePro toState);
128
129   /**
130    * Removes the specified transition from this state.
131    * <br>important: the specified transition must be a transition
132    * created via this state's addTransition method, otherwise an IllegalArgumentException is thrown
133    * @param transition
134    * @return true if transition was a transition of this state else false
135    */

136   public boolean removeTransition(IStatePro.ITransition transition);
137
138   public void removeAllTransitions();
139
140   public IStatePro.ITransition[] getTransitions();
141   public IStatePro.ITransition[] getETransitions();
142   public IStatePro.ITransition[] getAllTransitions();
143
144   /**
145    * Returns all states that are reachable from this state through it's transitions and so on.
146    * <br>important: this state is only element of the returned set, if it is an element of a loop
147    * @return all reachable states as a set
148    */

149   public StateProSet getAllReachableStates();
150
151   /**
152    * Visits this state with an epsilon transition and returns its epsilon closure.
153    * @return the epsilon closure of this state
154    */

155   public IState visit();
156
157   public int getStateNumber();
158 }
Popular Tags