Révision 7 petri/src/main/Network.java

Voir les différences:

Network.java
14 14
import element.Transition;
15 15

  
16 16
public class Network {
17
	//constant for the methode add arc
17 18
	public static int ArcOutering = 2;
18 19
	public static int ArcCleaner = 1;
19 20
	public static int ArcZero = 0;
......
27 28

  
28 29
	}
29 30

  
30

  
31
	/**
32
	 * create a new transition
33
	 */
31 34
	public void addTransition() {
32 35
		Transition transition = new Transition();
33 36
		listTransition.add(transition);
34 37
	}
38
	/**
39
	 * create a new place
40
	 */
35 41
	public void addPlace(int value) throws UndefinedToken {
36 42
		Place place = new Place(value);
37 43
		placeList.add(place);
......
43 49
		}
44 50

  
45 51
	}
52
	/**
53
	 * create a new arc
54
	 * @param transtion the transition link to this arc
55
	 * @param place the place link to this arc
56
	 * @param the value of this arc
57
	 * @param identifier the integer that correspond to the type of arc (define as static)
58
	 */
46 59
	public void addArc(Transition transition, Place place, int value, int identifier) throws UndefinedIdentifier {
47 60

  
48 61
		if (identifier==ArcZero) {
......
60 73
		}
61 74

  
62 75
	}
76
	/**
77
	 * delete an arc
78
	 */
63 79
	public void deleteArc(Arc a) {
64 80
		Arc aToDelete = null;
65 81
		for(Transition transition: listTransition) {
......
71 87
		}
72 88

  
73 89
	}
74

  
90
	/**
91
	 * delete a place an the arcs link to it
92
	 */
75 93
	public void deletePlace( Place place) {
76
		Arc aToDelete = null;
94
		List<Arc> aToDelete = new ArrayList<Arc>();
77 95
		for(Transition transition: listTransition) {
78 96
			for(Arc arc:transition.getArcList()) {
79 97
				if(arc.getPlace().equals(place)) {
80
					aToDelete=arc;	
98
					aToDelete.add(arc);
81 99
				}
82 100
			}
83
			deleteArc( aToDelete);
101
			aToDelete.forEach((Arc a)->{
102
				deleteArc(a);
103
			});
84 104
			placeList.remove(place);
85 105

  
86 106
		}
87 107

  
88 108
	}
89

  
109
	/**
110
	 * delete a transition
111
	 */
90 112
	public void deleteTransition(Transition transition) {
91 113

  
92 114
		listTransition.remove(transition);
93 115
	}
94

  
116
	/**
117
	 * fire the transition selected
118
	 */
95 119
	public void fire(Transition transition) {
96 120
		if (transition.isPullable()==true) {
97 121
			transition.doTransition();
98 122
		}
99 123
	}
124
	/**
125
	 * string  representation of a network
126
	 */
100 127
	public String toString() {
101 128
		String res= "[";
102 129
		for(int i=0;listTransition.size()>i;i++ ) {
......
105 132
		res=res+"]";
106 133
		return res;
107 134
	}
135
	//example of Petri network
108 136
	public static void main(String[] args) throws UndefinedToken, UndefinedIdentifier {
109 137

  
110 138
		Network n0=new Network();

Formats disponibles : Unified diff