mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
IDEA-161706 Migration to Stream API: support primitive types int/long/double
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with anyMatch()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public boolean testPrimitiveMap(List<String> data) {
|
||||
return data.stream().filter(str -> str.startsWith("xyz")).mapToInt(String::length).anyMatch(len -> len > 10);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
List<Integer> list = data.stream().filter(str -> str.startsWith("xyz")).mapToInt(String::length).filter(len -> len > 10).boxed().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
List<String> list = data.stream().filter(str -> str.startsWith("xyz")).mapToInt(String::length).filter(len -> len > 10).mapToObj(String::valueOf).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with count()" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
public int testPrimitiveArray(int[] data) {
|
||||
int count = (int) Arrays.stream(data).mapToLong(val -> val * val).filter(square -> square > 100).count();
|
||||
return count;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with findFirst()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public int testPrimitiveMap(List<String> data) {
|
||||
return data.stream().filter(str -> str.startsWith("xyz")).mapToInt(String::length).filter(len -> len > 10).findFirst().orElse(0);
|
||||
}
|
||||
}
|
||||
+4
-8
@@ -1,17 +1,13 @@
|
||||
// "Replace with forEach" "true"
|
||||
// "Replace with collect" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public List<Integer> test(int[][] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
Arrays.stream(arr).filter(Objects::nonNull).forEach(subArr -> {
|
||||
for (int str : subArr) {
|
||||
result.add(str);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
List<Integer> result = Arrays.stream(arr).filter(Objects::nonNull).flatMapToInt(Arrays::stream).boxed().collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -6,9 +6,9 @@ import java.util.Objects;
|
||||
class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
String foo(){
|
||||
foo.stream().filter(Objects::isNull).forEach(s -> {
|
||||
int i = 0;
|
||||
});
|
||||
foo.stream().filter(Objects::isNull).forEach(s -> bar());
|
||||
return null;
|
||||
}
|
||||
|
||||
bar() {}
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
int sum = data.stream().filter(str -> str.startsWith("xyz")).mapToInt(String::length).filter(len -> len > 10).map(len -> len * 2).sum();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
long sum = data.stream().filter(str -> str.startsWith("xyz")).mapToInt(String::length).filter(len -> len > 10).asLongStream().sum();
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with anyMatch()" "false"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public boolean testPrimitiveMap(List<String> data) {
|
||||
for(String str : d<caret>ata) {
|
||||
if(str.startsWith("xyz")) {
|
||||
float len = str.length();
|
||||
if(len > 10) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with anyMatch()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public boolean testPrimitiveMap(List<String> data) {
|
||||
for(String str : d<caret>ata) {
|
||||
if(str.startsWith("xyz")) {
|
||||
int len = str.length();
|
||||
if(len > 10) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
for(String str : d<caret>ata) {
|
||||
if(str.startsWith("xyz")) {
|
||||
int len = str.length();
|
||||
if(len > 10) {
|
||||
list.add(len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for(String str : d<caret>ata) {
|
||||
if(str.startsWith("xyz")) {
|
||||
int len = str.length();
|
||||
if(len > 10) {
|
||||
list.add(String.valueOf(len));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with count()" "true"
|
||||
|
||||
public class Main {
|
||||
public int testPrimitiveArray(int[] data) {
|
||||
int count = 0;
|
||||
for(int val : dat<caret>a) {
|
||||
long square = val*val;
|
||||
if(square > 100) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with count()" "false"
|
||||
|
||||
public class Main {
|
||||
public int testPrimitiveArray(short[] data) {
|
||||
int count = 0;
|
||||
for(int val : dat<caret>a) {
|
||||
long square = val*val;
|
||||
if(square > 100) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with findFirst()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public int testPrimitiveMap(List<String> data) {
|
||||
for(String str : dat<caret>a) {
|
||||
if(str.startsWith("xyz")) {
|
||||
int len = str.length();
|
||||
if(len > 10) {
|
||||
return len;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace with findFirst()" "false"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// Not supported as OptionalInt lacks mapping method
|
||||
public class Main {
|
||||
public int testPrimitiveMap(List<String> data) {
|
||||
for(String str : dat<caret>a) {
|
||||
if(str.startsWith("xyz")) {
|
||||
int len = str.length();
|
||||
if(len > 10) {
|
||||
return len * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
// "Replace with forEach" "true"
|
||||
// "Replace with collect" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public List<Integer> test(int[][] arr) {
|
||||
|
||||
+3
-1
@@ -6,8 +6,10 @@ class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
String foo(){
|
||||
for (String s : fo<caret>o) {
|
||||
if (s == null) int i = 0;
|
||||
if (s == null) bar();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
bar() {}
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
int sum = 0;
|
||||
for(String str : dat<caret>a) {
|
||||
if(str.startsWith("xyz")) {
|
||||
int len = str.length();
|
||||
if(len > 10) {
|
||||
sum += len*2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
long sum = 0;
|
||||
for(String str : da<caret>ta) {
|
||||
if(str.startsWith("xyz")) {
|
||||
int len = str.length();
|
||||
if(len > 10) {
|
||||
sum += len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user