mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
ComparatorCombinatorsInspection: support chain comparisons, provide fix
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
double first;
|
||||
Part second;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort(Comparator.comparingDouble((Obj o) -> o.first).thenComparing(o -> o.second));
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
double first;
|
||||
long second;
|
||||
char third(){};
|
||||
Part fourth;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort(Comparator.comparingDouble((Obj o) -> o.first).thenComparingLong(o -> o.second).thenComparingInt(Obj::third).thenComparing(o -> o.fourth));
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
Part first;
|
||||
Part second;
|
||||
int third;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort(Comparator.comparing((Obj o) -> o.first).thenComparing(o -> o.second).thenComparingInt(o -> o.third));
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
Part first;
|
||||
Part second;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort(Comparator.comparing((Obj o) -> o.first).thenComparing(o -> o.second));
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
Part first;
|
||||
Part second;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort(Comparator.comparing((Obj o) -> o.first).thenComparing(o -> o.second));
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
Part first;
|
||||
Part second;
|
||||
Part third;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort(Comparator.comparing((Obj o) -> o.first).thenComparing(o -> o.second).thenComparing(o -> o.third));
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
double first;
|
||||
Part second;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort((o1, o2) -> {<caret>
|
||||
int res = Double.compare(o1.first, o2.first);
|
||||
if(res == 0) res = o1.second.compareTo(o2.second);
|
||||
return res;
|
||||
});
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
double first;
|
||||
long second;
|
||||
char third(){};
|
||||
Part fourth;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort((o1, o2) -> {<caret>
|
||||
int res = Double.compare(o1.first, o2.first);
|
||||
if(res == 0) res = Long.compare(o1.second, o2.second);
|
||||
if(res == 0) res = o1.third() - o2.third();
|
||||
if(res == 0) res = o1.fourth.compareTo(o2.fourth);
|
||||
return res;
|
||||
});
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
Part first;
|
||||
Part second;
|
||||
int third;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort((o1, o2) -> {<caret>
|
||||
int res = o1.first.compareTo(o2.first);
|
||||
if(res == 0) res = o1.second.compareTo(o2.second);
|
||||
if(res == 0) res = o1.third - o2.third;
|
||||
return res;
|
||||
});
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
Part first;
|
||||
Part second;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort((o1, o2) -> {<caret>
|
||||
int res = o1.first.compareTo(o2.first);
|
||||
if(res == 0) res = o1.second.compareTo(o2.second);
|
||||
return res;
|
||||
});
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
Part first;
|
||||
Part second;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort((o1, o2) -> {<caret>
|
||||
int res = o1.first.compareTo(o2.first);
|
||||
return res == 0 ? o1.second.compareTo(o2.second) : res;
|
||||
});
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace with Comparator chain" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Part implements Comparable<Part> {
|
||||
}
|
||||
|
||||
static class Obj {
|
||||
Part first;
|
||||
Part second;
|
||||
Part third;
|
||||
}
|
||||
|
||||
void sort(List<Obj> objs) {
|
||||
objs.sort((o1, o2) -> {<caret>
|
||||
int res = o1.first.compareTo(o2.first);
|
||||
if(res != 0) return res;
|
||||
res = o1.second.compareTo(o2.second);
|
||||
return res == 0 ? o1.third.compareTo(o2.third) : res;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user