2 *******************************************************************************
\r
3 * Copyright (C) 1996-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.util;
\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
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
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
23 public abstract class Holiday implements DateRule
\r
27 * @provisional This API might change or be removed in a future release.
\r
29 public static Holiday[] getHolidays()
\r
31 return getHolidays(ULocale.getDefault());
\r
36 * @provisional This API might change or be removed in a future release.
\r
38 public static Holiday[] getHolidays(Locale locale)
\r
40 return getHolidays(ULocale.forLocale(locale));
\r
45 * @provisional This API might change or be removed in a future release.
\r
47 public static Holiday[] getHolidays(ULocale locale)
\r
49 Holiday[] result = noHolidays;
\r
52 ResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.HolidayBundle", locale);
\r
54 result = (Holiday[]) bundle.getObject("holidays");
\r
56 catch (MissingResourceException e) {
\r
62 * Return the first occurrence of this holiday on or after the given date
\r
64 * @param start Only holidays on or after this date are returned.
\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
69 * @see #firstBetween
\r
71 * @provisional This API might change or be removed in a future release.
\r
73 public Date firstAfter(Date start) {
\r
74 return rule.firstAfter(start);
\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
81 * @param start Only occurrences on or after this date are returned.
\r
82 * @param end Only occurrences before this date are returned.
\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
89 * @provisional This API might change or be removed in a future release.
\r
91 public Date firstBetween(Date start, Date end) {
\r
92 return rule.firstBetween(start, end);
\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
100 * @param date The date to check.
\r
101 * @return true if this holiday occurs on the given date.
\r
103 * @provisional This API might change or be removed in a future release.
\r
105 public boolean isOn(Date date) {
\r
106 //System.out.println(name + ".isOn(" + date.toString() + "):");
\r
107 return rule.isOn(date);
\r
111 * Check whether this holiday occurs at least once between the two
\r
114 * @provisional This API might change or be removed in a future release.
\r
116 public boolean isBetween(Date start, Date end) {
\r
117 return rule.isBetween(start, end);
\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
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
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
132 * @provisional This API might change or be removed in a future release.
\r
134 protected Holiday(String name, DateRule rule)
\r
141 * Return the name of this holiday in the language of the default locale.
\r
143 * @provisional This API might change or be removed in a future release.
\r
145 public String getDisplayName() {
\r
146 return getDisplayName(ULocale.getDefault());
\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
155 * @param locale A locale specifying the language in which the name is desired.
\r
157 * @see ResourceBundle
\r
159 * @provisional This API might change or be removed in a future release.
\r
161 public String getDisplayName(Locale locale)
\r
163 return getDisplayName(ULocale.forLocale(locale));
\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
172 * @param locale A locale specifying the language in which the name is desired.
\r
174 * @see ResourceBundle
\r
176 * @provisional This API might change or be removed in a future release.
\r
178 public String getDisplayName(ULocale locale)
\r
180 String dispName = name;
\r
183 ResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.HolidayBundle", locale);
\r
184 dispName = bundle.getString(name);
\r
186 catch (MissingResourceException e) {
\r
193 * @provisional This API might change or be removed in a future release.
\r
195 public DateRule getRule() {
\r
201 * @provisional This API might change or be removed in a future release.
\r
203 public void setRule(DateRule rule) {
\r
207 private String name;
\r
208 private DateRule rule;
\r
210 private static Holiday[] noHolidays = {};
\r