IDEA-161007 Support method chains and comparingInt/Long/Double

This commit is contained in:
Tagir Valeev
2016-09-13 16:02:23 +07:00
parent 2ede0c7c9a
commit e2c7ca2fff
8 changed files with 235 additions and 34 deletions

View File

@@ -0,0 +1,13 @@
// "Replace with Comparator.comparing" "true"
import java.util.*;
public class Main {
void sort(List<Person> persons) {
persons.sort(Comparator.comparing(p -> p.getName().toLowerCase(Locale.ENGLISH)));
}
interface Person {
String getName();
}
}

View File

@@ -0,0 +1,13 @@
// "Replace with Comparator.comparingDouble" "true"
import java.util.*;
public class Main {
void sort(List<Person> persons) {
persons.sort(Comparator.comparingDouble(p -> p.getName().length()));
}
interface Person {
String getName();
}
}

View File

@@ -0,0 +1,14 @@
// "Replace with Comparator.comparing" "true"
import java.util.*;
public class Main {
void sort(List<Person> persons) {
String p;
persons.sort(Comparator.comparing(p1 -> p1.name));
}
class Person {
String name;
}
}

View File

@@ -0,0 +1,14 @@
// "Replace with Comparator.comparing" "true"
import java.util.*;
public class Main {
void sort(List<Person> persons) {
persons.sort((p1, p2) -> p1.getName()<caret>.toLowerCase(Locale.ENGLISH)
.compareTo(p2.getName().toLowerCase(Locale.ENGLISH)));
}
interface Person {
String getName();
}
}

View File

@@ -0,0 +1,14 @@
// "Replace with Comparator.comparing" "false"
import java.util.*;
public class Main {
void sort(List<Person> persons) {
persons.sort((p1, p2) -> p1.getName()<caret>.toLowerCase(Locale.ENGLISH)
.compareTo(p2.getName().toLowerCase(Locale.CANADA)));
}
interface Person {
String getName();
}
}

View File

@@ -0,0 +1,13 @@
// "Replace with Comparator.comparingDouble" "true"
import java.util.*;
public class Main {
void sort(List<Person> persons) {
persons.sort((p1, p2) -> Double.com<caret>pare(p1.getName().length(), p2.getName().length()));
}
interface Person {
String getName();
}
}

View File

@@ -0,0 +1,14 @@
// "Replace with Comparator.comparing" "true"
import java.util.*;
public class Main {
void sort(List<Person> persons) {
String p;
persons.sort((p1, p2) -> p1.name.compar<caret>eTo(p2.name));
}
class Person {
String name;
}
}