Java Utililty Methods Integer Clamp

List of utility methods to do Integer Clamp

Description

The list of methods to do Integer Clamp are organized into topic(s).

Method

intclamp(int i, int low, int high)
Converts input number to a number within the specified range.
return Math.max(Math.min(i, high), low);
intclamp(int i, int min, int max)
clamp
if (min >= max)
    throw new IllegalArgumentException("Min must be less than max. " + min + " >= " + max);
if (i < min)
    return min;
if (i > max)
    return max;
return i;
intclamp(int min, int val, int max)
clamp
return Math.min(Math.max(val, min), max);
intclamp(int min, int value, int max)
clamp
return Math.min(max, Math.max(min, value));
intclamp(int n, int l, int u)
clamp
return Math.max(Math.min(n, u), l);
intclamp(int n, int lower, int upper)
Limit the value n between lower and upper
return Math.max(lower, Math.min(n, upper));
intclamp(int n, int min, int max)
clamp
if (n > max)
    return max;
if (n < min)
    return min;
return n;
intclamp(int n, int min, int max)
Restrains a number in a interval
if (min > max)
    return clamp(n, max, min);
if (n < min)
    n = min;
if (n > max)
    n = max;
return n;
intclamp(int num, int min, int max)
Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and third parameters.
return num < min ? min : (num > max ? max : num);
intclamp(int number, int low, int high)
Returns a number clamped between low and high inclusive.
if (low == high)
    return low;
int _low = Math.min(low, high);
int _high = Math.max(low, high);
return Math.min(Math.max(number, _low), _high);