support min/max in stream api migration, rearrange tests

This commit is contained in:
Roman Ivanov
2017-08-02 12:57:45 +07:00
parent dd4ba58889
commit 72bab18a58
561 changed files with 2091 additions and 17 deletions
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}