Reports cases where the static Integer.compare() method or similar methods can be used instead of more verbose or less efficient constructs.

If x and y are already boxed integers, then x.compareTo(y) is suggested.

Example:


  public int compare(int x, int y) {
    return x > y ? 1 : x < y ? -1 : 0;
  }

After the quick-fix is applied:


  public int compare(int x, int y) {
    return Integer.compare(x, y);
  }

Note that Double.compare and Float.compare slightly change the code semantics. In particular, they make -0.0 and 0.0 distinguishable (Double.compare(-0.0, 0.0) yields -1). Also, they consistently process NaN value. In most of the cases, this semantics change actually improves the code. Use the checkbox to disable this inspection for floating point numbers if semantics change is unacceptable in your case.

New in 2017.2