回答編集履歴
3
if分のネストが深くならないよう修正
test
CHANGED
@@ -46,37 +46,27 @@
|
|
46
46
|
|
47
47
|
// list.sort(new ListIntegerComparator());
|
48
48
|
|
49
|
-
// Collections
|
49
|
+
// Collections.reverse(list);
|
50
50
|
|
51
51
|
class IntegerListComparator implements Comparator<List<Integer>> {
|
52
52
|
|
53
53
|
@Override public int compare(List<Integer> a, List<Integer> b) {
|
54
54
|
|
55
|
-
i
|
55
|
+
Integer i = a.get(1) - b.get(1);
|
56
56
|
|
57
|
-
|
57
|
+
if (i == 0) {
|
58
58
|
|
59
|
-
if (Objects.equals(a.get(3), b.get(3))) {
|
60
|
-
|
61
|
-
return 0;
|
62
|
-
|
63
|
-
} else {
|
64
|
-
|
65
|
-
return a.get(3) - b.get(3);
|
66
|
-
|
67
|
-
}
|
68
|
-
|
69
|
-
} else {
|
70
|
-
|
71
|
-
|
59
|
+
i = a.get(2) - b.get(2);
|
72
|
-
|
73
|
-
}
|
74
|
-
|
75
|
-
} else {
|
76
|
-
|
77
|
-
return a.get(1) - b.get(1);
|
78
60
|
|
79
61
|
}
|
62
|
+
|
63
|
+
if (i == 0) {
|
64
|
+
|
65
|
+
i = a.get(3) - b.get(3);
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
return i;
|
80
70
|
|
81
71
|
}
|
82
72
|
|
2
Java 1.8 以前?でのサンプルを追加
test
CHANGED
@@ -42,6 +42,44 @@
|
|
42
42
|
|
43
43
|
}
|
44
44
|
|
45
|
+
// Java 1.8 以前
|
45
46
|
|
47
|
+
// list.sort(new ListIntegerComparator());
|
48
|
+
|
49
|
+
// Collections#reverse(list);
|
50
|
+
|
51
|
+
class IntegerListComparator implements Comparator<List<Integer>> {
|
52
|
+
|
53
|
+
@Override public int compare(List<Integer> a, List<Integer> b) {
|
54
|
+
|
55
|
+
if (Objects.equals(a.get(1), b.get(1))) {
|
56
|
+
|
57
|
+
if (Objects.equals(a.get(2), b.get(2))) {
|
58
|
+
|
59
|
+
if (Objects.equals(a.get(3), b.get(3))) {
|
60
|
+
|
61
|
+
return 0;
|
62
|
+
|
63
|
+
} else {
|
64
|
+
|
65
|
+
return a.get(3) - b.get(3);
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
} else {
|
70
|
+
|
71
|
+
return a.get(2) - b.get(2);
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
} else {
|
76
|
+
|
77
|
+
return a.get(1) - b.get(1);
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
}
|
46
84
|
|
47
85
|
```
|
1
インデックスが間違っていた
test
CHANGED
@@ -28,9 +28,9 @@
|
|
28
28
|
|
29
29
|
list.sort(Comparator.<List<Integer>>comparingInt(l -> l.get(0))
|
30
30
|
|
31
|
+
.thenComparingInt(l -> l.get(1))
|
32
|
+
|
31
33
|
.thenComparingInt(l -> l.get(2))
|
32
|
-
|
33
|
-
.thenComparingInt(l -> l.get(3))
|
34
34
|
|
35
35
|
.reversed());
|
36
36
|
|