List of utility methods to do Number Range Check
double | rangeCheck(double value) Checks 0..1 range if ((value < 0.0) || (value > 1.0)) { throw new IllegalArgumentException("Humanity should been between 0.0 and 1.0!"); } else { return value; |
void | rangeCheck(final C start, final C end, final C step) range Check if (step.doubleValue() == 0) { throw new IllegalArgumentException("step is 0."); if (start.compareTo(end) < 0 && step.doubleValue() < 0) { throw new IllegalArgumentException("start < end, but step is negative"); |
int | rangeCheck(final int value, final int min, final int max) range Check if (value >= min && value <= max) { return value; if (min == Integer.MIN_VALUE) { throw new IllegalArgumentException( String.format("Value must be less than or equals to %,d: %,d", max, value)); if (max == Integer.MAX_VALUE) { ... |
void | rangeCheck(int arrayLen, int fromIndex, int toIndex) range Check if (fromIndex > toIndex) throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); if (fromIndex < 0) throw new ArrayIndexOutOfBoundsException(fromIndex); if (toIndex > arrayLen) throw new ArrayIndexOutOfBoundsException(toIndex); |
boolean | rangeCheck(int arrayLength, int offset, int length) range Check return offset >= 0 && offset <= arrayLength && length >= 0 && length <= arrayLength - offset;
|
void | rangeCheck(int index, int size) Checks if the given index is in range. if (index >= size) { throw new IndexOutOfBoundsException(outOfBoundsMsg(index, size)); |
void | rangeCheck(int length, int fromIndex, int toIndex) Checks that fromIndex and toIndex are in the range and throws an appropriate exception, if they aren't. if (fromIndex > toIndex) { throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); if (fromIndex < 0) { throw new ArrayIndexOutOfBoundsException(fromIndex); if (toIndex > length) { throw new ArrayIndexOutOfBoundsException(toIndex); ... |
int | rangeCheck(int value, int begin, int end) range Check if (value >= begin && value <= end) { return value; throw new IllegalArgumentException("Value [" + value + "] not in range [" + begin + "," + end + "]"); |
void | rangeCheck(int value, int min, int max) Throws an exception whenever a value falls outside the given range. if (value < min || value > max) throw new IllegalArgumentException("Value falls out of required range [" + min + "," + max + "]."); |
void | rangeCheckForAdd(int index, int size) A version of rangeCheck used by add and addAll. if (index > size || index < 0) { throw new IndexOutOfBoundsException(outOfBoundsMsg(index, size)); |