1
18 package net.bull.javamelody.internal.model;
19
20 import java.util.Locale;
21
22 import net.bull.javamelody.internal.common.I18N;
23
24
28 public enum Period {
29
30 JOUR(1, "calendar_view_day.png", "day"),
31
32 SEMAINE(7, "calendar_view_week.png", "week"),
33
34 MOIS(31, "calendar_view_month.png", "month"),
35
36 ANNEE(366, "calendar.png", "year"),
37
39 TOUT(2 * 366, "calendar.png", "all");
40
41 private final String code;
42 private final String mailCode;
43 private final int durationDays;
44 private final int durationSeconds;
45 private final String iconName;
46 private final Range range;
47
48 Period(int durationDays, String iconName, String mailCode) {
49 this.durationDays = durationDays;
50 this.durationSeconds = durationDays * 24 * 60 * 60;
51 this.iconName = iconName;
52 this.mailCode = mailCode;
53 this.code = this.toString().toLowerCase(Locale.ENGLISH);
54 this.range = Range.createPeriodRange(this);
55 }
56
57 public static Period valueOfIgnoreCase(String period) {
58 return valueOf(period.toUpperCase(Locale.ENGLISH).trim());
59 }
60
61 public static Period valueOfByMailCode(String mailPeriod) {
62 final String mailCode = mailPeriod.toLowerCase(Locale.ENGLISH).trim();
63 for (final Period period : values()) {
64 if (period.mailCode.equals(mailCode)) {
65 return period;
66 }
67 }
68 throw new IllegalArgumentException(mailPeriod);
69 }
70
71 public String getCode() {
72 return code;
73 }
74
75 public String getMailCode() {
76 return mailCode;
77 }
78
79 public String getLabel() {
80 return I18N.getString(code + "_label");
81 }
82
83 public String getLinkLabel() {
84 return I18N.getString(code + "_link_label");
85 }
86
87 int getDurationDays() {
88 return durationDays;
89 }
90
91 int getDurationSeconds() {
92 return durationSeconds;
93 }
94
95 public String getIconName() {
96 return iconName;
97 }
98
99 public Range getRange() {
100 return range;
101 }
102 }
103