fr_b02 / petri / src / main / Place.java @ 2
Historique | Voir | Annoter | Télécharger (1,341 ko)
1 | 2 | a19coudr | 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 | } |