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,↵ | | 11 | ↵
|
12 | SECOND,↵ | | |
|
13 | MINUTE,↵ | | |
|
14 | HOUR,↵ | | |
|
15 | DAY,↵ | | |
|
16 | WEEK,↵ | | |
|
17 | MONTH,↵ | | |
|
18 | YEAR↵ | | |
|
19 | ↵ | | 12 | = {MILLISECOND, SECOND, MINUTE, HOUR,↵
|
20 | };↵ | | 13 | DAY, WEEK, MONTH, YEAR };↵
|
|
21 | private Map calendarFields = new HashMap();↵ | | 14 | private Map calendarFields = new HashMap();↵
|
|
22 | /** Constructor for Unit enumerated type. */↵ | | 15 | /** no arg constructor */↵
|
23 | public Unit() {↵ | | 16 | public Unit() {↵
|
24 | calendarFields.put(MILLISECOND,↵ | | 17 | calendarFields.put(MILLISECOND,↵
|
25 | new Integer(Calendar.MILLISECOND));↵ | | 18 | new Integer(Calendar.MILLISECOND));↵
|
26 | calendarFields.put(SECOND, new Integer(Calendar.SECOND));↵ | | 19 | calendarFields.put(SECOND, new Integer(Calendar.SECOND));↵
|
27 | calendarFields.put(MINUTE, new Integer(Calendar.MINUTE));↵ | | 20 | calendarFields.put(MINUTE, new Integer(Calendar.MINUTE));↵
|
28 | calendarFields.put(HOUR, new Integer(Calendar.HOUR_OF_DAY));↵ | | 21 | calendarFields.put(HOUR, new Integer(Calendar.HOUR_OF_DAY));↵
|
29 | calendarFields.put(DAY, new Integer(Calendar.DATE));↵ | | 22 | calendarFields.put(DAY, new Integer(Calendar.DATE));↵
|
30 | calendarFields.put(WEEK, new Integer(Calendar.WEEK_OF_YEAR));↵ | | 23 | calendarFields.put(WEEK, new Integer(Calendar.WEEK_OF_YEAR));↵
|
31 | calendarFields.put(MONTH, new Integer(Calendar.MONTH));↵ | | 24 | calendarFields.put(MONTH, new Integer(Calendar.MONTH));↵
|
32 | calendarFields.put(YEAR, new Integer(Calendar.YEAR));↵ | | 25 | calendarFields.put(YEAR, new Integer(Calendar.YEAR));↵
|
33 | }↵ | | 26 | }↵
|
|
34 | /**↵ | | 27 | /**↵
|
35 | * Convert the value to int unit value.↵ | | 28 | * Convert the value to a Calendar field index.↵
|
36 | * @return an int value.↵ | | 29 | * @return the calander value.↵
|
37 | */↵ | | 30 | */↵
|
38 | public int getCalendarField() {↵ | | 31 | public int getCalendarField() {↵
|
39 | String key = getValue().toLowerCase();↵ | | 32 | String key = getValue().toLowerCase();↵
|
40 | Integer i = (Integer) calendarFields.get(key);↵ | | 33 | Integer i = (Integer) calendarFields.get(key);↵
|
41 | return i.intValue();↵ | | 34 | return i.intValue();↵
|
42 | }↵ | | 35 | }↵
|
|
43 | /**↵ | | 36 | /**↵
|
44 | * Get the valid values.↵ | | |
|
45 | * @return the value values.↵ | | |
|
46 | */↵ | | 37 | {@inheritDoc}. */↵
|
47 | public String[] getValues() {↵ | | 38 | public String[] getValues() {↵
|
48 | return UNITS;↵ | | 39 | return UNITS;↵
|
49 | | | 40 |
|