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

StringclampString(String string, int limit)
clamp String
return string.substring(0, string.length() > limit ? limit : string.length());
intclampTo_0_255(int i)
clamp T_
return i > 255 ? 255 : (i < 0 ? 0 : i);
intclampToByte(int c)
Clamp a value to the range 0..255
if (c < 0)
    return 0;
if (c > 255)
    return 255;
return c;
intclampToByteSize(int value)
Clamp a value, I.E.
if (value >= BYTE_MAX_SIZE) {
    return BYTE_MAX_SIZE;
} else if (value <= 0) {
    return 0;
return value;
shortclampToShort(int x)
clamp To Short
return (short) (x > Short.MAX_VALUE ? Short.MAX_VALUE : (x < Short.MIN_VALUE ? Short.MIN_VALUE : x));
shortclampUShortNegative(int in)
clamp U Short Negative
return (in < 0 ? (short) 0 : (short) in);
intClampValue(int value, int lowerBound, int upperBound)
Clamp Value
if (value < lowerBound) {
    return lowerBound;
} else if (value > upperBound) {
    return upperBound;
} else {
    return value;