KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > util > SimpleHoliday


1 /*
2  *******************************************************************************
3  * Copyright (C) 1996-2006, International Business Machines Corporation and *
4  * others. All Rights Reserved. *
5  *******************************************************************************
6  */

7
8 package com.ibm.icu.util;
9
10 import java.util.Date JavaDoc;
11 import com.ibm.icu.util.Calendar;
12 import com.ibm.icu.util.GregorianCalendar;
13
14 /**
15  * A holiday whose date can be represented by a month, day, and optionally day of week
16  * in the Gregorian calendar.
17  *
18  * @draft ICU 2.8 (retainAll)
19  * @provisional This API might change or be removed in a future release.
20  */

21 public class SimpleHoliday extends Holiday {
22     /**
23      * Construct an object representing a holiday
24      *
25      * @param month The month in which this holiday occurs (0-based)
26      * @param dayOfMonth The date within the month (1-based).
27      *
28      * @param name The name of this holiday. This string is used as a key
29      * to look up the holiday's name a resource bundle.
30      * If the name is not found in the resource bundle,
31      * getDisplayName will return this string instead.
32      *
33      * @see Holiday#getDisplayName(java.util.Locale)
34      * @draft ICU 2.8
35      * @provisional This API might change or be removed in a future release.
36      */

37     public SimpleHoliday(int month, int dayOfMonth, String JavaDoc name)
38     {
39         super(name, new SimpleDateRule(month, dayOfMonth));
40     }
41
42     /**
43      * Construct an object representing a holiday
44      *
45      * @param month The month in which this holiday occurs (0-based)
46      * @param dayOfMonth The date within the month (1-based).
47      *
48      * @param name The name of this holiday. This string is used as a key
49      * to look up the holiday's name a resource bundle.
50      * If the name is not found in the resource bundle,
51      * getDisplayName will return this string instead.
52      *
53      * @see Holiday#getDisplayName(java.util.Locale)
54      * @draft ICU 2.8
55      * @provisional This API might change or be removed in a future release.
56      */

57     public SimpleHoliday(int month, int dayOfMonth, String JavaDoc name,
58                             int startYear)
59     {
60         super(name, rangeRule(startYear, 0, new SimpleDateRule(month, dayOfMonth)));
61     }
62
63     /**
64      * Construct an object representing a holiday
65      *
66      * @param month The month in which this holiday occurs (0-based)
67      * @param dayOfMonth The date within the month (1-based).
68      *
69      * @param name The name of this holiday. This string is used as a key
70      * to look up the holiday's name a resource bundle.
71      * If the name is not found in the resource bundle,
72      * getDisplayName will return this string instead.
73      *
74      * @see Holiday#getDisplayName(java.util.Locale)
75      * @draft ICU 2.8
76      * @provisional This API might change or be removed in a future release.
77      */

78     public SimpleHoliday(int month, int dayOfMonth, String JavaDoc name,
79                             int startYear, int endYear)
80     {
81         super(name, rangeRule(startYear, endYear, new SimpleDateRule(month, dayOfMonth)));
82     }
83
84     /** // TODO: remove
85      * Construct an object representing a holiday
86      *
87      * @param month The month in which this holiday occurs (0-based)
88      *
89      * @param dayOfMonth A date within the month (1-based). The
90      * interpretation of this parameter depends on the value of
91      * <code>dayOfWeek</code>.
92      *
93      * @param dayOfWeek The day of the week on which this holiday occurs.
94      * The following values are legal: <ul>
95      * <li>dayOfWeek == 0 - use dayOfMonth only
96      * <li>dayOfWeek < 0 - use last -dayOfWeek before or on dayOfMonth
97      * <li>dayOfWeek > 0 - use first dayOfWeek after or on dayOfMonth
98      * </ul>
99      *
100      * @param name The name of this holiday. This string is used as a key
101      * to look up the holiday's name a resource bundle.
102      * If the name is not found in the resource bundle,
103      * getDisplayName will return this string instead.
104      *
105      * @see Holiday#getDisplayName(java.util.Locale)
106      * @draft ICU 2.8
107      * @provisional This API might change or be removed in a future release.
108      */

109     public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String JavaDoc name)
110     {
111         super(name, new SimpleDateRule(month, dayOfMonth,
112                                         dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
113                                         dayOfWeek > 0));
114     }
115
116     /**
117      * @draft ICU 2.8
118      * @provisional This API might change or be removed in a future release.
119      */

120     public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String JavaDoc name,
121                         int startYear)
122     {
123         super(name, rangeRule(startYear, 0,
124                               new SimpleDateRule(month, dayOfMonth,
125                                                  dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
126                                                  dayOfWeek > 0)));
127     }
128
129
130     /**
131      * @draft ICU 2.8
132      * @provisional This API might change or be removed in a future release.
133      */

