In Java 21 the java.lang.Math class was updated with the static method Math.clamp, to clamp a numerical value between a
min and a max value.
Using this built-in method is now the preferred way to restrict to a given interval, as it is more readable and less error-prone.
Replace your clamp method implementation with the Math.clamp method.
int clampedValue = value > max ? max : value < min ? min : value; // Noncompliant; Replace with "Math.clamp"
int clampedValue = Math.max(min, Math.min(max, value)); // Noncompliant; Replace with "Math.clamp"
int clampedValue = Math.clamp(value, min, max);
int clampedValue = Math.clamp(value, min, max);