1 | public static class Unit extends EnumeratedAttribute {↵ | | 1 | public static class Unit extends EnumeratedAttribute {↵
|
|
2 | private static final String MILLISECOND = "millisecond";↵ | | 2 | private static final String MILLISECOND = "millisecond";↵
|
3 | private static final String SECOND = "second";↵ | | 3 | private static final String SECOND = "second";↵
|
4 | private static final String MINUTE = "minute";↵ | | 4 | private static final String MINUTE = "minute";↵
|
5 | private static final String HOUR = "hour";↵ | | 5 | private static final String HOUR = "hour";↵
|
6 | private static final String DAY = "day";↵ | | 6 | private static final String DAY = "day";↵
|
7 | private static final String WEEK = "week";↵ | | 7 | private static final String WEEK = "week";↵
|
8 | private static final String MONTH = "month";↵ | | 8 | private static final String MONTH = "month";↵
|
9 | private static final String YEAR = "year";↵ | | 9 | private static final String YEAR = "year";↵
|
|
10 | private static final String[] UNITS↵ | | 10 | private static final String[] UNITS = {↵
|
11 | = {MILLISECOND, SECOND, MINUTE, HOUR,↵ | | 11 | ↵
|
12 | DAY, WEEK, MONTH, YEAR↵ | | 12 | MILLISECOND,↵
|
| | | 13 | SECOND,↵
|
| | | 14 | MINUTE,↵
|
| | | 15 | HOUR,↵
|
| | | 16 | DAY,↵
|
| | | 17 | WEEK,↵
|
| | | 18 | MONTH,↵
|
| | | 19 | YEAR↵
|
13 | };↵ | | 20 | };↵
|
|
14 | private Map calendarFields = new HashMap();↵ | | 21 | private Map calendarFields = new HashMap();↵
|
|
15 | /** no arg constructor */↵ | | 22 | /** Constructor for Unit enumerated type. */↵
|
16 | public Unit() {↵ | | 23 | public Unit() {↵
|
17 | calendarFields.put(MILLISECOND,↵ | | 24 | calendarFields.put(MILLISECOND,↵
|
18 | new Integer(Calendar.MILLISECOND));↵ | | 25 | new Integer(Calendar.MILLISECOND));↵
|
19 | calendarFields.put(SECOND, new Integer(Calendar.SECOND));↵ | | 26 | calendarFields.put(SECOND, new Integer(Calendar.SECOND));↵
|
20 | calendarFields.put(MINUTE, new Integer(Calendar.MINUTE));↵ | | 27 | calendarFields.put(MINUTE, new Integer(Calendar.MINUTE));↵
|
21 | calendarFields.put(HOUR, new Integer(Calendar.HOUR_OF_DAY));↵ | | 28 | calendarFields.put(HOUR, new Integer(Calendar.HOUR_OF_DAY));↵
|
22 | calendarFields.put(DAY, new Integer(Calendar.DATE));↵ | | 29 | calendarFields.put(DAY, new Integer(Calendar.DATE));↵
|
23 | calendarFields.put(WEEK, new Integer(Calendar.WEEK_OF_YEAR));↵ | | 30 | calendarFields.put(WEEK, new Integer(Calendar.WEEK_OF_YEAR));↵
|
24 | calendarFields.put(MONTH, new Integer(Calendar.MONTH));↵ | | 31 | calendarFields.put(MONTH, new Integer(Calendar.MONTH));↵
|
25 | calendarFields.put(YEAR, new Integer(Calendar.YEAR));↵ | | 32 | calendarFields.put(YEAR, new Integer(Calendar.YEAR));↵
|
26 | }↵ | | 33 | }↵
|
|
27 | /**↵ | | 34 | /**↵
|
28 | * Convert the value to a Calendar field index.↵ | | 35 | * Convert the value to int unit value.↵
|
29 | * @return the calander value.↵ | | 36 | * @return an int value.↵
|
30 | */↵ | | 37 | */↵
|
31 | public int getCalendarField() {↵ | | 38 | public int getCalendarField() {↵
|
32 | String key = getValue().toLowerCase();↵ | | 39 | String key = getValue().toLowerCase();↵
|
33 | Integer i = (Integer) calendarFields.get(key);↵ | | 40 | Integer i = (Integer) calendarFields.get(key);↵
|
34 | return i.intValue();↵ | | 41 | return i.intValue();↵
|
35 | }↵ | | 42 | }↵
|
|
36 | /** {@inheritDoc}.↵ | | 43 | /**↵
|
| | | 44 | * Get the valid values.↵
|
| | | 45 | * @return the value values.↵
|
37 | */↵ | | 46 | */↵
|
38 | public String[] getValues() {↵ | | 47 | public String[] getValues() {↵
|
39 | return UNITS | | 48 | return UNITS
|