mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-160637 Stream API migration: support map and flatMap steps
This commit is contained in:
+1
-3
@@ -5,9 +5,7 @@ import java.util.List;
|
||||
class Sample {
|
||||
public static void main(List<String> testTags) {
|
||||
final List<String> resultJava7 = new ArrayList<>(testTags.size());
|
||||
testTags.stream().filter(tag -> !resultJava7.contains(tag.trim())).forEach(tag -> {
|
||||
resultJava7.add(tag.trim());
|
||||
});
|
||||
testTags.stream().filter(tag -> !resultJava7.contains(tag.trim())).forEach(tag -> resultJava7.add(tag.trim()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -4,8 +4,6 @@ import java.util.List;
|
||||
|
||||
abstract class Sample implements List<String> {
|
||||
void main() {
|
||||
this.stream().filter(tag -> !contains(tag.trim())).forEach(tag -> {
|
||||
add(tag.trim());
|
||||
});
|
||||
this.stream().filter(tag -> !contains(tag.trim())).forEach(tag -> add(tag.trim()));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -4,9 +4,7 @@ import java.util.List;
|
||||
|
||||
abstract class Sample implements List<String> {
|
||||
void main() {
|
||||
this.stream().filter(tag -> !foo(this)).forEach(tag -> {
|
||||
add(tag.trim());
|
||||
});
|
||||
this.stream().filter(tag -> !foo(this)).forEach(tag -> add(tag.trim()));
|
||||
}
|
||||
|
||||
static boolean foo(List<String> a){ return false;}
|
||||
|
||||
+1
-3
@@ -4,9 +4,7 @@ import java.util.List;
|
||||
|
||||
class Sample extends ArrayList<String> {
|
||||
void main() {
|
||||
this.stream().filter(tag -> !super.contains(tag)).forEach(tag -> {
|
||||
add(tag.trim());
|
||||
});
|
||||
this.stream().filter(tag -> !super.contains(tag)).forEach(tag -> add(tag.trim()));
|
||||
}
|
||||
|
||||
static boolean foo(List<String> a){ return false;}
|
||||
|
||||
+1
-3
@@ -5,9 +5,7 @@ import java.util.List;
|
||||
class Sample {
|
||||
public static void main(List<String> testTags) {
|
||||
final List<String> resultJava7 = new ArrayList<>(testTags.size());
|
||||
testTags.stream().filter(tag -> !foo(resultJava7)).forEach(tag -> {
|
||||
resultJava7.add(tag.trim());
|
||||
});
|
||||
testTags.stream().filter(tag -> !foo(resultJava7)).forEach(tag -> resultJava7.add(tag.trim()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public void test(List<Set<String>> nested) {
|
||||
List<String> result = nested.stream().filter(element -> element != null).flatMap(Collection::stream)
|
||||
.filter(str -> str.startsWith("xyz")).map(String::trim).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public void test(List<String[]> list) {
|
||||
List<String> result = list.stream().filter(arr -> arr.length > 2).flatMap(Arrays::stream).map(String::trim).filter(trimmed -> !trimmed.isEmpty()).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+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(arr -> Arrays.stream(arr)).map(String::trim).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with forEach" "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<>();
|
||||
map.entrySet().stream().filter(entry -> entry.getKey().startsWith("x")).map(Map.Entry::getValue).forEach(arr -> {
|
||||
for (String str : arr) {
|
||||
result.add(str.trim() + arr.length);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Main {
|
||||
public void test(List<Set<String>> nested) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (Set<String> element : nes<caret>ted) {
|
||||
if (element != null) {
|
||||
for (String str : element) {
|
||||
if (str.startsWith("xyz")) {
|
||||
String target = str.trim();
|
||||
result.add(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void test(List<String[]> list) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for(String[] arr : li<caret>st) {
|
||||
if(arr.length > 2) {
|
||||
for(String str : arr) {
|
||||
String trimmed = str.trim();
|
||||
if(!trimmed.isEmpty()) {
|
||||
result.add(trimmed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "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) {
|
||||
result.add(str.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with forEach" "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: map.<caret>entrySet())
|
||||
if (entry.getKey().startsWith("x")) {
|
||||
String[] arr = entry.getValue();
|
||||
for (String str : arr) {
|
||||
result.add(str.trim()+arr.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user