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);
}
Locating this inspection
- 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- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
This inspection depends on the Java feature 'Stream and Optional API', which is available since Java 8.
New in 2018.2
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Java, 243.23126 |
Last modified: 03 December 2024