40 lines
957 B
Plaintext
40 lines
957 B
Plaintext
== Why is this an issue?
|
|
|
|
Stream operations are divided into intermediate and terminal operations, and are combined to form stream pipelines.
|
|
A stream should be operated on (invoking an intermediate or terminal stream operation) only once.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
Stream<Widget> pipeline = widgets.stream().filter(b -> b.getColor() == Color.RED);
|
|
var res1 = pipeline.findAny();
|
|
var res2 = pipeline.mapToInt(b -> b.getWeight()).sum(); // Noncompliant
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps[Stream Operations]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Refactor this code so that this consumed stream pipeline is not reused.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
Primary: Operation invoked on consumed stream
|
|
|
|
Secondary: The previous terminal operation on that stream
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|