com.xyzwps.lib.dollar.iterable.Range Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xyzwps-dollar Show documentation
Show all versions of xyzwps-dollar Show documentation
A lodash-like, lazy and powerful java collection utils
The newest version!
package com.xyzwps.lib.dollar.iterable;
import java.util.Iterator;
import java.util.NoSuchElementException;
public final class Range implements Iterable {
/**
* Include
*/
private final int start;
/**
* Exclude
*/
private final int end;
public Range(int start, int end) {
if (start >= end) {
throw new IllegalArgumentException("The start value should be less than end value.");
}
this.start = start;
this.end = end;
}
@Override
public Iterator iterator() {
return new Iterator() {
private int current = start;
@Override
public boolean hasNext() {
return current < end;
}
@Override
public Integer next() {
if (hasNext()) {
return current++;
}
throw new NoSuchElementException();
}
};
}
}