1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.time;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.orekit.errors.OrekitException;
23 import org.orekit.errors.OrekitMessages;
24
25
26
27
28
29
30
31
32 public enum Month {
33
34
35 JANUARY( 1),
36
37
38 FEBRUARY( 2),
39
40
41 MARCH( 3),
42
43
44 APRIL( 4),
45
46
47 MAY( 5),
48
49
50 JUNE( 6),
51
52
53 JULY( 7),
54
55
56 AUGUST( 8),
57
58
59 SEPTEMBER( 9),
60
61
62 OCTOBER(10),
63
64
65 NOVEMBER(11),
66
67
68 DECEMBER(12);
69
70
71 private static final Map<String, Month> STRINGS_MAP = new HashMap<String, Month>();
72 static {
73 for (final Month month : values()) {
74 STRINGS_MAP.put(month.getLowerCaseName(), month);
75 STRINGS_MAP.put(month.getLowerCaseAbbreviation(), month);
76 }
77 }
78
79
80 private static final Map<Integer, Month> NUMBERS_MAP = new HashMap<Integer, Month>();
81 static {
82 for (final Month month : values()) {
83 NUMBERS_MAP.put(month.getNumber(), month);
84 }
85 }
86
87
88 private final int number;
89
90
91 private final String lowerCaseName;
92
93
94 private final String capitalizedName;
95
96
97 private final String upperCaseAbbreviation;
98
99
100 private final String lowerCaseAbbreviation;
101
102
103 private final String capitalizedAbbreviation;
104
105
106
107
108 private Month(final int number) {
109 this.number = number;
110 lowerCaseName = toString().toLowerCase();
111 capitalizedName = toString().charAt(0) + lowerCaseName.substring(1);
112 upperCaseAbbreviation = toString().substring(0, 3);
113 lowerCaseAbbreviation = lowerCaseName.substring(0, 3);
114 capitalizedAbbreviation = capitalizedName.substring(0, 3);
115 }
116
117
118
119
120 public int getNumber() {
121 return number;
122 }
123
124
125
126
127 public String getUpperCaseName() {
128 return toString();
129 }
130
131
132
133
134 public String getLowerCaseName() {
135 return lowerCaseName;
136 }
137
138
139
140
141 public String getCapitalizedName() {
142 return capitalizedName;
143 }
144
145
146
147
148 public String getUpperCaseAbbreviation() {
149 return upperCaseAbbreviation;
150 }
151
152
153
154
155 public String getLowerCaseAbbreviation() {
156 return lowerCaseAbbreviation;
157 }
158
159
160
161
162 public String getCapitalizedAbbreviation() {
163 return capitalizedAbbreviation;
164 }
165
166
167
168
169
170
171
172
173
174
175
176 public static Month parseMonth(final String s) {
177 final String normalizedString = s.trim().toLowerCase();
178 final Month month = STRINGS_MAP.get(normalizedString);
179 if (month == null) {
180 try {
181 return getMonth(Integer.parseInt(normalizedString));
182 } catch (NumberFormatException nfe) {
183 throw OrekitException.createIllegalArgumentException(OrekitMessages.UNKNOWN_MONTH, s);
184 }
185 }
186 return month;
187 }
188
189
190
191
192
193
194 public static Month getMonth(final int number) {
195 final Month month = NUMBERS_MAP.get(number);
196 if (month == null) {
197 throw OrekitException.createIllegalArgumentException(OrekitMessages.UNKNOWN_MONTH, number);
198 }
199 return month;
200 }
201
202 }