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