fr_b02 / petri / src / element / Place.java @ 7
Historique | Voir | Annoter | Télécharger (1,181 ko)
1 | 3 | a19coudr | package element; |
---|---|---|---|
2 | 2 | a19coudr | |
3 | 4 | a19coudr | |
4 | 2 | a19coudr | public class Place { |
5 | |||
6 | private int token; |
||
7 | 7 | a19coudr | /**
|
8 | * exception to handle negative value for token
|
||
9 | */
|
||
10 | 4 | a19coudr | @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 | 2 | a19coudr | this.token=token;
|
23 | } |
||
24 | |||
25 | public int getToken() { |
||
26 | return this.token; |
||
27 | } |
||
28 | 7 | a19coudr | /**
|
29 | * @return a string representation of the place
|
||
30 | */
|
||
31 | 2 | a19coudr | public String toString() { |
32 | return "Place Token : "+token; |
||
33 | } |
||
34 | 7 | a19coudr | /**
|
35 | * check if the place is not empty
|
||
36 | */
|
||
37 | 2 | a19coudr | public boolean isEmpty() { |
38 | return (this.token==0); |
||
39 | } |
||
40 | 7 | a19coudr | /**
|
41 | * @param int value that the place has to add to its token value
|
||
42 | */
|
||
43 | 2 | a19coudr | public void changeToken(int i) { |
44 | token += i; |
||
45 | } |
||
46 | 7 | a19coudr | /**
|
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 | 2 | a19coudr | 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 | } |