fr_b02 / petri / src / element / Transition.java @ 3
Historique | Voir | Annoter | Télécharger (1,589 ko)
1 |
package element; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.List; |
5 |
|
6 |
import arc.Arc; |
7 |
import arc.ArcEntering; |
8 |
import arc.ArcOutering; |
9 |
|
10 |
public class Transition { |
11 |
|
12 |
|
13 |
private List<Arc> arcList; |
14 |
|
15 |
public String toString() { |
16 |
String res= " ["; |
17 |
for(int i=0;arcList.size()>i;i++ ) { |
18 |
res=res+arcList.get(i).toString()+" // ";
|
19 |
} |
20 |
res=res+"] ";
|
21 |
return res;
|
22 |
} |
23 |
|
24 |
public Transition() {
|
25 |
this.arcList=new ArrayList<Arc>(); |
26 |
} |
27 |
|
28 |
|
29 |
public boolean isPullable() { |
30 |
int i=0; |
31 |
boolean res=true; |
32 |
while(i<this.arcList.size() && res==true) { |
33 |
res=this.arcList.get(i).isPullable();
|
34 |
i=i+1;
|
35 |
} |
36 |
return res;
|
37 |
} |
38 |
|
39 |
public void doTransition() { |
40 |
if (this.isPullable()==true) { |
41 |
for (int i=0; i<arcList.size();i++) { |
42 |
arcList.get(i).doTransition(); |
43 |
} |
44 |
} |
45 |
} |
46 |
public List<Arc> getArcList(){ |
47 |
return this.arcList; |
48 |
} |
49 |
public static void main(String[] args) { |
50 |
System.out.println("TEST METHODS TRANSITION"); |
51 |
|
52 |
Transition t1=new Transition();
|
53 |
t1.arcList.add(new ArcOutering(new Place(4), 2)); |
54 |
t1.arcList.add(new ArcEntering(new Place(4), 1)); |
55 |
|
56 |
Transition t2=new Transition();
|
57 |
t2.arcList.add(new ArcOutering(new Place(2), 3)); |
58 |
t2.arcList.add(new ArcEntering(new Place(2), 3)); |
59 |
|
60 |
System.out.println(" => method isPullable()"); |
61 |
|
62 |
System.out.println(t1);
|
63 |
System.out.println("true : "+t1.isPullable()); |
64 |
System.out.println(t2);
|
65 |
System.out.println("false : "+t2.isPullable()); |
66 |
|
67 |
System.out.println(" => method doTranstion()"); |
68 |
System.out.println("before : "+t1); |
69 |
t1.doTransition(); |
70 |
System.out.println("after : "+t1); |
71 |
|
72 |
|
73 |
} |
74 |
} |