mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-09 16:39:37 +07:00
improve codegen in simple case
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// "Replace with min()" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
static class Person implements Comparable<Person> {
|
||||
String name;
|
||||
int age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
|
||||
public Person work() {
|
||||
List<Person> personList = Arrays.asList(
|
||||
new Person("Roman", 21),
|
||||
new Person("James", 25),
|
||||
new Person("Kelly", 12)
|
||||
);
|
||||
Person minPerson = personList.stream().filter(p -> p.getAge() > 13).min(Comparator.comparing(Comparator.naturalOrder())).orElse(null);
|
||||
|
||||
return minPerson;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// "Replace with min()" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
static class Person implements Comparable<Person> {
|
||||
String name;
|
||||
int age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
|
||||
public Person work() {
|
||||
List<Person> personList = Arrays.asList(
|
||||
new Person("Roman", 21),
|
||||
new Person("James", 25),
|
||||
new Person("Kelly", 12)
|
||||
);
|
||||
Person minPerson = null;
|
||||
for <caret>(Person p : personList) {
|
||||
if(p.getAge() > 13) {
|
||||
if (minPerson == null || minPerson.compareTo(p) > 0) {
|
||||
minPerson = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return minPerson;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user