]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/util/Holiday.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / util / Holiday.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 1996-2008, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\r
7 \r
8 package com.ibm.icu.util;\r
9 \r
10 import java.util.Date;\r
11 import java.util.Locale;\r
12 import java.util.MissingResourceException;\r
13 import java.util.ResourceBundle;\r
14 \r
15 /**\r
16  * An abstract class representing a holiday.\r
17  * @draft ICU 2.8 (retainAll)\r
18  * @provisional This API might change or be removed in a future release.\r
19  */\r
20 public abstract class Holiday implements DateRule\r
21 {\r
22     /**\r
23      * @draft ICU 2.8\r
24      * @provisional This API might change or be removed in a future release.\r
25      */\r
26     public static Holiday[] getHolidays()\r
27     {\r
28         return getHolidays(ULocale.getDefault());\r
29     }\r
30 \r
31     /**\r
32      * @draft ICU 2.8\r
33      * @provisional This API might change or be removed in a future release.\r
34      */\r
35     public static Holiday[] getHolidays(Locale locale)\r
36     {\r
37         return getHolidays(ULocale.forLocale(locale));\r
38     }\r
39 \r
40     /**\r
41      * @draft ICU 3.2\r
42      * @provisional This API might change or be removed in a future release.\r
43      */\r
44     public static Holiday[] getHolidays(ULocale locale)\r
45     {\r
46         Holiday[] result = noHolidays;\r
47 \r
48         try {\r
49             ResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.HolidayBundle", locale);\r
50 \r
51             result = (Holiday[]) bundle.getObject("holidays");\r
52         }\r
53         catch (MissingResourceException e) {\r
54         }\r
55         return result;\r
56     }\r
57 \r
58     /**\r
59      * Return the first occurrence of this holiday on or after the given date\r
60      *\r
61      * @param start Only holidays on or after this date are returned.\r
62      *\r
63      * @return      The date on which this holiday occurs, or null if it\r
64      *              does not occur on or after the start date.\r
65      *\r
66      * @see #firstBetween\r
67      * @draft ICU 2.8\r
68      * @provisional This API might change or be removed in a future release.\r
69      */\r
70     public Date firstAfter(Date start) {\r
71         return rule.firstAfter(start);\r
72     }\r
73 \r
74     /**\r
75      * Return the first occurrence of this holiday that is on or after\r
76      * the given start date and before the given end date.\r
77      *\r
78      * @param start Only occurrences on or after this date are returned.\r
79      * @param end   Only occurrences before this date are returned.\r
80      *\r
81      * @return      The date on which this event occurs, or null if it\r
82      *              does not occur between the start and end dates.\r
83      *\r
84      * @see #firstAfter\r
85      * @draft ICU 2.8\r
86      * @provisional This API might change or be removed in a future release.\r
87      */\r
88     public Date firstBetween(Date start, Date end) {\r
89         return rule.firstBetween(start, end);\r
90     }\r
91 \r
92     /**\r
93      * Checks whether this holiday falls on the given date.  This does\r
94      * <em>not</em> take time of day into account; instead it checks\r
95      * whether the holiday and the given date are on the same day.\r
96      *\r
97      * @param date  The date to check.\r
98      * @return      true if this holiday occurs on the given date.\r
99      * @draft ICU 2.8\r
100      * @provisional This API might change or be removed in a future release.\r
101      */\r
102     public boolean isOn(Date date) {\r
103         //System.out.println(name + ".isOn(" + date.toString() + "):");\r
104         return rule.isOn(date);\r
105     }\r
106 \r
107     /**\r
108      * Check whether this holiday occurs at least once between the two\r
109      * dates given.\r
110      * @draft ICU 2.8\r
111      * @provisional This API might change or be removed in a future release.\r
112      */\r
113     public boolean isBetween(Date start, Date end) {\r
114         return rule.isBetween(start, end);\r
115     }\r
116 \r
117     /**\r
118      * Construct a new Holiday object.  This is for use by subclasses only.\r
119      * This constructs a new holiday with the given name and date rules.\r
120      *\r
121      * @param name  The name of this holiday.  The getDisplayName method\r
122      *              uses this string as a key to look up the holiday's name a\r
123      *              resource bundle object named HolidayBundle.\r
124      *\r
125      * @param rule  The date rules used for determining when this holiday\r
126      *              falls.  Holiday's implementation of the DateRule interface\r
127      *              simply delegates to this DateRule object.\r
128      * @draft ICU 2.8\r
129      * @provisional This API might change or be removed in a future release.\r
130      */\r
131     protected Holiday(String name, DateRule rule)\r
132     {\r
133         this.name = name;\r
134         this.rule = rule;\r
135     }\r
136 \r
137     /**\r
138      * Return the name of this holiday in the language of the default locale.\r
139      * @draft ICU 2.8\r
140      * @provisional This API might change or be removed in a future release.\r
141      */\r
142     public String getDisplayName() {\r
143         return getDisplayName(ULocale.getDefault());\r
144     }\r
145 \r
146     /**\r
147      * Return the name of this holiday in the language of the specified locale.\r
148      * The <code>name</code> parameter passed to this object's constructor is used\r
149      * as a key to look up the holiday's localized name in a ResourceBundle object\r
150      * named HolidayBundle.\r
151      *\r
152      * @param locale   A locale specifying the language in which the name is desired.\r
153      *\r
154      * @see ResourceBundle\r
155      * @draft ICU 2.8\r
156      * @provisional This API might change or be removed in a future release.\r
157      */\r
158     public String getDisplayName(Locale locale)\r
159     {\r
160         return getDisplayName(ULocale.forLocale(locale));\r
161     }\r
162 \r
163     /**\r
164      * Return the name of this holiday in the language of the specified locale\r
165      * The <code>name</code> parameter passed to this object's constructor is used\r
166      * as a key to look up the holiday's localized name in a ResourceBundle object\r
167      * named HolidayBundle.\r
168      *\r
169      * @param locale   A locale specifying the language in which the name is desired.\r
170      *\r
171      * @see ResourceBundle\r
172      * @draft ICU 3.2\r
173      * @provisional This API might change or be removed in a future release.\r
174      */\r
175     public String getDisplayName(ULocale locale)\r
176     {\r
177         String dispName = name;\r
178 \r
179         try {\r
180             ResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.HolidayBundle", locale);\r
181             dispName = bundle.getString(name);\r
182         }\r
183         catch (MissingResourceException e) {\r
184         }\r
185         return dispName;\r
186     }\r
187 \r
188     /**\r
189      * @draft ICU 2.8\r
190      * @provisional This API might change or be removed in a future release.\r
191      */\r
192     public DateRule getRule() {\r
193         return rule;\r
194     }\r
195 \r
196     /**\r
197      * @draft ICU 2.8\r
198      * @provisional This API might change or be removed in a future release.\r
199      */\r
200     public void setRule(DateRule rule) {\r
201         this.rule = rule;\r
202     }\r
203 \r
204     private String      name;\r
205     private DateRule    rule;\r
206 \r
207     private static Holiday[] noHolidays = {};\r
208 }\r