fr_b02 / petri / src / element / Place.java @ 7
Historique | Voir | Annoter | Télécharger (1,181 ko)
1 |
package element; |
---|---|
2 |
|
3 |
|
4 |
public class Place { |
5 |
|
6 |
private int token; |
7 |
/**
|
8 |
* exception to handle negative value for token
|
9 |
*/
|
10 |
@SuppressWarnings("serial") |
11 |
public class UndefinedToken extends Exception{ |
12 |
public UndefinedToken() {
|
13 |
super("the token cannot take a value <0"); |
14 |
} |
15 |
|
16 |
} |
17 |
|
18 |
public Place(int token) throws UndefinedToken{ |
19 |
if(token<0) { |
20 |
throw new UndefinedToken(); |
21 |
} |
22 |
this.token=token;
|
23 |
} |
24 |
|
25 |
public int getToken() { |
26 |
return this.token; |
27 |
} |
28 |
/**
|
29 |
* @return a string representation of the place
|
30 |
*/
|
31 |
public String toString() { |
32 |
return "Place Token : "+token; |
33 |
} |
34 |
/**
|
35 |
* check if the place is not empty
|
36 |
*/
|
37 |
public boolean isEmpty() { |
38 |
return (this.token==0); |
39 |
} |
40 |
/**
|
41 |
* @param int value that the place has to add to its token value
|
42 |
*/
|
43 |
public void changeToken(int i) { |
44 |
token += i; |
45 |
} |
46 |
/**
|
47 |
* @param Object to compare to the place
|
48 |
*the goal of this method is to check if two places are the same object (same identityHashCode)
|
49 |
*/
|
50 |
public boolean equals(Object o) { |
51 |
if((o instanceof Place) &&(System.identityHashCode(((Place)o))==System.identityHashCode(this))) { |
52 |
return true; |
53 |
} |
54 |
else {
|
55 |
return false; |
56 |
} |
57 |
} |
58 |
|
59 |
} |