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