Stream API migration: ignore mutable variables in nested lambdas/anonymous classes; add type argument to map/mapToObj calls where necessary

This commit is contained in:
Tagir Valeev
2016-10-24 11:01:06 +07:00
parent aff7104a99
commit 7620508bc3
7 changed files with 109 additions and 1 deletions
@@ -5,7 +5,7 @@ import java.util.stream.Collectors;
class Test {
public static <T> List<TokenFilter<T>> fromString(final T src, Function<T, List<String>> extractor) {
final List<TokenFilter<T>> result = extractor.apply(src).stream().map((Function<String, TokenFilter<T>>) TokenFilter::new).collect(Collectors.toList());
final List<TokenFilter<T>> result = extractor.apply(src).stream().<TokenFilter<T>>map(TokenFilter::new).collect(Collectors.toList());
return result;
}
@@ -0,0 +1,18 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
public List<Runnable> test(List<String> list) {
List<Runnable> result = list.stream().<Runnable>map(s -> new Runnable() {
@Override
public void run() {
String str = s;
if (str.isEmpty()) str = "none";
System.out.println(str);
}
}).collect(Collectors.toList());
return result;
}
}
@@ -0,0 +1,15 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
public List<Runnable> test(List<String> list) {
List<Runnable> result = list.stream().<Runnable>map(s -> () -> {
String str = s;
if (str.isEmpty()) str = "none";
System.out.println(str);
}).collect(Collectors.toList());
return result;
}
}
@@ -0,0 +1,21 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public List<Runnable> test(List<String> list) {
List<Runnable> result = new ArrayList<>();
for(String s : l<caret>ist) {
Runnable r = new Runnable() {
@Override
public void run() {
String str = s;
if (str.isEmpty()) str = "none";
System.out.println(str);
}
};
result.add(r);
}
return result;
}
}
@@ -0,0 +1,18 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public List<Runnable> test(List<String> list) {
List<Runnable> result = new ArrayList<>();
for(String s : li<caret>st) {
Runnable r = () -> {
String str = s;
if (str.isEmpty()) str = "none";
System.out.println(str);
};
result.add(r);
}
return result;
}
}