1 import java
.util
.Comparator
;
3 public class Image
extends Forme
implements Compactable
,
6 final int IMAGE_MAX_SIZE
= 100;
7 Forme
[] formeCollection
;
12 formeCollection
= new Forme
[IMAGE_MAX_SIZE
];
18 formeCollection
= new Forme
[IMAGE_MAX_SIZE
];
22 public int getSize() {
26 private boolean isEmpty() {
27 return (formeNumber
== 0);
30 private boolean isFull() {
31 return (formeNumber
>= formeCollection
.length
);
34 public void dessiner(Piletransformations pile
) {
35 for (int i
= 0; i
< formeNumber
; i
++) {
36 formeCollection
[i
].dessiner(pile
);
40 public void deplacer(Point p
) {
41 for (int i
= 0; i
< formeNumber
; i
++) {
42 formeCollection
[i
].deplacer(p
);
46 public boolean ajouter(Forme forme
) {
47 boolean rtVal
= false;
49 formeCollection
[formeNumber
] = forme
;
56 public boolean supprimer(int index
) {
57 boolean rtVal
= false;
59 for (int j
= index
; (j
< formeNumber
- 1 && index
< formeNumber
); j
++) {
60 formeCollection
[j
] = formeCollection
[j
+ 1];
68 public void afficher() {
69 String className
= this.getClass().getSimpleName();
70 System
.out
.println("---- " + className
+ " ----");
71 for (int i
= 0; i
< formeNumber
; i
++) {
72 formeCollection
[i
].afficher();
76 public void compacter(int nElements
) {
78 /* int minIndex = formeNumber - nElements - 1;
79 for (int i = formeNumber - 1; (i > minIndex && !isEmpty()); i--) {
82 // Lightweight solution
83 if (formeNumber
- nElements
> 0) {
84 formeNumber
-= nElements
;
90 public int compareTo(Image image
) {
91 return formeNumber
- image
.getSize();
94 public int compare(Image image1
, Image image2
) {
95 return (int)(image1
.getpOri().getY() - image2
.getpOri().getY());