01: package com.jidesoft.grouper.date;
02:
03: import com.jidesoft.grouper.GroupResources;
04: import com.jidesoft.grouper.GrouperContext;
05:
06: import java.util.Calendar;
07: import java.util.Locale;
08:
09: public class DateDayOfMonthGrouper extends DateGrouper {
10: public static GrouperContext CONTEXT = new GrouperContext(
11: "DateDayOfMonth");
12:
13: private static Object[] _groups = null;
14:
15: public static Object[] getAvailableGroups() {
16: if (_groups == null) {
17: Calendar cal = Calendar.getInstance();
18: cal.set(Calendar.MONTH, 0);
19: cal.set(Calendar.DAY_OF_MONTH, 1);
20: _groups = new Object[cal.getMaximum(Calendar.DAY_OF_MONTH)];
21: for (int i = 0; i < _groups.length; i++) {
22: _groups[i] = getCalendarField(cal,
23: Calendar.DAY_OF_MONTH);
24: cal.roll(Calendar.DAY_OF_MONTH, 1);
25: }
26: }
27: return _groups;
28: }
29:
30: public Object getValue(Object value) {
31: Object field = getCalendarField(value, Calendar.DAY_OF_MONTH);
32: if (field instanceof Integer && (Integer) field >= 1
33: && (Integer) field <= getAvailableGroups().length) {
34: return getAvailableGroups()[(Integer) field - 1];
35: } else {
36: return null;
37: }
38: }
39:
40: public String getName() {
41: return GroupResources.getResourceBundle(Locale.getDefault())
42: .getString("Date.dayOfMonth");
43: }
44:
45: // public static void main(String[] args) {
46: // ObjectGrouper grouper = new DateDayOfMonthGrouper();
47: // Calendar calendar = Calendar.getInstance();
48: // for (int i = 0; i < 40; i++) {
49: // System.out.println(grouper.getValue(calendar));
50: // calendar.roll(Calendar.DATE, 1);
51: // }
52: // }
53: }
|