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

ShapeWriter.java

Blame
  • Forked from COUETOUX Basile / graphic-2020
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    CoordinateIterator.java 814 B
    package datastruct;
    
    import java.util.Iterator;
    import java.util.NoSuchElementException;
    
    class CoordinateIterator implements Iterator<Coordinate> {
        private final int width;
        private final int height;
        private int x = 0;
        private int y = 0;
    
        public CoordinateIterator(int width, int height) {
            this.width = width;
            this.height = height;
        }
    
        @Override
        public boolean hasNext() {
            return y < this.height;
        }
    
        @Override
        public Coordinate next() {
            if (!this.hasNext()) {
                throw new NoSuchElementException();
            }
            Coordinate coord = new Coordinate(this.x, this.y);
            this.x = this.x + 1;
            if (this.x == this.width) {
                this.x = 0;
                this.y = this.y + 1;
            }
            return coord;
        }
    }