rspec/rules/S4266/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
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.
2023-05-25 14:18:12 +02:00

56 lines
1.3 KiB
Plaintext

== Why is this an issue?
When using the ``++Stream++`` API, call chains should be simplified as much as possible to improve readability and maintainability.
This rule raises an issue when one of the following substitution can be made:
[frame=all]
[cols="^1,^1"]
|===
|Original|Preferred
|``++stream.collect(counting())++``|``++stream.count()++``
|``++stream.collect(maxBy(comparator))++``|``++stream.max(comparator)++``
|``++stream.collect(minBy(comparator))++``|``++stream.min(comparator)++``
|``++stream.collect(mapping(mapper))++``|``++stream.map(mapper).collect()++``
|``++stream.collect(reducing(...))++``|``++stream.reduce(...)++``
|``++stream.collect(summingInt(mapper))++``|``++stream.mapToInt(mapper).sum()++``
|``++stream.collect(summingLong(mapper))++``|``++stream.mapToLong(mapper).sum()++``
|``++stream.collect(summingDouble(mapper))++``|``++stream.mapToDouble(mapper).sum()++``
|===
=== Noncompliant code example
[source,java]
----
int count = stream.collect(counting()); // Noncompliant
----
=== Compliant solution
[source,java]
----
int count = stream.count();
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Replace this "collect(xxx())" call by "yyy"
=== Highlighting
The "stream.collect()" call
endif::env-github,rspecator-view[]