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