Révision 3

Voir les différences:

petri/src/main/ArcCleaner.java
1
package main;
2

  
3
public class ArcCleaner extends Arc{
4
	
5

  
6
	public ArcCleaner(Place place) {
7
		super(place);
8
	
9
	}
10
	
11
	public void doTransition() {
12
		if (this.isActive()==true) {
13
			this.getPlace().changeToken(-this.getPlace().getToken());
14
		}
15
	}
16
	
17
	public boolean isActive() {
18
		return (this.getPlace().getToken()>0);
19
	}
20
	
21
	public boolean isPullable() {
22
		return this.isActive();
23
	}
24
	public String toString() {
25
		return "ArcCleaner,"+this.getPlace();
26
	}
27
	public static void main(String[] args) {
28
		System.out.println("TEST METHODS ARCCLEANER");
29
		
30
		System.out.println(" => method isActive()");
31
		Place emptyPlace = new Place(0);
32
		ArcCleaner arcc1 = new ArcCleaner(emptyPlace);
33
		Place place3 = new Place(3);
34
		ArcCleaner arcc2 = new ArcCleaner(place3);
35
		System.out.println("false : "+arcc1.isActive());
36
		System.out.println("true : "+arcc2.isActive());
37

  
38
	
39
		System.out.println(" => method isPullable()");
40
		System.out.println(arcc1);
41
		System.out.println("false : "+arcc1.isPullable());
42
		System.out.println(arcc2);
43
		System.out.println("true : "+arcc2.isPullable());
44

  
45
		System.out.println(" => method doTranstion()");
46
		System.out.println("before : "+arcc2);
47
		arcc2.doTransition();
48
		System.out.println("after  : "+arcc2);
49

  
50
	}
51
	
52
	
53

  
54
}
petri/src/main/ArcEntering.java
1
package main;
2

  
3
public class ArcEntering extends Arc{
4
	
5
	private int value;
6

  
7
	public ArcEntering(Place place, int value) {
8
		super(place);
9
		// TODO Auto-generated constructor stub
10
		this.value=value;
11
	}
12
	
13
	public void doTransition() {
14
		this.getPlace().changeToken(this.value);
15
	}
16
	
17
	public boolean isActive() {
18
		return true;
19
	}
20
	
21
	public boolean isPullable() {
22
		return true;
23
	}
24
	public String toString() {
25
		return "ArcEntering value:"+value+", "+this.getPlace();
26
	}
27
	public static void main(String[] args) {
28
		System.out.println("TEST METHODS ARCENTERING");
29
		
30
		System.out.println(" => method isActive()");
31
		Place emptyPlace = new Place(0);
32
		ArcEntering arce = new ArcEntering(emptyPlace, 3);
33
		System.out.println("true : "+arce.isActive());
34

  
35
	
36
		System.out.println(" => method isPullable()");
37
		Place place3 = new Place(3);
38
		ArcEntering arce2 = new ArcEntering(place3, 2);
39
		ArcEntering arce4 = new ArcEntering(place3, 4);
40
		System.out.println(arce2);
41
		System.out.println("true : "+arce2.isPullable());
42
		System.out.println(arce4);
43
		System.out.println("true : "+arce4.isPullable());
44
		
45
		System.out.println(" => method doTranstion()");
46
		System.out.println("before : "+arce2);
47
		arce2.doTransition();
48
		System.out.println("after  : "+arce2);
49
		System.out.println(" => method equals()");
50
		// the method equals is test here because arc is an abstract method
51
		System.out.println("true : "+arce2.equals(arce2));
52
		System.out.println("false : "+arce2.equals(arce4));
53
	}
54
	
55

  
56
}
petri/src/main/ArcOutering.java
1
package main;
2

  
3
public class ArcOutering extends Arc{
4
	
5
	private int value;
6

  
7
	public ArcOutering(Place place, int value) {
8
		super(place);
9
		this.value=value;
10
	}
11
	public String toString() {
12
		return "ArcOutering value:"+value+", "+this.getPlace();
13
	}
14
	
15
	public void doTransition() {
16
		this.getPlace().changeToken(this.value*(-1));
17
	}
18
	
19
	public boolean isActive() {
20
		return true;
21
	}
22
	
23
	public boolean isPullable() {
24
		return (this.getPlace().getToken()>=value);
25
	}
26
	public static void main(String[] args) {
27
		System.out.println("TEST METHODS ARCOUTERING");
28
		
29
		System.out.println(" => method isActive()");
30
		Place emptyPlace = new Place(0);
31
		ArcOutering arco = new ArcOutering(emptyPlace, 3);
32
		System.out.println("true : "+arco.isActive());
33

  
34
	
35
		System.out.println(" => method isPullable()");
36
		Place place3 = new Place(3);
37
		ArcOutering arco2 = new ArcOutering(place3, 2);
38
		ArcOutering arco4 = new ArcOutering(place3, 4);
39
		System.out.println(arco2);
40
		System.out.println("true : "+arco2.isPullable());
41
		System.out.println(arco4);
42
		System.out.println("false : "+arco4.isPullable());
43
		
44
		System.out.println(" => method doTranstion()");
45
		System.out.println("before : "+arco2);
46
		arco2.doTransition();
47
		System.out.println("after  : "+arco2);
48
		System.out.println(" => method equals()");
49
		// the method equals is test here because arc is an abstract method
50
		System.out.println("true : "+arco2.equals(arco2));
51
		System.out.println("false : "+arco2.equals(arco4));
52
	}
53

  
54

  
55
}
petri/src/main/Place.java
1
package main;
2

  
3
public class Place {
4
	
5
	private int token;
6
	
7
	public Place(int token) {
8
		this.token=token;
9
	}
10
	
11
	public int getToken() {
12
		return this.token;
13
	}
14
	public String toString() {
15
		return "Place Token : "+token;
16
	}
17
	
18
	public boolean isEmpty() {
19
		return (this.token==0);
20
	}
21
	
22
	public void changeToken(int i) {
23
		token += i;
24
	}
25
	
26
	public boolean equals(Object o) {
27
		if((o instanceof Place) &&(System.identityHashCode(((Place)o))==System.identityHashCode(this))) {
28
			return true;
29
		}
30
		else {
31
			return false;
32
		}
33
	}
34
	public static void main(String[] args) {
35
		System.out.println("TEST METHODS PLACE");
36
		
37
		System.out.println(" => method isEmpty()");
38
		Place emptyPlace = new Place(0);
39
		System.out.println("true : "+emptyPlace.isEmpty());
40
		Place notEmptyPlace = new Place(2);
41
		System.out.println("true : "+notEmptyPlace.isEmpty());
42
	
43
		System.out.println(" => method changeToken(int i)");
44
		Place place3 = new Place(3);
45
		place3.changeToken(5);
46
		System.out.println("3 + 5 = "+place3.getToken());
47
		place3.changeToken(-4);
48
		System.out.println("8 - 4 = "+place3.getToken());
49
		
50
		System.out.println(" => method equals()");
51
		Place place1 = new Place(0);
52
		Place place2 = new Place(0);
53
		System.out.println("true : "+place1.equals(place1));
54
		System.out.println("false : "+place1.equals(place2));
55
	}
56

  
57
}
petri/src/main/Arc.java
1
package main;
2

  
3
public abstract class Arc implements ArcInterface {
4
	
5
	private Place place;
6
	
7
	public Arc(Place place) {
8
		this.place=place;
9
	}
10
	
11
	public Place getPlace() {
12
		return this.place;
13
	}
14
	public boolean equals(Object o) {
15
		if((o instanceof Arc) &&(System.identityHashCode(((Arc)o))==System.identityHashCode(this))) {
16
			return true;
17
		}
18
		else {
19
			return false;
20
		}
21
		
22
	}
23

  
24
}
petri/src/main/ArcZero.java
1
package main;
2

  
3
public class ArcZero extends ArcOutering {
4
	
5
	public ArcZero(Place place, int value) {
6
		super(place, value);
7
		// TODO Auto-generated constructor stub
8
	}
9
	
10
	public void doTransition() {
11
	}
12
	public boolean isActive() {
13
		return (this.getPlace().getToken()==0);
14
	}
15
	public boolean isPullable() {
16
		return this.isActive();
17
	}
18
	public String toString() {
19
		return "ArcZero, "+this.getPlace(); 
20
	}
21
	public static void main(String[] args) {
22
		System.out.println("TEST METHODS ARCZERO");
23
		
24
		System.out.println(" => method isActive()");
25
		Place emptyPlace = new Place(0);
26
		ArcZero arcc1 = new ArcZero(emptyPlace,2);
27
		Place place3 = new Place(3);
28
		ArcZero arcc2 = new ArcZero(place3,2);
29
		System.out.println(arcc1);
30
		System.out.println("true : "+arcc1.isActive());
31
		System.out.println(arcc2);
32
		System.out.println("false : "+arcc2.isActive());
33

  
34
	
35
		System.out.println(" => method isPullable()");
36
		System.out.println(arcc1);
37
		System.out.println("false : "+arcc1.isPullable());
38
		System.out.println(arcc2);
39
		System.out.println("true : "+arcc2.isPullable());
40

  
41
		System.out.println(" => method doTranstion()");
42
		System.out.println("before : "+arcc2);
43
		arcc2.doTransition();
44
		System.out.println("after  : "+arcc2);
45

  
46
	}
47

  
48
}
petri/src/main/ArcInterface.java
1
package main;
2

  
3
public interface ArcInterface {
4
	
5
	public void doTransition();
6
	public boolean isPullable();
7
	public boolean isActive();
8

  
9
}
petri/src/main/Transition.java
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
}
petri/src/main/Network.java
4 4
import java.util.ArrayList;
5 5
import java.util.List;
6 6

  
7
import arc.Arc;
8
import arc.ArcCleaner;
9
import arc.ArcEntering;
10
import arc.ArcOutering;
11
import arc.ArcZero;
12
import element.Place;
13
import element.Transition;
14

  
7 15
public class Network {
8 16
	public static int ArcOutering = 2;
9 17
	public static int ArcCleaner = 1;
petri/src/arc/Arc.java
1
package arc;
2

  
3
import element.Place;
4

  
5
public abstract class Arc implements ArcInterface {
6
	
7
	private Place place;
8
	
9
	public Arc(Place place) {
10
		this.place=place;
11
	}
12
	
13
	public Place getPlace() {
14
		return this.place;
15
	}
16
	public boolean equals(Object o) {
17
		if((o instanceof Arc) &&(System.identityHashCode(((Arc)o))==System.identityHashCode(this))) {
18
			return true;
19
		}
20
		else {
21
			return false;
22
		}
23
		
24
	}
25

  
26
}
0 27

  
petri/src/arc/ArcZero.java
1
package arc;
2

  
3
import element.Place;
4

  
5
public class ArcZero extends ArcOutering {
6
	
7
	public ArcZero(Place place, int value) {
8
		super(place, value);
9
		// TODO Auto-generated constructor stub
10
	}
11
	
12
	public void doTransition() {
13
	}
14
	public boolean isActive() {
15
		return (this.getPlace().getToken()==0);
16
	}
17
	public boolean isPullable() {
18
		return this.isActive();
19
	}
20
	public String toString() {
21
		return "ArcZero, "+this.getPlace(); 
22
	}
23
	public static void main(String[] args) {
24
		System.out.println("TEST METHODS ARCZERO");
25
		
26
		System.out.println(" => method isActive()");
27
		Place emptyPlace = new Place(0);
28
		ArcZero arcc1 = new ArcZero(emptyPlace,2);
29
		Place place3 = new Place(3);
30
		ArcZero arcc2 = new ArcZero(place3,2);
31
		System.out.println(arcc1);
32
		System.out.println("true : "+arcc1.isActive());
33
		System.out.println(arcc2);
34
		System.out.println("false : "+arcc2.isActive());
35

  
36
	
37
		System.out.println(" => method isPullable()");
38
		System.out.println(arcc1);
39
		System.out.println("false : "+arcc1.isPullable());
40
		System.out.println(arcc2);
41
		System.out.println("true : "+arcc2.isPullable());
42

  
43
		System.out.println(" => method doTranstion()");
44
		System.out.println("before : "+arcc2);
45
		arcc2.doTransition();
46
		System.out.println("after  : "+arcc2);
47

  
48
	}
49

  
50
}
0 51

  
petri/src/arc/ArcInterface.java
1
package arc;
2

  
3
public interface ArcInterface {
4
	
5
	public void doTransition();
6
	public boolean isPullable();
7
	public boolean isActive();
8

  
9
}
0 10

  
petri/src/arc/ArcCleaner.java
1
package arc;
2

  
3
import element.Place;
4

  
5
public class ArcCleaner extends Arc{
6
	
7

  
8
	public ArcCleaner(Place place) {
9
		super(place);
10
	
11
	}
12
	
13
	public void doTransition() {
14
		if (this.isActive()==true) {
15
			this.getPlace().changeToken(-this.getPlace().getToken());
16
		}
17
	}
18
	
19
	public boolean isActive() {
20
		return (this.getPlace().getToken()>0);
21
	}
22
	
23
	public boolean isPullable() {
24
		return this.isActive();
25
	}
26
	public String toString() {
27
		return "ArcCleaner,"+this.getPlace();
28
	}
29
	public static void main(String[] args) {
30
		System.out.println("TEST METHODS ARCCLEANER");
31
		
32
		System.out.println(" => method isActive()");
33
		Place emptyPlace = new Place(0);
34
		ArcCleaner arcc1 = new ArcCleaner(emptyPlace);
35
		Place place3 = new Place(3);
36
		ArcCleaner arcc2 = new ArcCleaner(place3);
37
		System.out.println("false : "+arcc1.isActive());
38
		System.out.println("true : "+arcc2.isActive());
39

  
40
	
41
		System.out.println(" => method isPullable()");
42
		System.out.println(arcc1);
43
		System.out.println("false : "+arcc1.isPullable());
44
		System.out.println(arcc2);
45
		System.out.println("true : "+arcc2.isPullable());
46

  
47
		System.out.println(" => method doTranstion()");
48
		System.out.println("before : "+arcc2);
49
		arcc2.doTransition();
50
		System.out.println("after  : "+arcc2);
51

  
52
	}
53
	
54
	
55

  
56
}
0 57

  
petri/src/arc/ArcEntering.java
1
package arc;
2

  
3
import element.Place;
4

  
5
public class ArcEntering extends Arc{
6
	
7
	private int value;
8

  
9
	public ArcEntering(Place place, int value) {
10
		super(place);
11
		// TODO Auto-generated constructor stub
12
		this.value=value;
13
	}
14
	
15
	public void doTransition() {
16
		this.getPlace().changeToken(this.value);
17
	}
18
	
19
	public boolean isActive() {
20
		return true;
21
	}
22
	
23
	public boolean isPullable() {
24
		return true;
25
	}
26
	public String toString() {
27
		return "ArcEntering value:"+value+", "+this.getPlace();
28
	}
29
	public static void main(String[] args) {
30
		System.out.println("TEST METHODS ARCENTERING");
31
		
32
		System.out.println(" => method isActive()");
33
		Place emptyPlace = new Place(0);
34
		ArcEntering arce = new ArcEntering(emptyPlace, 3);
35
		System.out.println("true : "+arce.isActive());
36

  
37
	
38
		System.out.println(" => method isPullable()");
39
		Place place3 = new Place(3);
40
		ArcEntering arce2 = new ArcEntering(place3, 2);
41
		ArcEntering arce4 = new ArcEntering(place3, 4);
42
		System.out.println(arce2);
43
		System.out.println("true : "+arce2.isPullable());
44
		System.out.println(arce4);
45
		System.out.println("true : "+arce4.isPullable());
46
		
47
		System.out.println(" => method doTranstion()");
48
		System.out.println("before : "+arce2);
49
		arce2.doTransition();
50
		System.out.println("after  : "+arce2);
51
		System.out.println(" => method equals()");
52
		// the method equals is test here because arc is an abstract method
53
		System.out.println("true : "+arce2.equals(arce2));
54
		System.out.println("false : "+arce2.equals(arce4));
55
	}
56
	
57

  
58
}
0 59

  
petri/src/arc/ArcOutering.java
1
package arc;
2

  
3
import element.Place;
4

  
5
public class ArcOutering extends Arc{
6
	
7
	private int value;
8

  
9
	public ArcOutering(Place place, int value) {
10
		super(place);
11
		this.value=value;
12
	}
13
	public String toString() {
14
		return "ArcOutering value:"+value+", "+this.getPlace();
15
	}
16
	
17
	public void doTransition() {
18
		this.getPlace().changeToken(this.value*(-1));
19
	}
20
	
21
	public boolean isActive() {
22
		return true;
23
	}
24
	
25
	public boolean isPullable() {
26
		return (this.getPlace().getToken()>=value);
27
	}
28
	public static void main(String[] args) {
29
		System.out.println("TEST METHODS ARCOUTERING");
30
		
31
		System.out.println(" => method isActive()");
32
		Place emptyPlace = new Place(0);
33
		ArcOutering arco = new ArcOutering(emptyPlace, 3);
34
		System.out.println("true : "+arco.isActive());
35

  
36
	
37
		System.out.println(" => method isPullable()");
38
		Place place3 = new Place(3);
39
		ArcOutering arco2 = new ArcOutering(place3, 2);
40
		ArcOutering arco4 = new ArcOutering(place3, 4);
41
		System.out.println(arco2);
42
		System.out.println("true : "+arco2.isPullable());
43
		System.out.println(arco4);
44
		System.out.println("false : "+arco4.isPullable());
45
		
46
		System.out.println(" => method doTranstion()");
47
		System.out.println("before : "+arco2);
48
		arco2.doTransition();
49
		System.out.println("after  : "+arco2);
50
		System.out.println(" => method equals()");
51
		// the method equals is test here because arc is an abstract method
52
		System.out.println("true : "+arco2.equals(arco2));
53
		System.out.println("false : "+arco2.equals(arco4));
54
	}
55

  
56

  
57
}
0 58

  
petri/src/element/Place.java
1
package element;
2

  
3
public class Place {
4
	
5
	private int token;
6
	
7
	public Place(int token) {
8
		this.token=token;
9
	}
10
	
11
	public int getToken() {
12
		return this.token;
13
	}
14
	public String toString() {
15
		return "Place Token : "+token;
16
	}
17
	
18
	public boolean isEmpty() {
19
		return (this.token==0);
20
	}
21
	
22
	public void changeToken(int i) {
23
		token += i;
24
	}
25
	
26
	public boolean equals(Object o) {
27
		if((o instanceof Place) &&(System.identityHashCode(((Place)o))==System.identityHashCode(this))) {
28
			return true;
29
		}
30
		else {
31
			return false;
32
		}
33
	}
34
	public static void main(String[] args) {
35
		System.out.println("TEST METHODS PLACE");
36
		
37
		System.out.println(" => method isEmpty()");
38
		Place emptyPlace = new Place(0);
39
		System.out.println("true : "+emptyPlace.isEmpty());
40
		Place notEmptyPlace = new Place(2);
41
		System.out.println("true : "+notEmptyPlace.isEmpty());
42
	
43
		System.out.println(" => method changeToken(int i)");
44
		Place place3 = new Place(3);
45
		place3.changeToken(5);
46
		System.out.println("3 + 5 = "+place3.getToken());
47
		place3.changeToken(-4);
48
		System.out.println("8 - 4 = "+place3.getToken());
49
		
50
		System.out.println(" => method equals()");
51
		Place place1 = new Place(0);
52
		Place place2 = new Place(0);
53
		System.out.println("true : "+place1.equals(place1));
54
		System.out.println("false : "+place1.equals(place2));
55
	}
56

  
57
}
0 58

  
petri/src/element/Transition.java
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
}
0 75

  

Formats disponibles : Unified diff