teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コメントを少し追加!

2017/12/22 12:33

投稿

umyu
umyu

スコア5846

answer CHANGED
@@ -31,6 +31,7 @@
31
31
  public class Q105888 {
32
32
  public static void main(String[] args) throws IOException {
33
33
  try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
34
+ //配列から動的配列(ArrayList)に宣言を変更。
34
35
  List<ToDo> ToDoList = new ArrayList<>();
35
36
 
36
37
  while (true) {
@@ -77,27 +78,27 @@
77
78
  }
78
79
  }
79
80
 
80
- public static void display_month_order(List<ToDo> ToDoList) {
81
+ private static void display_month_order(List<ToDo> ToDoList) {
81
82
  System.out.println("予定です。(月昇順)");
82
83
  ToDoList.sort(new Comparator<ToDo>() {
83
84
  @Override
84
85
  public int compare(ToDo todo1, ToDo todo2) {
86
+ // 標準ライブラリのInteger.compareを使用すると、compareをシンプルに記述することができます。
85
87
  int month = Integer.compare(todo1.month, todo2.month);
88
+ // ガード節による入れ子条件記述の置き換え
86
- if (month == 0) {
89
+ if (month != 0) {
87
- return Integer.compare(todo1.day, todo2.day);
88
- } else {
89
90
  return month;
90
91
  }
92
+ return Integer.compare(todo1.day, todo2.day);
91
93
  }
92
94
  });
93
95
  ToDoList.forEach(t -> System.out.println(t));
94
96
  }
95
97
 
96
- public static void display_priority_order(List<ToDo> ToDoList) {
98
+ private static void display_priority_order(List<ToDo> ToDoList) {
97
99
  System.out.println("予定です。(優先度昇順)");
98
100
  ToDoList.sort((a, b) -> a.priority - b.priority);
99
101
  ToDoList.forEach(t -> System.out.println(t));
100
102
  }
101
103
  }
102
-
103
104
  ```