Skip to content
Snippets Groups Projects
Commit 7171edb0 authored by SAIDI Hatim's avatar SAIDI Hatim
Browse files

test

parent ba54759a
No related branches found
No related tags found
No related merge requests found
......@@ -42,5 +42,7 @@ public interface Cell {
*/
Property<Color> getColorProperty();
Iterator<Cell> iterator();
}
package model;
import javafx.scene.paint.Color;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class ColoredCellIterator implements Iterator<Cell> {
private Color color;
private Set<Cell> visitedCells;
private Set<Cell> pendingCells ;
public ColoredCellIterator(Cell startCell){
this.color = startCell.getColor();
this.visitedCells = new HashSet<>();
this.pendingCells = new HashSet<>();
pendingCells.add(startCell);
}
@Override
public Cell next() {
for(Cell cell : pendingCells){
if(cell.getColor() == pendingCells.stream().findFirst().get().getColor()&& hasNext()&& !visitedCells.contains(cell) ){
for (int i=0;i<cell.getNeighbours().size()-1;i++){
if(visitedCells.contains(cell.getNeighbours().get(i)) ||
cell.getNeighbours().get(i).getColor()!= pendingCells.stream().findFirst().get().getColor()){
visitedCells.add(cell);
return cell;
}
else {
pendingCells.add(cell.getNeighbours().get(i));
}
visitedCells.add(cell);
return cell;
}
visitedCells.add(cell);
return cell;
}
}
return new SquareCell();
}
@Override
public boolean hasNext() {
if (pendingCells.isEmpty()){
return false;
}
else {
return true;
}
}
}
......@@ -3,6 +3,7 @@ package model;
import javafx.beans.property.Property;
import javafx.scene.paint.Color;
import java.util.Iterator;
import java.util.List;
public class GrayCell extends AbstractCell{
......@@ -34,4 +35,7 @@ public class GrayCell extends AbstractCell{
public void setColor(Color color){
}
public Iterator<Cell> iterator(){
return null;
}
}
......@@ -38,4 +38,8 @@ public class SquareCell extends AbstractCell {
this.neighbours.set(i,cells.get(i));
}
}
public Iterator<Cell> iterator(){
return new ColoredCellIterator(new SquareCell());
}
}
\ No newline at end of file
package util;
import model.Cell;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set;
......@@ -7,4 +10,5 @@ public class SetUtil {
public static <T> T anyElement(Set<T> elements){
return elements.stream().findAny().orElseThrow(NoSuchElementException::new);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment