KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Locale JavaDoc;
12 import java.util.MissingResourceException JavaDoc;
13 import java.util.ResourceBundle JavaDoc;
14
15 /**
16  * An abstract class representing a holiday.
17  * @draft ICU 2.8 (retainAll)
18  * @provisional This API might change or be removed in a future release.
19  */

20 public abstract class Holiday implements DateRule
21 {
22     /**
23      * @draft ICU 2.8
24      * @provisional This API might change or be removed in a future release.
25      */

26     public static Holiday[] getHolidays()
27     {
28         return getHolidays(ULocale.getDefault());
29     }
30
31     /**
32      * @draft ICU 2.8
33      * @provisional This API might change or be removed in a future release.
34      */

35     public static Holiday[] getHolidays(Locale JavaDoc locale)
36     {
37         return getHolidays(ULocale.forLocale(locale));
38     }
39
40     /**
41      * @draft ICU 3.2
42      * @provisional This API might change or be removed in a future release.
43      */

44     public static Holiday[] getHolidays(ULocale locale)
45     {
46         Holiday[] result = noHolidays;
47
48         try {
49             ResourceBundle JavaDoc bundle = UResourceBundle.getBundleInstance("HolidayBundle", locale);
50
51             result = (Holiday[]) bundle.getObject("holidays");
52         }
53         catch (MissingResourceException JavaDoc e) {
54         }
55         return result;
56     }
57
58     /**
59      * Return the first occurrance of this holiday on or after the given date
60      *
61      * @param start Only holidays on or after this date are returned.
62      *
63      * @return The date on which this holiday occurs, or null if it
64      * does not occur on or after the start date.
65      *
66      * @see #firstBetween
67      * @draft ICU 2.8
68      * @provisional This API might change or be removed in a future release.
69      */

70     public Date JavaDoc firstAfter(Date JavaDoc start) {
71         return rule.firstAfter(start);
72     }
73
74     /**
75      * Return the first occurrance of this holiday that is on or after
76      * the given start date and before the given end date.
77      *
78      * @param start Only occurrances on or after this date are returned.
79      * @param end Only occurrances before this date are returned.
80      *
81      * @return The date on which this event occurs, or null if it
82      * does not occur between the start and end dates.
83      *
84      * @see #firstAfter
85      * @draft ICU 2.8
86      * @provisional This API might change or be removed in a future release.
87      */

88     public Date JavaDoc firstBetween(Date JavaDoc start, Date JavaDoc end) {
89         return rule.firstBetween(start, end);
90     }
91
92     /**
93      * Checks whether this holiday falls on the given date. This does
94      * <em>not</em> take time of day into account; instead it checks
95      * whether the holiday and the given date are on the same day.
96      *
97      * @param date The date to check.
98      * @return true if this holiday occurs on the given date.
99      * @draft ICU 2.8
100      * @provisional This API might change or be removed in a future release.
101      */

102     public boolean isOn(Date JavaDoc date) {
103         //System.out.println(name + ".isOn(" + date.toString() + "):");
104
return rule.isOn(date);
105     }
106
107     /**
108      * Check whether this holiday occurs at least once between the two
109      * dates given.
110      * @draft ICU 2.8
111      * @provisional This API might change or be removed in a future release.
112      */

113     public boolean isBetween(Date JavaDoc start, Date JavaDoc end) {
114         return rule.isBetween(start, end);
115     }
116
117     /**
118      * Construct a new Holiday object. This is for use by subclasses only.
119      * This constructs a new holiday with the given name and date rules.
120      *
121      * @param name The name of this holiday. The getDisplayName method
122      * uses this string as a key to look up the holiday's name a
123      * resource bundle object named HolidayBundle.
124      *
125      * @param rule The date rules used for determining when this holiday
126      * falls. Holiday's implementation of the DateRule inteface
127      * simply delegates to this DateRule object.
128      * @draft ICU 2.8
129      * @provisional This API might change or be removed in a future release.
130      */

131     protected Holiday(String JavaDoc name, DateRule rule)
132     {
133         this.name = name;
134         this.rule = rule;
135     }
136
137     /**
138      * Return the name of this holiday in the language of the default locale
139      * @draft ICU 2.8
140      * @provisional This API might change or be removed in a future release.
141      */

142     public String JavaDoc getDisplayName() {
143         return getDisplayName(ULocale.getDefault());
144     }
145
146     /**
147      * Return the name of this holiday in the language of the specified locale
148      * The <code>name</code> parameter passed to this object's constructor is used
149      * as a key to look up the holiday's localized name in a ResourceBundle object
150      * named HolidayBundle.
151      *
152      * @param locale A locale specifying the language in which the name is desired.
153      *
154      * @see ResourceBundle
155      * @draft ICU 2.8
156      * @provisional This API might change or be removed in a future release.
157      */

158     public String JavaDoc getDisplayName(Locale JavaDoc locale)
159     {
160         return getDisplayName(ULocale.forLocale(locale));
161     }
162
163     /**
164      * Return the name of this holiday in the language of the specified locale
165      * The <code>name</code> parameter passed to this object's constructor is used
166      * as a key to look up the holiday's localized name in a ResourceBundle object
167      * named HolidayBundle.
168      *
169      * @param locale A locale specifying the language in which the name is desired.
170      *
171      * @see ResourceBundle
172      * @draft ICU 3.2
173      * @provisional This API might change or be removed in a future release.
174      */

175     public String JavaDoc getDisplayName(ULocale locale)
176     {
177         String JavaDoc name = this.name;
178
179         try {
180             ResourceBundle JavaDoc bundle = UResourceBundle.getBundleInstance("HolidayBundle", locale);
181             name = bundle.getString(name);
182         }
183         catch (MissingResourceException JavaDoc e) {
184             //System.out.println("Using default display name for " + name);
185
}
186         return name;
187     }
188
189     /**
190      * @draft ICU 2.8
191      * @provisional This API might change or be removed in a future release.
192      */

193     public DateRule getRule() {
194         return rule;
195     }
196
197     /**
198      * @draft ICU 2.8
199      * @provisional This API might change or be removed in a future release.
200      */

201     public void setRule(DateRule rule) {
202         this.rule = rule;
203     }
204
205     private String JavaDoc name;
206     private DateRule rule;
207
208     private static Holiday[] noHolidays = {};
209 }
210
Popular Tags