Select Git revision
Forked from
COUETOUX Basile / FirefighterStarter
Source project has a limited visibility.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
GridIterator.java 650 B
package model;
import java.util.Iterator;
public class GridIterator<T> implements Iterator<T> {
private int rowIndex;
private int columnIndex;
private final Grid<T> grid;
GridIterator(Grid grid) {
this.rowIndex = 0;
this.columnIndex = 0;
this.grid = grid;
}
@Override
public boolean hasNext() {
return columnIndex < grid.getNumberOfColumns() && rowIndex < grid.getNumberOfRows();
}
@Override
public T next() {
final T result = grid.getSquare(rowIndex, columnIndex);
columnIndex = (columnIndex +1) % grid.getNumberOfColumns();
if(columnIndex == 0){
rowIndex++;
}
return result;
}
}