mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 19:29:30 +07:00
IDEA-162945 Stream API migration: support cases where variable is modified and reassigned
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
void test(BufferedReader br) throws IOException {
|
||||
long count = br.lines().map(String::trim).mapToLong(String::length).sum();
|
||||
System.out.println(count);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public void test(Map<String, String[]> map) {
|
||||
List<String> result = map.entrySet().stream().filter(entry -> entry.getKey().startsWith("x")).map(Map.Entry::getValue).flatMap(Arrays::stream).map(String::trim).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with sum()" "false"
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
void test(BufferedReader br) throws IOException {
|
||||
String line = "";
|
||||
long count = 0;
|
||||
wh<caret>ile((line = br.readLine()) != null) {
|
||||
count+=(line = line.trim()).length();
|
||||
}
|
||||
System.out.println(count);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with sum()" "false"
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void test(Map<String, String[]> map) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for(Map.Entry<String, String[]> entry: m<caret>ap.entrySet()) {
|
||||
if(entry.getKey().startsWith("x")) {
|
||||
String[] arr = entry.getValue();
|
||||
for (String str : arr) {
|
||||
str = str.trim();
|
||||
result.add(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user