mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 06:11:42 +07:00
IDEA-160946 Stream API migration: understand if(...) continue at the beginning of the loop
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 {
|
||||
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;
|
||||
}
|
||||
}
|
||||
+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 {
|
||||
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