List of utility methods to do Clamp
short | clamp(final short value, final short lower, final short upper) Return the value if it is greater than lower and less than upper, otherwise return lower or upper, respectively. if (value < lower) { return lower; } else if (value > upper) { return upper; } else { return value; |
T | clamp(final T MIN, final T MAX, final T VALUE) clamp if (VALUE.doubleValue() < MIN.doubleValue()) return MIN; if (VALUE.doubleValue() > MAX.doubleValue()) return MAX; return VALUE; |
T | clamp(final T MIN, final T MAX, final T VALUE) clamp if (VALUE.doubleValue() < MIN.doubleValue()) return MIN; if (VALUE.doubleValue() > MAX.doubleValue()) return MAX; return VALUE; |
T | clamp(T min, T val, T max) clamp return (val.compareTo(min) < 0) ? min : (val.compareTo(max) > 0) ? max : val; |
T | clamp(T n, T l, T h) clamp return (n.doubleValue() > h.doubleValue() ? h : (n.doubleValue() < l.doubleValue() ? l : n));
|
T | clamp(T value, T minimum, T maximum) Clamps a Number if (minimum.doubleValue() > maximum.doubleValue()) { T temp = minimum; minimum = maximum; maximum = temp; if (value.doubleValue() > maximum.doubleValue()) value = maximum; if (value.doubleValue() < minimum.doubleValue()) ... |
long | clamp01(long value) Clamp the given value between 0 and 1 . return clamp(value, 0, 1);
|
long | clampAdd(long lhs, long rhs) Add the supplied arguments and handle overflow by clamping the resulting sum to Long.MinValue if the sum would have been less than Long.MinValue or Long.MaxValue if the sum would have been greater than Long.MaxValue . long sum = lhs + rhs; if ((~(lhs ^ rhs) & (lhs ^ sum)) < 0) { if (lhs >= 0) { return Long.MAX_VALUE; } else { return Long.MIN_VALUE; return sum; |