mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-21 23:38:50 -05:00
[!] Stream.count() may short-circuit and not traverse any elements at all.
@apiNote An implementation may choose to not execute the stream pipeline (either sequentially or in parallel) if it is capable of computing the count directly from the stream source. In such cases no source elements will be traversed and no intermediate operations will be evaluated. Behavioral parameters with side-effects, which are strongly discouraged except for harmless cases such as debugging, may be affected. For example, consider the following stream: List<String> l = Arrays.asList("A", "B", "C", "D"); long count = l.stream().peek(System.out::println).count(); The number of elements covered by the stream source, a List, is known and the intermediate operation, peek, does not inject into or remove elements from the stream (as may be the case for flatMap or filter operations). Thus the count is the size of the List and there is no need to execute the pipeline and, as a side-effect, print out the list elements.
This commit is contained in:
parent
6fb43e79b7
commit
a9285d53fd
@ -139,10 +139,7 @@ public class ArgumentProcessor {
|
||||
}
|
||||
|
||||
private int print(Stream<?> values) {
|
||||
return values.map(v -> {
|
||||
System.out.println(v);
|
||||
return v;
|
||||
}).count() > 0 ? SUCCESS : ERROR;
|
||||
return values.peek(System.out::println).mapToInt(v -> 1).sum() > 0 ? SUCCESS : ERROR;
|
||||
}
|
||||
|
||||
private void printStegosaurus(String line1, String line2) {
|
||||
|
Loading…
Reference in New Issue
Block a user