-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceInsightRangePreset.java
More file actions
74 lines (61 loc) · 2.12 KB
/
Copy pathServiceInsightRangePreset.java
File metadata and controls
74 lines (61 loc) · 2.12 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package apu.saerok_admin.web.serviceinsight;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
public enum ServiceInsightRangePreset {
LAST_7_DAYS("recent-7", "최근 1주", 7),
LAST_14_DAYS("recent-14", "최근 2주", 14),
LAST_30_DAYS("recent-30", "최근 1달", 30),
ALL("all", "전체", null),
CUSTOM("custom", "사용자 지정", null);
private final String paramValue;
private final String displayLabel;
private final Integer days;
ServiceInsightRangePreset(String paramValue, String displayLabel, Integer days) {
this.paramValue = paramValue;
this.displayLabel = displayLabel;
this.days = days;
}
public String paramValue() {
return paramValue;
}
public String displayLabel() {
return displayLabel;
}
public boolean isCustom() {
return this == CUSTOM;
}
public boolean isAll() {
return this == ALL;
}
public Optional<RangeWindow> toWindow(LocalDate today) {
if (days == null) {
return Optional.empty();
}
if (today == null) {
return Optional.empty();
}
if (days <= 0) {
return Optional.empty();
}
LocalDate endDate = today;
LocalDate startDate = today.minusDays(days - 1L);
return Optional.of(new RangeWindow(startDate, endDate));
}
public static Optional<ServiceInsightRangePreset> fromParameter(String parameter) {
if (parameter == null || parameter.isBlank()) {
return Optional.empty();
}
String normalized = parameter.trim().toLowerCase(Locale.ROOT);
return Arrays.stream(values())
.filter(preset -> preset.paramValue.equalsIgnoreCase(normalized) || preset.name().equalsIgnoreCase(normalized))
.findFirst();
}
public static List<ServiceInsightRangePreset> quickSelections() {
return List.of(LAST_7_DAYS, LAST_14_DAYS, LAST_30_DAYS, ALL);
}
public record RangeWindow(LocalDate startDate, LocalDate endDate) {
}
}