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 DateDayOfWeekGrouper extends DateGrouper {
10:
11: public static GrouperContext CONTEXT = new GrouperContext(
12: "DateDayOfWeek");
13:
14: private static Object[] _groups = null;
15:
16: public static Object[] getAvailableGroups() {
17: if (_groups == null) {
18: Calendar cal = Calendar.getInstance();
19: cal.set(Calendar.DAY_OF_WEEK, 0);
20: _groups = new Object[cal.getMaximum(Calendar.DAY_OF_WEEK)];
21: for (int i = 0; i < _groups.length; i++) {
22: _groups[i] = i;
23: cal.roll(Calendar.DAY_OF_WEEK, 1);
24: }
25: }
26: return _groups;
27: }
28:
29: public Object getValue(Object value) {
30: Object field = getCalendarField(value, Calendar.DAY_OF_WEEK);
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.dayOfWeek");
42: }
43:
44: // public static void main(String[] args) {
45: // ObjectGrouper grouper = new DateDayOfWeekGrouper();
46: // System.out.println(grouper.getValue(Calendar.getInstance()));
47: // }
48: }
|