Skip to content
Snippets Groups Projects
Select Git revision
  • 095239902ce939cd3767e8ff144e0a1ce2beb5e5
  • master default protected
2 results

IntervalSequencesTest.java

Blame
  • Forked from NAVES Guyslain / ProgAvExercices
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    GridIterator.java 780 B
    import java.util.Iterator;
    
     /**
     * {@link GridIterator} instances are used to iterate over the cells of a grid.
     */
    public class GridIterator implements Iterator<Cell> {
        private int rowIndex;
        private int columnIndex;
        private Grid 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 Cell next() {
            final Cell result = grid.getCell(rowIndex, columnIndex);
            columnIndex = (columnIndex +1) % grid.getNumberOfColumns();
            if(columnIndex == 0){
                rowIndex++;
            }
            return result;
        }
    }