Skip to content
Snippets Groups Projects
Commit 0d1891b5 authored by RAKOTOARISOA Andrianinarisaina cy's avatar RAKOTOARISOA Andrianinarisaina cy
Browse files

Tâche 5 (8.1) : Création de la classe ColoredCellIterator de ses 4 attributs,...

Tâche 5 (8.1) : Création de la classe ColoredCellIterator de ses 4 attributs, de son constructeurs et des méthodes qu'il doit implémenter en tant qu'interface de Iterator<Cell>
parent f1f986de
Branches
No related tags found
No related merge requests found
......@@ -42,5 +42,8 @@ public interface Cell {
*/
Property<Color> getColorProperty();
//Demandée par l'exercice
Iterator<Cell> iterator() ;
}
package model;
import java.awt.*;
import java.util.Iterator;
import java.util.Set ;
public class ColorCellIterator implements Iterator<Cell> {
Color color ; // qui correspond à la couleur de la cellule de départ
Set<Cell> visitedCells ; //pour stocker l’ensemble des cellules sur lesquelles on a déjà itéré
Set<Cell> pendingCells ; //à la cellule de départ et qui n’ont pas encore été parcourues
//Constructeur de la classe
public void ColoredCellIterator(Cell startCell) { //startCell : cellule à partir de laquelle on souhaite démarrer l’itération
this.pendingCells.add(startCell) ;
}
@Override
public boolean hasNext() {
return false;
}
@Override
public Cell next() {
return null;
}
public Set<Cell> getNeighbours() {
while (this.pendingCells.iterator().hasNext()) {
Cell pendingCell = this.pendingCells.iterator().next();
if (pendingCell.iterator().hasNext().getColor() == pendingCells.getColor()) {
this.pendingCells.add(pendingCell);
}
this.visitedCells.add(pendingCell);
if (this.pendingCells.iterator().hasNext()) {
pendingCell = this.pendingCells.iterator().next();
}
else return this.visitedCells;
}
}
}
......@@ -49,5 +49,10 @@ public class SquareCell extends AbstractCell{
}
@Override
public Iterator<Cell> iterator() {
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment