2 *******************************************************************************
\r
3 * Copyright (C) 1996-2008, 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 * 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
20 public abstract class Holiday implements DateRule
\r
24 * @provisional This API might change or be removed in a future release.
\r
26 public static Holiday[] getHolidays()
\r
28 return getHolidays(ULocale.getDefault());
\r
33 * @provisional This API might change or be removed in a future release.
\r
35 public static Holiday[] getHolidays(Locale locale)
\r
37 return getHolidays(ULocale.forLocale(locale));
\r
42 * @provisional This API might change or be removed in a future release.
\r
44 public static Holiday[] getHolidays(ULocale locale)
\r
46 Holiday[] result = noHolidays;
\r
49 ResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.HolidayBundle", locale);
\r
51 result = (Holiday[]) bundle.getObject("holidays");
\r
53 catch (MissingResourceException e) {
\r
59 * Return the first occurrence of this holiday on or after the given date
\r
61 * @param start Only holidays on or after this date are returned.
\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
66 * @see #firstBetween
\r
68 * @provisional This API might change or be removed in a future release.
\r
70 public Date firstAfter(Date start) {
\r
71 return rule.firstAfter(start);
\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
78 * @param start Only occurrences on or after this date are returned.
\r
79 * @param end Only occurrences before this date are returned.
\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
86 * @provisional This API might change or be removed in a future release.
\r
88 public Date firstBetween(Date start, Date end) {
\r
89 return rule.firstBetween(start, end);
\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
97 * @param date The date to check.
\r
98 * @return true if this holiday occurs on the given date.
\r
100 * @provisional This API might change or be removed in a future release.
\r
102 public boolean isOn(Date date) {
\r
103 //System.out.println(name + ".isOn(" + date.toString() + "):");
\r
104 return rule.isOn(date);
\r
108 * Check whether this holiday occurs at least once between the two
\r
111 * @provisional This API might change or be removed in a future release.
\r
113 public boolean isBetween(Date start, Date end) {
\r
114 return rule.isBetween(start, end);
\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
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
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
129 * @provisional This API might change or be removed in a future release.
\r
131 protected Holiday(String name, DateRule rule)
\r
138 * Return the name of this holiday in the language of the default locale.
\r
140 * @provisional This API might change or be removed in a future release.
\r
142 public String getDisplayName() {
\r
143 return getDisplayName(ULocale.getDefault());
\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
152 * @param locale A locale specifying the language in which the name is desired.
\r
154 * @see ResourceBundle
\r
156 * @provisional This API might change or be removed in a future release.
\r
158 public String getDisplayName(Locale locale)
\r
160 return getDisplayName(ULocale.forLocale(locale));
\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
169 * @param locale A locale specifying the language in which the name is desired.
\r
171 * @see ResourceBundle
\r
173 * @provisional This API might change or be removed in a future release.
\r
175 public String getDisplayName(ULocale locale)
\r
177 String dispName = name;
\r
180 ResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.HolidayBundle", locale);
\r
181 dispName = bundle.getString(name);
\r
183 catch (MissingResourceException e) {
\r
190 * @provisional This API might change or be removed in a future release.
\r
192 public DateRule getRule() {
\r
198 * @provisional This API might change or be removed in a future release.
\r
200 public void setRule(DateRule rule) {
\r
204 private String name;
\r
205 private DateRule rule;
\r
207 private static Holiday[] noHolidays = {};
\r