Convert for-loop with Collections.addAll: support primitive types; switch off when count expression is used; wrong contracts removed

This commit is contained in:
Tagir Valeev
2017-01-12 11:04:58 +07:00
parent f963dee4e5
commit 0957d52585
4 changed files with 48 additions and 5 deletions
@@ -0,0 +1,11 @@
// "Replace with toArray" "true"
import java.util.*;
import java.util.function.Function;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Test {
String[] test(int count) {
return IntStream.range(0, count).mapToObj(i -> Stream.of("one", "two", "three")).flatMap(Function.identity()).toArray(String[]::new);
}
}
@@ -0,0 +1,12 @@
// "Replace with toArray" "true"
import java.util.*;
public class Test {
String[] test(int count) {
List<String> result = new ArrayList<>();
for(int <caret>i=0; i < count; i++) {
Collections.addAll(result, "one", "two", "three");
}
return result.toArray(new String[result.size()]);
}
}
@@ -0,0 +1,16 @@
// "Replace with toArray" "false"
import java.util.*;
public class Test {
Object[] test(List<String[]> list) {
List<Object> result = new LinkedList<>();
for(String[] str : li<caret>st) {
if(str != null) {
Collections.addAll(result, str);
if(result.size() > 10) break;
}
}
result.sort(null);
return result.toArray();
}
}