Statistiques
| Révision:

fr_b02 / petri / src / main / Transition.java @ 2

Historique | Voir | Annoter | Télécharger (1,519 ko)

1
package main;
2

    
3
import java.util.ArrayList;
4
import java.util.List;
5

    
6
public class Transition {
7
        
8
        
9
        private List<Arc> arcList;
10
        
11
        public String toString() {
12
                String res= " [";
13
                for(int i=0;arcList.size()>i;i++ ) {
14
                        res=res+arcList.get(i).toString()+" // ";
15
                }
16
                res=res+"] ";
17
                return res;
18
        }
19

    
20
        public Transition() {
21
                this.arcList=new ArrayList<Arc>();
22
        }
23
        
24

    
25
        public boolean isPullable() {
26
                int i=0;
27
                boolean res=true;
28
                while(i<this.arcList.size() && res==true) {
29
                        res=this.arcList.get(i).isPullable();
30
                        i=i+1;
31
                }
32
                return res;
33
        }
34
        
35
        public void doTransition() {
36
                if (this.isPullable()==true) {
37
                        for (int i=0; i<arcList.size();i++) {
38
                                arcList.get(i).doTransition();
39
                        }
40
                }
41
        }
42
        public List<Arc> getArcList(){
43
                return this.arcList;
44
        }
45
        public static void main(String[] args) {
46
                System.out.println("TEST METHODS TRANSITION");
47
                
48
                Transition t1=new Transition();
49
                t1.arcList.add(new ArcOutering(new Place(4), 2));
50
                t1.arcList.add(new ArcEntering(new Place(4), 1));
51

    
52
                Transition t2=new Transition();
53
                t2.arcList.add(new ArcOutering(new Place(2), 3));
54
                t2.arcList.add(new ArcEntering(new Place(2), 3));
55
        
56
                System.out.println(" => method isPullable()");
57

    
58
                System.out.println(t1);
59
                System.out.println("true : "+t1.isPullable());
60
                System.out.println(t2);
61
                System.out.println("false : "+t2.isPullable());
62
                
63
                System.out.println(" => method doTranstion()");
64
                System.out.println("before : "+t1);
65
                t1.doTransition();
66
                System.out.println("after  : "+t1);
67

    
68

    
69
        }
70
}