
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.
56 lines
1.3 KiB
Plaintext
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[]
|