Expression can be folded into Stream chain
Reports expressions with a repeating pattern that could be replaced with Stream API or a String.join() call.
Example:
boolean allStartWith(String a, String b, String c, String d, String prefix) {
return a.startsWith(prefix) && b.startsWith(prefix) && c.startsWith(prefix) && d.startsWith(prefix);
}After the quick-fix is applied:
boolean foo(String a, String b, String c, String d, String prefix) {
return Stream.of(a, b, c, d).allMatch(s -> s.startsWith(prefix));
}Example:
String joinAll(String a, String b, String c, String d) {
return a + "," + b + "," + c + "," + d;
}After the quick-fix is applied:
String joinAll(String a, String b, String c, String d) {
return String.join(",", a, b, c, d);
}- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
FoldExpressionIntoStream
This inspection depends on the Java feature 'Stream and Optional API', which is available since Java 8.
New in 2018.2
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
//noinspection FoldExpressionIntoStreamnote
Actual comment syntax will depend on the code language you are working with
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |