package com.jscape.util.collections;

import com.jscape.util.ArrayTools;

/**
 * @author Alex Usun
 */
public class LongArrayIterator
        implements LongIterator {

    protected final long[] data;
    protected final int initialPosition;
    protected final int length;
    protected int position;

    public LongArrayIterator(long[] data, int offset, int length) {
        this.data = data;
        this.initialPosition = offset;
        this.length = length;
        this.position = this.initialPosition;
    }

    public LongArrayIterator(long[] data) {
        this(data, 0, data.length);
    }

    public boolean hasNext() {
        return this.position < this.length;
    }

    public long next() {
        return this.data[this.position++];
    }

    public void reset() {
        this.position = this.initialPosition;
    }

    @Override
    public String toString() {
        return "LongArrayIterator {"
                + "data=" + ArrayTools.toString(this.data)
                + ", initialPosition=" + this.initialPosition
                + ", length=" + this.length
                + ", position=" + this.position
                + '}';
    }
}
