diff --git a/src/main/java/matrix/CoordinateIterator.java b/src/main/java/matrix/CoordinateIterator.java index 810b71287e52821943a45e52eb7959ace9df7f06..c74cff9dbf6ebd9b91147a1867c9409483672852 100644 --- a/src/main/java/matrix/CoordinateIterator.java +++ b/src/main/java/matrix/CoordinateIterator.java @@ -8,7 +8,9 @@ import java.util.NoSuchElementException; * height range. */ class CoordinateIterator implements Iterator<Coordinate> { - + private final int width ; + private final int height ; + private Coordinate current = new Coordinate(0,0) ; /** * Creates a new {@link CoordinateIterator} with the specified width and height. * @@ -16,7 +18,8 @@ class CoordinateIterator implements Iterator<Coordinate> { * @param height The height of the coordinate range. */ public CoordinateIterator(int width, int height) { - // TODO: à compléter + this.width = width ; + this.height = height ; } /** @@ -26,8 +29,7 @@ class CoordinateIterator implements Iterator<Coordinate> { */ @Override public boolean hasNext() { - // TODO: à compléter - return false; + return current.y()<height; } /** @@ -38,7 +40,17 @@ class CoordinateIterator implements Iterator<Coordinate> { */ @Override public Coordinate next() { - // TODO: à compléter - return null; + if (!hasNext()) throw new NoSuchElementException(); + + Coordinate next = current; + // on crée un méthode update + update(); + return next; + } + + private void update(){ + current = current.right(); + if (current.x() == width) + current = new Coordinate(0, current.y()+1); } }