IDEA-CR-13704 ComparatorCombinatorsInspection: support block lambdas; EquivalenceChecker used

This commit is contained in:
Tagir Valeev
2016-09-14 12:29:01 +07:00
parent 71b251e64e
commit e47c438b25
6 changed files with 93 additions and 35 deletions

View File

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

View File

@@ -0,0 +1,14 @@
// "Replace with Comparator.comparingLong" "true"
import java.util.*;
public class Main {
void sort(List<Duration> durations) {
durations.sort(Comparator.comparingLong(d -> d.getEnd() - d.getStart()));
}
interface Duration {
long getStart();
long getEnd();
}
}

View File

@@ -0,0 +1,15 @@
// "Replace with Comparator.comparingInt" "true"
import java.util.List;
public class Main {
void sort(List<Person> persons) {
persons.sort((p1, p2) -> {<caret>
return Integer.compare(p1.getName().length(), p2.getName().length());
});
}
interface Person {
String getName();
}
}

View File

@@ -0,0 +1,14 @@
// "Replace with Comparator.comparingLong" "true"
import java.util.*;
public class Main {
void sort(List<Duration> durations) {
durations.sort((d1, d2) -> Long.com<caret>pare(d1.getEnd()-d1.getStart(), d2.getEnd()-d2.getStart()));
}
interface Duration {
long getStart();
long getEnd();
}
}

View File

@@ -0,0 +1,14 @@
// "Replace with Comparator.comparingLong" "false"
import java.util.*;
public class Main {
void sort(List<Duration> durations) {
durations.sort((d1, d2) -> Long.com<caret>pare(d1.getEnd()-d1.getStart(), d2.getEnd()-d1.getStart()));
}
interface Duration {
long getStart();
long getEnd();
}
}