rspec/rules/S4029/java/rule.adoc

39 lines
932 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
unparsedFiles.stream()
.sorted((f1, f2) -> f1.lines - f2.lines) // Noncompliant
.limit(30);
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
unparsedFiles.stream()
.sorted(Comparator.comparingInt(UnparsedFile::getLines()))
.limit(30);
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]