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

intclampInt(final int min, final int max, final int value)
clamp Int
if ((value < min) || (value > max)) {
    if (value < min) {
        return min;
    } else if (value > max) {
        return max;
return value;
...
intclampInt(final int min, final int value, final int max)
Clamps an integer within the bounds [min, max] by setting it the the closest bound if it not within the range.
return Math.min(max, Math.max(min, value));
intclampInt(int value, int min, int max)
Clamps an int between the given minimum and maximum values.
return value < min ? min : value > max ? max : value;
intclampInt(int value, int min, int max)
clamp Int
return (value < min) ? min : (value > max) ? max : value;
intCLAMPIS(int a, int b, int c)
CLAMPIS
return a < b ? b : a > c ? c : a;
intclampLoop(int v, int min, int max)
clamp Loop
if (min == max)
    return min;
int range = max - min;
if (v < min)
    v = max + 1 - ((min - v) % range);
if (v > max)
    v = min - 1 + ((v - max) % range);
return v;
...
intclampMono(int value)
Clamp a mono audio sample to a valid range [-0x8000..0x7FFF].
return Math.max(Math.min(value, 0x7FFF), -0x8000);
intclampNonNegative(int i, int a, int b)
Returns i if i is between a and b , otherwise the boundary of [a..b].
if (a < 0)
    a = 0;
if (b < 0)
    b = 0;
if (b < a) {
    int tmp = a;
    a = b;
    b = tmp;
...
intclampPower(int num)
clamp Power
int initialCapacity = 1;
if (num >= initialCapacity) {
    initialCapacity = num;
    initialCapacity |= (initialCapacity >>> 1);
    initialCapacity |= (initialCapacity >>> 2);
    initialCapacity |= (initialCapacity >>> 4);
    initialCapacity |= (initialCapacity >>> 8);
    initialCapacity |= (initialCapacity >>> 16);
...
intclampRGB(int val)
Clamps an integer value between 0 and 255
if (val < 0) {
    return 0;
} else if (val > 255) {
    return 255;
return val;