Skip to content
Snippets Groups Projects
Commit cb86aaef authored by Guyslain's avatar Guyslain
Browse files

section 3 CoordinateIterator fini

parent 2dc6df6c
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,10 @@ import java.util.NoSuchElementException; ...@@ -9,6 +9,10 @@ import java.util.NoSuchElementException;
*/ */
class CoordinateIterator implements Iterator<Coordinate> { class CoordinateIterator implements Iterator<Coordinate> {
private Coordinate current = new Coordinate(0,0);
private final int width;
private final int height;
/** /**
* Creates a new {@link CoordinateIterator} with the specified width and height. * Creates a new {@link CoordinateIterator} with the specified width and height.
* *
...@@ -16,7 +20,8 @@ class CoordinateIterator implements Iterator<Coordinate> { ...@@ -16,7 +20,8 @@ class CoordinateIterator implements Iterator<Coordinate> {
* @param height The height of the coordinate range. * @param height The height of the coordinate range.
*/ */
public CoordinateIterator(int width, int height) { public CoordinateIterator(int width, int height) {
// TODO: à compléter this.width = width;
this.height = height;
} }
/** /**
...@@ -26,8 +31,7 @@ class CoordinateIterator implements Iterator<Coordinate> { ...@@ -26,8 +31,7 @@ class CoordinateIterator implements Iterator<Coordinate> {
*/ */
@Override @Override
public boolean hasNext() { public boolean hasNext() {
// TODO: à compléter return this.current.y() != height;
return false;
} }
/** /**
...@@ -38,7 +42,18 @@ class CoordinateIterator implements Iterator<Coordinate> { ...@@ -38,7 +42,18 @@ class CoordinateIterator implements Iterator<Coordinate> {
*/ */
@Override @Override
public Coordinate next() { public Coordinate next() {
// TODO: à compléter if (!hasNext()) {
return null; throw new NoSuchElementException();
}
Coordinate next = this.current;
this.update();
return next;
}
private void update() {
this.current = this.current.right();
if (this.current.x() == this.width) {
this.current = new Coordinate(0,this.current.y() + 1);
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment