Java Utililty Methods Number Range Check

List of utility methods to do Number Range Check

Description

The list of methods to do Number Range Check are organized into topic(s).

Method

intinRange(final int value, final int min, final int max)
in Range
return Math.max(Math.min(value, max), min);
intinRange(final int value, final int min, final int max, final String fieldName)
Verifies the value and fails if the given value is outside the given range.
if (value < min || value > max) {
    throw new IllegalArgumentException(
            "The " + fieldName + " value of " + value + " is out of range: [" + min + "," + max + "].");
return value;
booleaninRange(float n, float min, float max)
Checks if x is inclusively within the specified range.
return ((n >= min) && (n < max));
booleaninrange(int actual, int leftRange, int rightRange)
inrange
return (actual >= leftRange && actual <= rightRange);
booleaninRange(int check, int range)
in Range
double from = range - (range * 5 / 100);
double to = range + (range * 5 / 100);
return from <= check && check <= to;
intinRange(int checkValue, int min, int max)
in Range
if (checkValue < min) {
    return min;
if (checkValue > max) {
    return max;
return checkValue;
booleaninRange(int firstIndex, int secondIndex)
Check whether the first index is in range of the second one.
if (firstIndex < 34 && secondIndex < 34) {
    if (Math.abs(secondIndex - firstIndex) <= 6.0) {
        return true;
    } else {
        return false;
if (firstIndex > 33) {
...
booleaninRange(int l, int u, int v, int... v_)
in Range
boolean r = v >= l && v <= u;
if (!r)
    return false;
for (int v__ : v_)
    if (!(r &= (v__ >= l && v__ <= u)))
        return false;
return true;
booleaninRange(int minValue, int maxValue, int value)
in Range
if (maxValue < minValue) {
    return false;
return (value >= minValue) && (value <= maxValue);
intinRange(int n, int lo, int hi)
Avoid a number getting out of a certain range
return n < lo ? lo : (n > hi ? hi : n);