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(final int min, final int x, final int max)
Clamps the value 'x' to be in the range [min, max].
if (max < min) {
    throw new IllegalArgumentException("Max is less than min");
return Math.max(min, Math.min(max, x));
intclamp(final int value, final int min, final int max)
clamp
return Math.min(Math.max(value, min), max);
intclamp(final int value, final int min, final int max)
clamp
if (Integer.compare(value, min) < 0) {
    return min;
if (Integer.compare(value, max) > 0) {
    return max;
return value;
intclamp(int a)
clamp
if (a < 0) {
    return 0;
} else if (a > 0xff) {
    return 0xff;
return a;
intclamp(int a, int x, int b)
Clamps the value between two endpoints.
if (x < a) {
    return a;
} else if (x > b) {
    return b;
} else {
    return x;
intclamp(int a, int x, int y)
clamp
if (x > y) {
    int m = x;
    y = x;
    x = m;
return Math.max(x, Math.min(y, a));
intclamp(int amt, int low, int high)
Constrains a value to not exceed a maximum and minimum value.
return (amt < low) ? low : ((amt > high) ? high : amt);
intclamp(int c)
Clamp a value to range 0..255.
if (c < 0) {
    return 0;
if (c > 255) {
    return 255;
return c;
intclamp(int c)
Clamp a value to the range 0..255
if (c < 0)
    return 0;
if (c > 255)
    return 255;
return c;
intclamp(int floor, int ceiling, int value)
clamp
return Math.min(ceiling, Math.max(floor, value));