package org.psjava.util;

import java.util.Iterator;

public class IntSequenceIterator {

	public static Iterator<Integer> create(final int start, final int step, final int size) {
		return new ReadOnlyIterator<Integer>() {
			int nextIndex = 0;

			@Override
			public boolean hasNext() {
				return nextIndex < size;
			}

			@Override
			public Integer next() {
				return start + step * (nextIndex++);
			}
		};
	}

	private IntSequenceIterator() {
	}

}

package org.psjava.util;

import java.util.Iterator;

public class IntSequenceIterator {

	public static Iterator<Integer> create(final int start, final int step, final int size) {
		final int last = start + step * (size-1);
		return new ReadOnlyIterator<Integer>() {
			int next = start;

			@Override
			public boolean hasNext() {
				return next <= last;
			}

			@Override
			public Integer next() {
				int r = next;
				next += step;
				return r;
			}
		};
	}

	private IntSequenceIterator() {
	}

}

improve performance of IntSequenceIterator