
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
45 lines
969 B
Plaintext
45 lines
969 B
Plaintext
== Why is this an issue?
|
|
|
|
With Java 8, there's no need to write ``++Comparator++``s that compare primitive values or other ``++Comparable++``s; they can be generated for you using the ``++Comparator.comparing*++`` functions: ``++comparing++``, ``++comparingDouble++``, ``++comparingInt++``, ``++comparingLong++``.
|
|
|
|
|
|
*Note* that this rule is automatically disabled when the project's ``++sonar.java.source++`` is lower than ``++8++``.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
unparsedFiles.stream()
|
|
.sorted((f1, f2) -> f1.lines - f2.lines) // Noncompliant
|
|
.limit(30);
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
unparsedFiles.stream()
|
|
.sorted(Comparator.comparingInt(UnparsedFile::getLines()))
|
|
.limit(30);
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Use "Comparator.comparingXXX" instead.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
Custom comparator
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|