mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
support min/max in stream api migration, rearrange tests
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
import java.util.Arrays;
|
||||
|
||||
// "Replace with sum()" "true"
|
||||
public class Main {
|
||||
public int sum(int[] array) {
|
||||
int sum = Arrays.stream(array).sum();
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace with sum()" "true"
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public boolean check(Integer x) {
|
||||
return x % 3 == 0;
|
||||
}
|
||||
|
||||
public boolean check(int x) {
|
||||
return x % 2 == 0;
|
||||
}
|
||||
|
||||
public int sum(List<Integer> list) {
|
||||
int sum = list.stream().mapToInt(x -> x).filter(this::check).sum();
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new Main().sum(Arrays.asList(1,2,3,4,5,6)));
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with sum()" "true"
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public int sum(List<Integer> list) {
|
||||
int sum = list.stream().mapToInt(x -> x).sum();
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with sum()" "true"
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public int sum(List<Integer> list) {
|
||||
int sum = list.stream().mapToInt(x -> x).sum();
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
public long test(String[] array) {
|
||||
long i = Arrays.stream(array).filter(a -> a.startsWith("xyz")).mapToLong(String::length).sum();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main {
|
||||
public double test(String[][] array) {
|
||||
double d = 10;
|
||||
d += Arrays.stream(array).filter(Objects::nonNull).flatMap(Arrays::stream).filter(a -> a.startsWith("xyz")).mapToDouble(a -> 1.0 / a.length()).sum();
|
||||
return d;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
interface Person {
|
||||
int getAge();
|
||||
}
|
||||
|
||||
public long test(List<Person> collection) {
|
||||
long i = collection.stream().mapToLong(Person::getAge).sum();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
int sum;
|
||||
if(Math.random() > 0.5) {
|
||||
sum = 10;
|
||||
} else {
|
||||
sum = data.stream().filter(str -> str.startsWith("xyz")).mapToInt(String::length).filter(len -> len > 10).map(len -> len * 2).sum();
|
||||
}
|
||||
System.out.println(sum);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
int sum = 0;
|
||||
if(Math.random() > 0.5) {
|
||||
System.out.println("oops");
|
||||
} else {
|
||||
sum = data.stream().filter(str -> str.startsWith("xyz")).mapToInt(String::length).filter(len -> len > 10).map(len -> len * 2).sum();
|
||||
}
|
||||
System.out.println(sum);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
public void test(long[] list) {
|
||||
int sum = Arrays.stream(list).mapToInt(x -> (int) x).sum();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
public void test(double[] list) {
|
||||
int sum = Arrays.stream(list).mapToInt(x -> (int) (x * x)).sum();
|
||||
}
|
||||
}
|
||||
+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();
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with sum()" "false"
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public int sum(List<Float> list) {
|
||||
int sum = 0;
|
||||
for(float x : li<caret>st) {
|
||||
sum += x;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with sum()" "true"
|
||||
public class Main {
|
||||
public int sum(int[] array) {
|
||||
int sum = 0;
|
||||
for(int x : arr<caret>ay) {
|
||||
sum += x;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Replace with sum()" "true"
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public boolean check(Integer x) {
|
||||
return x % 3 == 0;
|
||||
}
|
||||
|
||||
public boolean check(int x) {
|
||||
return x % 2 == 0;
|
||||
}
|
||||
|
||||
public int sum(List<Integer> list) {
|
||||
int sum = 0;
|
||||
for(int x : li<caret>st) {
|
||||
if(check(x))
|
||||
sum += x;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new Main().sum(Arrays.asList(1,2,3,4,5,6)));
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with sum()" "true"
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public int sum(List<Integer> list) {
|
||||
int sum = 0;
|
||||
for(int x : li<caret>st) {
|
||||
sum += x;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with sum()" "true"
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public int sum(List<Integer> list) {
|
||||
int sum = 0;
|
||||
for(Integer x : li<caret>st) {
|
||||
sum += x;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace with sum()" "false"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public long testFor(List<List<String>> list) {
|
||||
long count = 0;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
for (String s : list.g<caret>et(i)) {
|
||||
String trimmed = s.trim();
|
||||
if (trimmed.isEmpty()) {
|
||||
count += i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
public class Main {
|
||||
public long test(String[] array) {
|
||||
long i = 0;
|
||||
for(String a : ar<caret>ray) {
|
||||
if(a.startsWith("xyz"))
|
||||
i = i + a.length();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with sum()" "false"
|
||||
|
||||
public class Main {
|
||||
public long test(String[] array) {
|
||||
float i = 0;
|
||||
for(String a : ar<caret>ray) {
|
||||
if(a.startsWith("xyz"))
|
||||
i = i + a.length();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
public class Main {
|
||||
public double test(String[][] array) {
|
||||
double d = 10;
|
||||
for(String[] arr : arra<caret>y) {
|
||||
if(arr != null) {
|
||||
for (String a : arr) {
|
||||
if (a.startsWith("xyz"))
|
||||
d = d + 1.0/a.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
interface Person {
|
||||
int getAge();
|
||||
}
|
||||
|
||||
public long test(List<Person> collection) {
|
||||
long i = 0;
|
||||
for(Person person : collecti<caret>on) {
|
||||
i = i + person.getAge();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
int sum = 0;
|
||||
if(Math.random() > 0.5) {
|
||||
sum = 10;
|
||||
} else {
|
||||
for (String str : dat<caret>a) {
|
||||
if (str.startsWith("xyz")) {
|
||||
int len = str.length();
|
||||
if (len > 10) {
|
||||
sum += len * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println(sum);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void testPrimitiveMap(List<String> data) {
|
||||
int sum = 0;
|
||||
if(Math.random() > 0.5) {
|
||||
System.out.println("oops");
|
||||
} else {
|
||||
for (String str : dat<caret>a) {
|
||||
if (str.startsWith("xyz")) {
|
||||
int len = str.length();
|
||||
if (len > 10) {
|
||||
sum += len * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println(sum);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
public class Main {
|
||||
public void test(long[] list) {
|
||||
int sum = 0;
|
||||
for(long x : li<caret>st) {
|
||||
sum+=x;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
public class Main {
|
||||
public void test(double[] list) {
|
||||
int sum = 0;
|
||||
for(double x : li<caret>st) {
|
||||
sum+=x * x;
|
||||
}
|
||||
}
|
||||
}
|
||||
+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