IDEA-160946 Stream API migration: understand if(...) continue at the beginning of the loop

This commit is contained in:
Tagir Valeev
2016-09-08 18:19:27 +07:00
parent 42003b5fbe
commit 29097076aa
7 changed files with 179 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 {
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,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 {
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;
}
}