1 /*
2  * Copyright 2008-2019 by Emeric Vernat
3  *
4  *     This file is part of Java Melody.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package net.bull.javamelody.internal.model;
19
20 import java.util.Locale;
21
22 import net.bull.javamelody.internal.common.I18N;
23
24 /**
25  * Énumération des périodes possibles.
26  * @author Emeric Vernat
27  */

28 public enum Period {
29     /** Jour. */
30     JOUR(1, "calendar_view_day.png""day"),
31     /** Semaine. */
32     SEMAINE(7, "calendar_view_week.png""week"),
33     /** Mois. */
34     MOIS(31, "calendar_view_month.png""month"),
35     /** Année. */
36     ANNEE(366, "calendar.png""year"),
37     /** Tout.
38      * (affiche les graphs sur 2 ans et toutes les requêtes y compris les dernières minutes) */

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