package uk.co.nickthecoder.feather.runtime;
final public class IntRange extends IntProgression {
public IntRange(int start, int endInclusive) {
super(start, endInclusive, 1);
}
public static final IntRange EMPTY = new IntRange(1, 0);
public static IntRange exclusiveRange(int start, int endInclusive) {
if (endInclusive == Integer.MIN_VALUE) return EMPTY;
return new IntRange(start, endInclusive - 1);
}
public boolean contains(int value) {
return start <= value && value <= endInclusive;
}
public IntProgression backwards() {
return new IntProgression(endInclusive, start, -1);
}
public IntProgression step(int step) {
if (step > 0) {
return new IntProgression(start, endInclusive, step);
}
if (step < 0) {
return new IntProgression(endInclusive, start, step);
}
throw new IllegalArgumentException("Step cannot be 0");
}
}