134     public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String JavaDoc name,
135                         int startYear, int endYear)
136     {
137         super(name, rangeRule(startYear, endYear,
138                               new SimpleDateRule(month, dayOfMonth,
139                                                  dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
140                                                  dayOfWeek > 0)));
141     }
142
143     private static DateRule rangeRule(int startYear, int endYear, DateRule rule)
144     {
145         if (startYear == 0 && endYear == 0) {
146             return rule;
147         }
148
149         RangeDateRule rangeRule = new RangeDateRule();
150
151         if (startYear != 0) {
152             Calendar start = new GregorianCalendar(startYear, Calendar.JANUARY, 1);
153             rangeRule.add(start.getTime(), rule);
154         } else {
155             rangeRule.add(rule);
156         }
157         if (endYear != 0) {
158             Date JavaDoc end = new GregorianCalendar(endYear, Calendar.DECEMBER, 31).getTime();
159             rangeRule.add(end, null);
160         }
161
162         return rangeRule;
163     }
164
165     /* Constants for holidays that are common throughout the Western
166      * and Christian worlds.... */

167
168     /**
169      * New Year's Day - January 1st
170      * @draft ICU 2.8
171      * @provisional This API might change or be removed in a future release.
172      */

173     public static final SimpleHoliday NEW_YEARS_DAY =
174         new SimpleHoliday(Calendar.JANUARY, 1, "New Year's Day");
175
176     /**
177      * Epiphany, January 6th
178      * @draft ICU 2.8
179      * @provisional This API might change or be removed in a future release.
180      */

181     public static final SimpleHoliday EPIPHANY =
182         new SimpleHoliday(Calendar.JANUARY, 6, "Epiphany");
183
184     /**
185      * May Day, May 1st
186      * @draft ICU 2.8
187      * @provisional This API might change or be removed in a future release.
188      */

189     public static final SimpleHoliday MAY_DAY =
190         new SimpleHoliday(Calendar.MAY, 1, "May Day");
191
192     /**
193      * Assumption, August 15th
194      * @draft ICU 2.8
195      * @provisional This API might change or be removed in a future release.
196      */

197     public static final SimpleHoliday ASSUMPTION =
198         new SimpleHoliday(Calendar.AUGUST, 15, "Assumption");
199
200     /**
201      * All Saints' Day, November 1st
202      * @draft ICU 2.8
203      * @provisional This API might change or be removed in a future release.
204      */

205     public static final SimpleHoliday ALL_SAINTS_DAY =
206         new SimpleHoliday(Calendar.NOVEMBER, 1, "All Saints' Day");
207
208     /**
209      * All Souls' Day, November 1st
210      * @draft ICU 2.8
211      * @provisional This API might change or be removed in a future release.
212      */

213     public static final SimpleHoliday ALL_SOULS_DAY =
214         new SimpleHoliday(Calendar.NOVEMBER, 2, "All Souls' Day");
215
216     /**
217      * Immaculate Conception, December 8th
218      * @draft ICU 2.8
219      * @provisional This API might change or be removed in a future release.
220      */

221     public static final SimpleHoliday IMMACULATE_CONCEPTION =
222         new SimpleHoliday(Calendar.DECEMBER, 8, "Immaculate Conception");
223
224     /**
225      * Christmas Eve, December 24th
226      * @draft ICU 2.8
227      * @provisional This API might change or be removed in a future release.
228      */

229     public static final SimpleHoliday CHRISTMAS_EVE =
230         new SimpleHoliday(Calendar.DECEMBER, 24, "Christmas Eve");
231
232     /**
233      * Christmas, December 25th
234      * @draft ICU 2.8
235      * @provisional This API might change or be removed in a future release.
236      */

237     public static final SimpleHoliday CHRISTMAS =
238         new SimpleHoliday(Calendar.DECEMBER, 25, "Christmas");
239
240     /**
241      * Boxing Day, December 26th
242      * @draft ICU 2.8
243      * @provisional This API might change or be removed in a future release.
244      */

245     public static final SimpleHoliday BOXING_DAY =
246         new SimpleHoliday(Calendar.DECEMBER, 26, "Boxing Day");
247
248     /**
249      * Saint Stephen's Day, December 26th
250      * @draft ICU 2.8
251      * @provisional This API might change or be removed in a future release.
252      */

253     public static final SimpleHoliday ST_STEPHENS_DAY =
254         new SimpleHoliday(Calendar.DECEMBER, 26, "St. Stephen's Day");
255
256     /**
257      * New Year's Eve, December 31st
258      * @draft ICU 2.8
259      * @provisional This API might change or be removed in a future release.
260      */

261     public static final SimpleHoliday NEW_YEARS_EVE =
262         new SimpleHoliday(Calendar.DECEMBER, 31, "New Year's Eve");
263
264 }
265
Popular Tags