001package fr.aumgn.bukkitutils.geom.vector;
002
003import java.util.Iterator;
004import java.util.NoSuchElementException;
005
006import fr.aumgn.bukkitutils.geom.Vector;
007
008public class VectorIterator implements Iterator<Vector> {
009
010    private Vector min;
011    private Vector max;
012    private boolean hasNext;
013    private double nextX;
014    private double nextY;
015    private double nextZ;
016
017    public VectorIterator(Vector min, Vector max) {
018        this.min = min;
019        this.max = max;
020        this.hasNext = true;
021        this.nextX = min.getX();
022        this.nextY = min.getY();
023        this.nextZ = min.getZ();
024    }
025
026    public boolean hasNext() {
027        return hasNext;
028    }
029
030    public Vector next() {
031        if (!hasNext) {
032            throw new NoSuchElementException();
033        }
034
035        Vector answer = new Vector(nextX, nextY, nextZ);
036        if (++nextX <= max.getX()) {
037            return answer;
038        }
039
040        nextX = min.getX();
041        if (++nextZ <= max.getZ()) {
042            return answer;
043        }
044
045        nextZ = min.getZ();
046        if (++nextY <= max.getY()) {
047            return answer;
048        }
049
050        hasNext = false;
051        return answer;
052    }
053
054    public void remove() {
055        throw new UnsupportedOperationException();
056    }
057}