| 1 | |
| 2 | @ClassPreamble ( |
| 3 | author = "Jérôme Benoit", |
| 4 | date = "06/21/2009" |
| 5 | ) |
| 6 | class Piletransformations { |
| 7 | private Point[] transformations; |
| 8 | private int currentTransformation; |
| 9 | |
| 10 | Piletransformations(int size) { |
| 11 | transformations = new Point[size]; |
| 12 | for (int i = 0; i < transformations.length; i++) { |
| 13 | transformations[i] = new Point(0, 0); |
| 14 | } |
| 15 | currentTransformation = 0; |
| 16 | } |
| 17 | |
| 18 | public Point getCurrentTransformation() { |
| 19 | if (isEmpty()) { |
| 20 | return transformations[currentTransformation]; |
| 21 | } else { |
| 22 | return transformations[currentTransformation - 1]; |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | private boolean isEmpty() { |
| 27 | return (currentTransformation == 0); |
| 28 | } |
| 29 | |
| 30 | private boolean isFull() { |
| 31 | return (currentTransformation >= transformations.length); |
| 32 | } |
| 33 | |
| 34 | public boolean empiler(Point p) { |
| 35 | boolean rtVal = false; |
| 36 | if (isEmpty()) { |
| 37 | transformations[currentTransformation] = p; |
| 38 | currentTransformation++; |
| 39 | rtVal = true; |
| 40 | } else if (!isFull()) { |
| 41 | transformations[currentTransformation] = transformations[currentTransformation - 1].additionner(p); |
| 42 | currentTransformation++; |
| 43 | rtVal = true; |
| 44 | } |
| 45 | return rtVal; |
| 46 | } |
| 47 | |
| 48 | public Point depiler() { |
| 49 | if(!isEmpty()) { |
| 50 | currentTransformation--; |
| 51 | return transformations[currentTransformation]; |
| 52 | } else { |
| 53 | return transformations[currentTransformation]; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | public void display() { |
| 58 | System.out.println("----"); |
| 59 | for (int i = 0; i < currentTransformation; i++) { |
| 60 | System.out.println(transformations[i].toString()); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | } |