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:
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main {
|
||||
interface Person {
|
||||
int getAge();
|
||||
}
|
||||
|
||||
public long test(List<Person> collection) {
|
||||
long i = collection.stream().filter(Objects::nonNull).mapToLong(Person::getAge).sum();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+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, Person include) {
|
||||
long i = collection.stream().filter(include::equals).mapToLong(Person::getAge).sum();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
interface Person {
|
||||
double getAge();
|
||||
}
|
||||
|
||||
public double test(List<Person> collection) {
|
||||
double d = collection.stream().filter(person -> !(person.getAge() == 10)).mapToDouble(Person::getAge).sum();
|
||||
return d;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
|
||||
public List<String> test(Map<String, List<String>> map) {
|
||||
List<String> result = map.entrySet().stream().filter(entry -> !entry.getKey().isEmpty()).map(Map.Entry::getValue).filter(Objects::nonNull).flatMap(Collection::stream).map(String::trim).filter(trimmed -> !trimmed.isEmpty()).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
|
||||
public List<String> test(Map<String, List<String>> map) {
|
||||
List<String> result = map.entrySet().stream().filter(entry -> !entry.getKey().isEmpty()).map(Map.Entry::getValue).filter(Objects::nonNull).flatMap(Collection::stream).map(String::trim).filter(trimmed -> !trimmed.isEmpty()).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+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().filter(person -> person != null && person.getAge() >= 10).mapToLong(Person::getAge).sum();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "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 : col<caret>lection) {
|
||||
if(person == null) {
|
||||
continue;
|
||||
}
|
||||
i = i + person.getAge();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with forEach" "false"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
{
|
||||
for (String s : fo<caret>o) {
|
||||
if (s == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
interface Person {
|
||||
int getAge();
|
||||
}
|
||||
|
||||
public long test(List<Person> collection, Person include) {
|
||||
long i = 0;
|
||||
for(Person person : collec<caret>tion) {
|
||||
if(!include.equals(person))
|
||||
continue;
|
||||
i = i + person.getAge();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
interface Person {
|
||||
double getAge();
|
||||
}
|
||||
|
||||
public double test(List<Person> collection) {
|
||||
double d = 0;
|
||||
for(Person person : collec<caret>tion) {
|
||||
if(person.getAge() == 10)
|
||||
continue;
|
||||
d = d + person.getAge();
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
|
||||
public List<String> test(Map<String, List<String>> map) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for(Map.Entry<String, List<String>> entry : map.en<caret>trySet()) {
|
||||
if(entry.getKey().isEmpty()) continue;
|
||||
List<String> list = entry.getValue();
|
||||
if(list == null) continue;
|
||||
for(String str : list) {
|
||||
String trimmed = str.trim();
|
||||
if(trimmed.isEmpty()) continue;
|
||||
result.add(trimmed);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
|
||||
public List<String> test(Map<String, List<String>> map) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for(Map.Entry<String, List<String>> entry : map.en<caret>trySet()) {
|
||||
if(entry.getKey().isEmpty()) continue;
|
||||
else {
|
||||
List<String> list = entry.getValue();
|
||||
if (list == null) continue;
|
||||
for (String str : list) {
|
||||
String trimmed = str.trim();
|
||||
if (trimmed.isEmpty()) continue;
|
||||
else result.add(trimmed);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// "Replace with forEach" "false"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
|
||||
public List<String> test(Map<String, List<String>> map) {
|
||||
List<String> result = new ArrayList<>();
|
||||
outer:
|
||||
for(Map.Entry<String, List<String>> entry : map.ent<caret>rySet()) {
|
||||
if(entry.getKey().isEmpty()) continue;
|
||||
List<String> list = entry.getValue();
|
||||
if(list == null) continue;
|
||||
for(String str : list) {
|
||||
String trimmed = str.trim();
|
||||
if(trimmed.isEmpty()) continue outer;
|
||||
result.add(trimmed);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "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) {
|
||||
if(person == null || person.getAge() < 10)
|
||||
continue;
|
||||
i = i + person.getAge();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user