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 DateWeekOfMonthGrouper extends DateGrouper {
10: public static GrouperContext CONTEXT = new GrouperContext(
11: "DateWeekOfMonth");
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.DATE, 0);
19: _groups = new Object[cal.getMaximum(Calendar.WEEK_OF_MONTH)];
20: for (int i = 0; i < _groups.length; i++) {
21: _groups[i] = getCalendarField(cal,
22: Calendar.WEEK_OF_MONTH);
23: cal.roll(Calendar.WEEK_OF_MONTH, 1);
24: }
25: }
26: return _groups;
27: }
28:
29: public Object getValue(Object value) {
30: Object field = getCalendarField(value, Calendar.WEEK_OF_MONTH);
31: if (field instanceof Integer && (Integer) field >= 0
32: && (Integer) field < getAvailableGroups().length) {
33: return getAvailableGroups()[((Integer) field)];
34: } else {
35: return null;
36: }
37: }
38:
39: public String getName() {
40: return GroupResources.getResourceBundle(Locale.getDefault())
41: .getString("Date.weekOfMonth");
42: }
43:
44: // public static void main(String[] args) {
45: // ObjectGrouper grouper = new DateWeekOfMonthGrouper();
46: // Calendar calendar = Calendar.getInstance();
47: // for (int i = 0; i < 40; i++) {
48: // System.out.println(grouper.getValue(calendar));
49: // calendar.roll(Calendar.DAY_OF_YEAR, 7);
50: // }
51: // }
52: }
|