mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
Convert for-loop with Collections.addAll: support primitive types; switch off when count expression is used; wrong contracts removed
This commit is contained in:
+11
@@ -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);
|
||||
}
|
||||
}
|
||||
+12
@@ -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()]);
|
||||
}
|
||||
}
|
||||
+16
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user