mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-30 07:53:45 +07:00
IDEA-161925 Stream API migration: support toArray conversion, fixed mapping to initialized array, fixed final variable status, clean up in RefactoringUtil
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public Object[] testToArray(List<String> data) {
|
||||
return data.stream().filter(str -> !str.isEmpty()).toArray();
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public Object[] testToArray(List<String> data) {
|
||||
Object[] arr;
|
||||
arr = data.stream().filter(str -> !str.isEmpty()).toArray();
|
||||
System.out.println(Arrays.toString(arr));
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public Object[] testToArray(List<String> data) {
|
||||
Object[] arr = data.stream().filter(str -> !str.isEmpty()).toArray();
|
||||
System.out.println(Arrays.toString(arr));
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public List<?>[] testToArray(List<String> data) {
|
||||
return data.stream().filter(str -> !str.isEmpty()).map(Collections::singletonList).distinct().toArray(List<?>[]::new);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public String[] testToArray(List<String> data) {
|
||||
return data.stream().filter(str -> !str.isEmpty()).distinct().toArray(String[]::new);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public CharSequence[] testToArray(List<String> data) {
|
||||
return data.stream().filter(str -> !str.isEmpty()).distinct().toArray(CharSequence[]::new);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public String[] testToArray(List<String> data) {
|
||||
Set<String> result = new LinkedHashSet<>();
|
||||
if(!data.isEmpty()) {
|
||||
return data.stream().filter(str -> !str.isEmpty()).map(String::trim).distinct().toArray(String[]::new);
|
||||
}
|
||||
result.add("None");
|
||||
return result.toArray(new String[1]);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public Object[] testToArray(List<String> data) {
|
||||
return data.stream().filter(str -> !str.isEmpty()).distinct().sorted().toArray(String[]::new);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public String[][] testToArray(List<String> data) {
|
||||
return data.stream().filter(str -> !str.isEmpty()).map(str -> new String[]{str}).toArray(String[][]::new);
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace with collect" "false"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {
|
||||
String getName() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
final Set<String> names = new HashSet<>(), other = new HashSet<>();
|
||||
if(persons != null) {
|
||||
for (Person person : pers<caret>ons) {
|
||||
names.add(person.getName());
|
||||
}
|
||||
}
|
||||
System.out.println(names);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public Object[] testToArray(List<String> data) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String str : d<caret>ata) {
|
||||
if (!str.isEmpty())
|
||||
result.add(str);
|
||||
}
|
||||
return result.toArray();
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public Object[] testToArray(List<String> data) {
|
||||
Object[] arr;
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String str : d<caret>ata) {
|
||||
if (!str.isEmpty())
|
||||
result.add(str);
|
||||
}
|
||||
arr = result.toArray();
|
||||
System.out.println(Arrays.toString(arr));
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public Object[] testToArray(List<String> data) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String str : d<caret>ata) {
|
||||
if (!str.isEmpty())
|
||||
result.add(str);
|
||||
}
|
||||
Object[] arr = result.toArray();
|
||||
System.out.println(Arrays.toString(arr));
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with toArray" "false"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public Object[] testToArray(List<String> data) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String str : d<caret>ata) {
|
||||
if (!str.isEmpty())
|
||||
result.add(str);
|
||||
}
|
||||
Object[] arr = result.toArray();
|
||||
System.out.println(result);
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public List<?>[] testToArray(List<String> data) {
|
||||
Set<List<String>> result = new LinkedHashSet<>();
|
||||
for (String str : dat<caret>a) {
|
||||
if (!str.isEmpty()) {
|
||||
List<String> list = Collections.singletonList(str);
|
||||
result.add(list);
|
||||
}
|
||||
}
|
||||
return result.toArray(new List<?>[0]);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public String[] testToArray(List<String> data) {
|
||||
Set<String> result = new HashSet<>();
|
||||
for (String str : d<caret>ata) {
|
||||
if (!str.isEmpty())
|
||||
result.add(str);
|
||||
}
|
||||
return result.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with toArray" "false"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public Object[] testToArray(List<String> data) {
|
||||
Set<String> result = new IdentityHashSet<>();
|
||||
for (String str : d<caret>ata) {
|
||||
if (!str.isEmpty())
|
||||
result.add(str);
|
||||
}
|
||||
return result.toArray();
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public CharSequence[] testToArray(List<String> data) {
|
||||
Set<String> result = new LinkedHashSet<>();
|
||||
for (String str : d<caret>ata) {
|
||||
if (!str.isEmpty())
|
||||
result.add(str);
|
||||
}
|
||||
return result.toArray(new CharSequence[result.size()]);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public String[] testToArray(List<String> data) {
|
||||
Set<String> result = new LinkedHashSet<>();
|
||||
if(!data.isEmpty()) {
|
||||
for (String str : d<caret>ata) {
|
||||
if (!str.isEmpty()) {
|
||||
result.add(str.trim());
|
||||
}
|
||||
}
|
||||
return result.toArray(new String[result.size()]);
|
||||
}
|
||||
result.add("None");
|
||||
return result.toArray(new String[1]);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public Object[] testToArray(List<String> data) {
|
||||
Set<String> result = new TreeSet<>();
|
||||
for (String str : d<caret>ata) {
|
||||
if (!str.isEmpty())
|
||||
result.add(str);
|
||||
}
|
||||
return result.toArray(new String[result.size()]);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace with toArray" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public String[][] testToArray(List<String> data) {
|
||||
List<String[]> result = new ArrayList<>();
|
||||
for (String str : dat<caret>a) {
|
||||
if (!str.isEmpty()) {
|
||||
String[] arr = {str};
|
||||
result.add(arr);
|
||||
}
|
||||
}
|
||||
return result.toArray(new String[result.size()][]);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with toArray" "false"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public Object[] testToArray(List<String> data) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String str : d<caret>ata) {
|
||||
if (!str.isEmpty())
|
||||
result.add(str);
|
||||
}
|
||||
return result.toArray(new String[10]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user