Skip to content
Snippets Groups Projects
Commit 16f2b5a1 authored by BEL KHALIFA Mohamed amine's avatar BEL KHALIFA Mohamed amine
Browse files

ColoredCellIterator

parent 92481741
Branches
No related tags found
No related merge requests found
package model;
import javafx.scene.paint.Color;
import util.SetUtil;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class ColoredCellIterator implements Iterator<Cell> {
private Color color;
private Cell startCell;
private Set<Cell> pendingCells;
private Set<Cell> visitedCells;
public ColoredCellIterator(Cell startCell ){
this.pendingCells = new HashSet<>();
this.visitedCells = new HashSet<>();
this.startCell=startCell;
this.color=startCell.getColor();
pendingCells.add(startCell);
}
@Override
public boolean hasNext() {
return !(pendingCells.isEmpty());
}
@Override
public Cell next() {
startCell = SetUtil.anyElement(pendingCells);
for (Cell c : startCell.getNeighbours()) {
if (c.getColor().equals(startCell.getColor()) && !visitedCells.contains(c)) {
pendingCells.add(c);
}
}
Cell cell=startCell;
pendingCells.remove(startCell);
visitedCells.add(startCell);
return cell;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment