-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTaskStatisticsPolicy.java
More file actions
43 lines (36 loc) · 1.44 KB
/
TaskStatisticsPolicy.java
File metadata and controls
43 lines (36 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package clap.server.domain.policy.task;
import clap.server.common.annotation.architecture.Policy;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.stream.Collectors;
@Policy
public class TaskStatisticsPolicy {
private static final String DISPLAY_FORMAT = "M월 d일";
public Map<String, Long> formatStatistics(Map<String, Long> statistics) {
return statistics.entrySet().stream()
.collect(Collectors.toMap(
entry -> formatDate(entry.getKey()),
Entry::getValue,
(v1, v2) -> v1,
TreeMap::new
));
}
private String formatDate(String dateString) {
LocalDate date = LocalDate.parse(dateString);
return date.format(DateTimeFormatter.ofPattern(DISPLAY_FORMAT));
}
public Map<String, Long> formatDayStatistics(Map<String, Long> statistics) {
for (int i = 0; i <= 23; i++) statistics.putIfAbsent(String.format("%02d", i), 0L);
return statistics.entrySet().stream()
.collect(Collectors.toMap(
entry -> Integer.parseInt(entry.getKey()) + "시",
Entry::getValue,
(v1, v2) -> v1,
LinkedHashMap::new
));
}
}