author | mchung |
Fri, 22 May 2015 16:43:39 -0700 | |
changeset 30789 | 9eca83469588 |
parent 25859 | 3317bb8137f4 |
child 34774 | 03b4e6dc367b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
17708
diff
changeset
|
2 |
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
/* |
|
27 |
* (C) Copyright Taligent, Inc. 1996 - All Rights Reserved |
|
28 |
* (C) Copyright IBM Corp. 1996 - All Rights Reserved |
|
29 |
* |
|
30 |
* The original version of this source code and documentation is copyrighted |
|
31 |
* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These |
|
32 |
* materials are provided under terms of a License Agreement between Taligent |
|
33 |
* and Sun. This technology is protected by multiple US and International |
|
34 |
* patents. This notice and attribution to Taligent may not be removed. |
|
35 |
* Taligent is a registered trademark of Taligent, Inc. |
|
36 |
* |
|
37 |
*/ |
|
38 |
||
39 |
package java.text; |
|
40 |
||
41 |
import java.io.IOException; |
|
42 |
import java.io.ObjectOutputStream; |
|
43 |
import java.io.Serializable; |
|
44 |
import java.lang.ref.SoftReference; |
|
45 |
import java.text.spi.DateFormatSymbolsProvider; |
|
46 |
import java.util.Arrays; |
|
47 |
import java.util.Locale; |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
48 |
import java.util.Objects; |
2 | 49 |
import java.util.ResourceBundle; |
50 |
import java.util.TimeZone; |
|
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
51 |
import java.util.concurrent.ConcurrentHashMap; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
52 |
import java.util.concurrent.ConcurrentMap; |
13583 | 53 |
import sun.util.locale.provider.LocaleProviderAdapter; |
54 |
import sun.util.locale.provider.LocaleServiceProviderPool; |
|
15260 | 55 |
import sun.util.locale.provider.ResourceBundleBasedAdapter; |
13583 | 56 |
import sun.util.locale.provider.TimeZoneNameUtility; |
2 | 57 |
|
58 |
/** |
|
59 |
* <code>DateFormatSymbols</code> is a public class for encapsulating |
|
60 |
* localizable date-time formatting data, such as the names of the |
|
61 |
* months, the names of the days of the week, and the time zone data. |
|
17708
eccbcb1b38be
7056126: DateFormatSymbols documentation has incorrect description about DateFormat
naoto
parents:
16010
diff
changeset
|
62 |
* <code>SimpleDateFormat</code> uses |
2 | 63 |
* <code>DateFormatSymbols</code> to encapsulate this information. |
64 |
* |
|
65 |
* <p> |
|
66 |
* Typically you shouldn't use <code>DateFormatSymbols</code> directly. |
|
67 |
* Rather, you are encouraged to create a date-time formatter with the |
|
68 |
* <code>DateFormat</code> class's factory methods: <code>getTimeInstance</code>, |
|
69 |
* <code>getDateInstance</code>, or <code>getDateTimeInstance</code>. |
|
70 |
* These methods automatically create a <code>DateFormatSymbols</code> for |
|
71 |
* the formatter so that you don't have to. After the |
|
72 |
* formatter is created, you may modify its format pattern using the |
|
73 |
* <code>setPattern</code> method. For more information about |
|
74 |
* creating formatters using <code>DateFormat</code>'s factory methods, |
|
75 |
* see {@link DateFormat}. |
|
76 |
* |
|
77 |
* <p> |
|
78 |
* If you decide to create a date-time formatter with a specific |
|
79 |
* format pattern for a specific locale, you can do so with: |
|
80 |
* <blockquote> |
|
81 |
* <pre> |
|
82 |
* new SimpleDateFormat(aPattern, DateFormatSymbols.getInstance(aLocale)). |
|
83 |
* </pre> |
|
84 |
* </blockquote> |
|
85 |
* |
|
86 |
* <p> |
|
87 |
* <code>DateFormatSymbols</code> objects are cloneable. When you obtain |
|
88 |
* a <code>DateFormatSymbols</code> object, feel free to modify the |
|
89 |
* date-time formatting data. For instance, you can replace the localized |
|
90 |
* date-time format pattern characters with the ones that you feel easy |
|
91 |
* to remember. Or you can change the representative cities |
|
92 |
* to your favorite ones. |
|
93 |
* |
|
94 |
* <p> |
|
95 |
* New <code>DateFormatSymbols</code> subclasses may be added to support |
|
96 |
* <code>SimpleDateFormat</code> for date-time formatting for additional locales. |
|
97 |
||
98 |
* @see DateFormat |
|
99 |
* @see SimpleDateFormat |
|
100 |
* @see java.util.SimpleTimeZone |
|
101 |
* @author Chen-Lieh Huang |
|
102 |
*/ |
|
103 |
public class DateFormatSymbols implements Serializable, Cloneable { |
|
104 |
||
105 |
/** |
|
106 |
* Construct a DateFormatSymbols object by loading format data from |
|
16010
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
107 |
* resources for the default {@link java.util.Locale.Category#FORMAT FORMAT} |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
108 |
* locale. This constructor can only |
2 | 109 |
* construct instances for the locales supported by the Java |
110 |
* runtime environment, not for those supported by installed |
|
111 |
* {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider} |
|
112 |
* implementations. For full locale coverage, use the |
|
113 |
* {@link #getInstance(Locale) getInstance} method. |
|
16010
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
114 |
* <p>This is equivalent to calling |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
115 |
* {@link #DateFormatSymbols(Locale) |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
116 |
* DateFormatSymbols(Locale.getDefault(Locale.Category.FORMAT))}. |
2 | 117 |
* @see #getInstance() |
16010
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
118 |
* @see java.util.Locale#getDefault(java.util.Locale.Category) |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
119 |
* @see java.util.Locale.Category#FORMAT |
2 | 120 |
* @exception java.util.MissingResourceException |
121 |
* if the resources for the default locale cannot be |
|
122 |
* found or cannot be loaded. |
|
123 |
*/ |
|
124 |
public DateFormatSymbols() |
|
125 |
{ |
|
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
126 |
initializeData(Locale.getDefault(Locale.Category.FORMAT)); |
2 | 127 |
} |
128 |
||
129 |
/** |
|
130 |
* Construct a DateFormatSymbols object by loading format data from |
|
131 |
* resources for the given locale. This constructor can only |
|
132 |
* construct instances for the locales supported by the Java |
|
133 |
* runtime environment, not for those supported by installed |
|
134 |
* {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider} |
|
135 |
* implementations. For full locale coverage, use the |
|
136 |
* {@link #getInstance(Locale) getInstance} method. |
|
137 |
* |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
17708
diff
changeset
|
138 |
* @param locale the desired locale |
2 | 139 |
* @see #getInstance(Locale) |
140 |
* @exception java.util.MissingResourceException |
|
141 |
* if the resources for the specified locale cannot be |
|
142 |
* found or cannot be loaded. |
|
143 |
*/ |
|
144 |
public DateFormatSymbols(Locale locale) |
|
145 |
{ |
|
146 |
initializeData(locale); |
|
147 |
} |
|
148 |
||
149 |
/** |
|
150 |
* Era strings. For example: "AD" and "BC". An array of 2 strings, |
|
151 |
* indexed by <code>Calendar.BC</code> and <code>Calendar.AD</code>. |
|
152 |
* @serial |
|
153 |
*/ |
|
154 |
String eras[] = null; |
|
155 |
||
156 |
/** |
|
157 |
* Month strings. For example: "January", "February", etc. An array |
|
158 |
* of 13 strings (some calendars have 13 months), indexed by |
|
159 |
* <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc. |
|
160 |
* @serial |
|
161 |
*/ |
|
162 |
String months[] = null; |
|
163 |
||
164 |
/** |
|
165 |
* Short month strings. For example: "Jan", "Feb", etc. An array of |
|
166 |
* 13 strings (some calendars have 13 months), indexed by |
|
167 |
* <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc. |
|
168 |
||
169 |
* @serial |
|
170 |
*/ |
|
171 |
String shortMonths[] = null; |
|
172 |
||
173 |
/** |
|
174 |
* Weekday strings. For example: "Sunday", "Monday", etc. An array |
|
175 |
* of 8 strings, indexed by <code>Calendar.SUNDAY</code>, |
|
176 |
* <code>Calendar.MONDAY</code>, etc. |
|
177 |
* The element <code>weekdays[0]</code> is ignored. |
|
178 |
* @serial |
|
179 |
*/ |
|
180 |
String weekdays[] = null; |
|
181 |
||
182 |
/** |
|
183 |
* Short weekday strings. For example: "Sun", "Mon", etc. An array |
|
184 |
* of 8 strings, indexed by <code>Calendar.SUNDAY</code>, |
|
185 |
* <code>Calendar.MONDAY</code>, etc. |
|
186 |
* The element <code>shortWeekdays[0]</code> is ignored. |
|
187 |
* @serial |
|
188 |
*/ |
|
189 |
String shortWeekdays[] = null; |
|
190 |
||
191 |
/** |
|
192 |
* AM and PM strings. For example: "AM" and "PM". An array of |
|
193 |
* 2 strings, indexed by <code>Calendar.AM</code> and |
|
194 |
* <code>Calendar.PM</code>. |
|
195 |
* @serial |
|
196 |
*/ |
|
197 |
String ampms[] = null; |
|
198 |
||
199 |
/** |
|
200 |
* Localized names of time zones in this locale. This is a |
|
201 |
* two-dimensional array of strings of size <em>n</em> by <em>m</em>, |
|
202 |
* where <em>m</em> is at least 5. Each of the <em>n</em> rows is an |
|
203 |
* entry containing the localized names for a single <code>TimeZone</code>. |
|
204 |
* Each such row contains (with <code>i</code> ranging from |
|
205 |
* 0..<em>n</em>-1): |
|
206 |
* <ul> |
|
207 |
* <li><code>zoneStrings[i][0]</code> - time zone ID</li> |
|
208 |
* <li><code>zoneStrings[i][1]</code> - long name of zone in standard |
|
209 |
* time</li> |
|
210 |
* <li><code>zoneStrings[i][2]</code> - short name of zone in |
|
211 |
* standard time</li> |
|
212 |
* <li><code>zoneStrings[i][3]</code> - long name of zone in daylight |
|
213 |
* saving time</li> |
|
214 |
* <li><code>zoneStrings[i][4]</code> - short name of zone in daylight |
|
215 |
* saving time</li> |
|
216 |
* </ul> |
|
217 |
* The zone ID is <em>not</em> localized; it's one of the valid IDs of |
|
218 |
* the {@link java.util.TimeZone TimeZone} class that are not |
|
219 |
* <a href="../java/util/TimeZone.html#CustomID">custom IDs</a>. |
|
220 |
* All other entries are localized names. |
|
221 |
* @see java.util.TimeZone |
|
222 |
* @serial |
|
223 |
*/ |
|
224 |
String zoneStrings[][] = null; |
|
225 |
||
226 |
/** |
|
227 |
* Indicates that zoneStrings is set externally with setZoneStrings() method. |
|
228 |
*/ |
|
229 |
transient boolean isZoneStringsSet = false; |
|
230 |
||
231 |
/** |
|
232 |
* Unlocalized date-time pattern characters. For example: 'y', 'd', etc. |
|
233 |
* All locales use the same these unlocalized pattern characters. |
|
234 |
*/ |
|
13583 | 235 |
static final String patternChars = "GyMdkHmsSEDFwWahKzZYuXL"; |
6491
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
236 |
|
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
237 |
static final int PATTERN_ERA = 0; // G |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
238 |
static final int PATTERN_YEAR = 1; // y |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
239 |
static final int PATTERN_MONTH = 2; // M |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
240 |
static final int PATTERN_DAY_OF_MONTH = 3; // d |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
241 |
static final int PATTERN_HOUR_OF_DAY1 = 4; // k |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
242 |
static final int PATTERN_HOUR_OF_DAY0 = 5; // H |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
243 |
static final int PATTERN_MINUTE = 6; // m |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
244 |
static final int PATTERN_SECOND = 7; // s |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
245 |
static final int PATTERN_MILLISECOND = 8; // S |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
246 |
static final int PATTERN_DAY_OF_WEEK = 9; // E |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
247 |
static final int PATTERN_DAY_OF_YEAR = 10; // D |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
248 |
static final int PATTERN_DAY_OF_WEEK_IN_MONTH = 11; // F |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
249 |
static final int PATTERN_WEEK_OF_YEAR = 12; // w |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
250 |
static final int PATTERN_WEEK_OF_MONTH = 13; // W |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
251 |
static final int PATTERN_AM_PM = 14; // a |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
252 |
static final int PATTERN_HOUR1 = 15; // h |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
253 |
static final int PATTERN_HOUR0 = 16; // K |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
254 |
static final int PATTERN_ZONE_NAME = 17; // z |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
255 |
static final int PATTERN_ZONE_VALUE = 18; // Z |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
256 |
static final int PATTERN_WEEK_YEAR = 19; // Y |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
257 |
static final int PATTERN_ISO_DAY_OF_WEEK = 20; // u |
6497
22752a2b3413
4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents:
6491
diff
changeset
|
258 |
static final int PATTERN_ISO_ZONE = 21; // X |
13583 | 259 |
static final int PATTERN_MONTH_STANDALONE = 22; // L |
2 | 260 |
|
261 |
/** |
|
262 |
* Localized date-time pattern characters. For example, a locale may |
|
263 |
* wish to use 'u' rather than 'y' to represent years in its date format |
|
264 |
* pattern strings. |
|
265 |
* This string must be exactly 18 characters long, with the index of |
|
266 |
* the characters described by <code>DateFormat.ERA_FIELD</code>, |
|
267 |
* <code>DateFormat.YEAR_FIELD</code>, etc. Thus, if the string were |
|
268 |
* "Xz...", then localized patterns would use 'X' for era and 'z' for year. |
|
269 |
* @serial |
|
270 |
*/ |
|
271 |
String localPatternChars = null; |
|
272 |
||
273 |
/** |
|
274 |
* The locale which is used for initializing this DateFormatSymbols object. |
|
275 |
* |
|
276 |
* @since 1.6 |
|
277 |
* @serial |
|
278 |
*/ |
|
279 |
Locale locale = null; |
|
280 |
||
281 |
/* use serialVersionUID from JDK 1.1.4 for interoperability */ |
|
282 |
static final long serialVersionUID = -5987973545549424702L; |
|
283 |
||
284 |
/** |
|
285 |
* Returns an array of all locales for which the |
|
286 |
* <code>getInstance</code> methods of this class can return |
|
287 |
* localized instances. |
|
288 |
* The returned array represents the union of locales supported by the |
|
289 |
* Java runtime and by installed |
|
290 |
* {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider} |
|
291 |
* implementations. It must contain at least a <code>Locale</code> |
|
292 |
* instance equal to {@link java.util.Locale#US Locale.US}. |
|
293 |
* |
|
294 |
* @return An array of locales for which localized |
|
295 |
* <code>DateFormatSymbols</code> instances are available. |
|
296 |
* @since 1.6 |
|
297 |
*/ |
|
298 |
public static Locale[] getAvailableLocales() { |
|
299 |
LocaleServiceProviderPool pool= |
|
300 |
LocaleServiceProviderPool.getPool(DateFormatSymbolsProvider.class); |
|
301 |
return pool.getAvailableLocales(); |
|
302 |
} |
|
303 |
||
304 |
/** |
|
305 |
* Gets the <code>DateFormatSymbols</code> instance for the default |
|
306 |
* locale. This method provides access to <code>DateFormatSymbols</code> |
|
307 |
* instances for locales supported by the Java runtime itself as well |
|
308 |
* as for those supported by installed |
|
309 |
* {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider} |
|
310 |
* implementations. |
|
16010
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
311 |
* <p>This is equivalent to calling {@link #getInstance(Locale) |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
312 |
* getInstance(Locale.getDefault(Locale.Category.FORMAT))}. |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
313 |
* @see java.util.Locale#getDefault(java.util.Locale.Category) |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
314 |
* @see java.util.Locale.Category#FORMAT |
2 | 315 |
* @return a <code>DateFormatSymbols</code> instance. |
316 |
* @since 1.6 |
|
317 |
*/ |
|
318 |
public static final DateFormatSymbols getInstance() { |
|
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
319 |
return getInstance(Locale.getDefault(Locale.Category.FORMAT)); |
2 | 320 |
} |
321 |
||
322 |
/** |
|
323 |
* Gets the <code>DateFormatSymbols</code> instance for the specified |
|
324 |
* locale. This method provides access to <code>DateFormatSymbols</code> |
|
325 |
* instances for locales supported by the Java runtime itself as well |
|
326 |
* as for those supported by installed |
|
327 |
* {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider} |
|
328 |
* implementations. |
|
329 |
* @param locale the given locale. |
|
330 |
* @return a <code>DateFormatSymbols</code> instance. |
|
331 |
* @exception NullPointerException if <code>locale</code> is null |
|
332 |
* @since 1.6 |
|
333 |
*/ |
|
334 |
public static final DateFormatSymbols getInstance(Locale locale) { |
|
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
335 |
DateFormatSymbols dfs = getProviderInstance(locale); |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
336 |
if (dfs != null) { |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
337 |
return dfs; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
338 |
} |
13583 | 339 |
throw new RuntimeException("DateFormatSymbols instance creation failed."); |
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
340 |
} |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
341 |
|
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
342 |
/** |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
343 |
* Returns a DateFormatSymbols provided by a provider or found in |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
344 |
* the cache. Note that this method returns a cached instance, |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
345 |
* not its clone. Therefore, the instance should never be given to |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
346 |
* an application. |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
347 |
*/ |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
348 |
static final DateFormatSymbols getInstanceRef(Locale locale) { |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
349 |
DateFormatSymbols dfs = getProviderInstance(locale); |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
350 |
if (dfs != null) { |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
351 |
return dfs; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
352 |
} |
13583 | 353 |
throw new RuntimeException("DateFormatSymbols instance creation failed."); |
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
354 |
} |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
355 |
|
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
356 |
private static DateFormatSymbols getProviderInstance(Locale locale) { |
13583 | 357 |
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); |
358 |
DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider(); |
|
359 |
DateFormatSymbols dfsyms = provider.getInstance(locale); |
|
360 |
if (dfsyms == null) { |
|
361 |
provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider(); |
|
362 |
dfsyms = provider.getInstance(locale); |
|
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
363 |
} |
13583 | 364 |
return dfsyms; |
2 | 365 |
} |
366 |
||
367 |
/** |
|
368 |
* Gets era strings. For example: "AD" and "BC". |
|
369 |
* @return the era strings. |
|
370 |
*/ |
|
371 |
public String[] getEras() { |
|
372 |
return Arrays.copyOf(eras, eras.length); |
|
373 |
} |
|
374 |
||
375 |
/** |
|
376 |
* Sets era strings. For example: "AD" and "BC". |
|
377 |
* @param newEras the new era strings. |
|
378 |
*/ |
|
379 |
public void setEras(String[] newEras) { |
|
380 |
eras = Arrays.copyOf(newEras, newEras.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
381 |
cachedHashCode = 0; |
2 | 382 |
} |
383 |
||
384 |
/** |
|
385 |
* Gets month strings. For example: "January", "February", etc. |
|
13583 | 386 |
* |
387 |
* <p>If the language requires different forms for formatting and |
|
388 |
* stand-alone usages, this method returns month names in the |
|
389 |
* formatting form. For example, the preferred month name for |
|
390 |
* January in the Czech language is <em>ledna</em> in the |
|
391 |
* formatting form, while it is <em>leden</em> in the stand-alone |
|
392 |
* form. This method returns {@code "ledna"} in this case. Refer |
|
393 |
* to the <a href="http://unicode.org/reports/tr35/#Calendar_Elements"> |
|
394 |
* Calendar Elements in the Unicode Locale Data Markup Language |
|
395 |
* (LDML) specification</a> for more details. |
|
396 |
* |
|
2 | 397 |
* @return the month strings. |
398 |
*/ |
|
399 |
public String[] getMonths() { |
|
400 |
return Arrays.copyOf(months, months.length); |
|
401 |
} |
|
402 |
||
403 |
/** |
|
404 |
* Sets month strings. For example: "January", "February", etc. |
|
405 |
* @param newMonths the new month strings. |
|
406 |
*/ |
|
407 |
public void setMonths(String[] newMonths) { |
|
408 |
months = Arrays.copyOf(newMonths, newMonths.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
409 |
cachedHashCode = 0; |
2 | 410 |
} |
411 |
||
412 |
/** |
|
413 |
* Gets short month strings. For example: "Jan", "Feb", etc. |
|
13583 | 414 |
* |
415 |
* <p>If the language requires different forms for formatting and |
|
416 |
* stand-alone usages, This method returns short month names in |
|
417 |
* the formatting form. For example, the preferred abbreviation |
|
418 |
* for January in the Catalan language is <em>de gen.</em> in the |
|
419 |
* formatting form, while it is <em>gen.</em> in the stand-alone |
|
420 |
* form. This method returns {@code "de gen."} in this case. Refer |
|
421 |
* to the <a href="http://unicode.org/reports/tr35/#Calendar_Elements"> |
|
422 |
* Calendar Elements in the Unicode Locale Data Markup Language |
|
423 |
* (LDML) specification</a> for more details. |
|
424 |
* |
|
2 | 425 |
* @return the short month strings. |
426 |
*/ |
|
427 |
public String[] getShortMonths() { |
|
428 |
return Arrays.copyOf(shortMonths, shortMonths.length); |
|
429 |
} |
|
430 |
||
431 |
/** |
|
432 |
* Sets short month strings. For example: "Jan", "Feb", etc. |
|
433 |
* @param newShortMonths the new short month strings. |
|
434 |
*/ |
|
435 |
public void setShortMonths(String[] newShortMonths) { |
|
436 |
shortMonths = Arrays.copyOf(newShortMonths, newShortMonths.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
437 |
cachedHashCode = 0; |
2 | 438 |
} |
439 |
||
440 |
/** |
|
441 |
* Gets weekday strings. For example: "Sunday", "Monday", etc. |
|
442 |
* @return the weekday strings. Use <code>Calendar.SUNDAY</code>, |
|
443 |
* <code>Calendar.MONDAY</code>, etc. to index the result array. |
|
444 |
*/ |
|
445 |
public String[] getWeekdays() { |
|
446 |
return Arrays.copyOf(weekdays, weekdays.length); |
|
447 |
} |
|
448 |
||
449 |
/** |
|
450 |
* Sets weekday strings. For example: "Sunday", "Monday", etc. |
|
451 |
* @param newWeekdays the new weekday strings. The array should |
|
452 |
* be indexed by <code>Calendar.SUNDAY</code>, |
|
453 |
* <code>Calendar.MONDAY</code>, etc. |
|
454 |
*/ |
|
455 |
public void setWeekdays(String[] newWeekdays) { |
|
456 |
weekdays = Arrays.copyOf(newWeekdays, newWeekdays.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
457 |
cachedHashCode = 0; |
2 | 458 |
} |
459 |
||
460 |
/** |
|
461 |
* Gets short weekday strings. For example: "Sun", "Mon", etc. |
|
462 |
* @return the short weekday strings. Use <code>Calendar.SUNDAY</code>, |
|
463 |
* <code>Calendar.MONDAY</code>, etc. to index the result array. |
|
464 |
*/ |
|
465 |
public String[] getShortWeekdays() { |
|
466 |
return Arrays.copyOf(shortWeekdays, shortWeekdays.length); |
|
467 |
} |
|
468 |
||
469 |
/** |
|
470 |
* Sets short weekday strings. For example: "Sun", "Mon", etc. |
|
471 |
* @param newShortWeekdays the new short weekday strings. The array should |
|
472 |
* be indexed by <code>Calendar.SUNDAY</code>, |
|
473 |
* <code>Calendar.MONDAY</code>, etc. |
|
474 |
*/ |
|
475 |
public void setShortWeekdays(String[] newShortWeekdays) { |
|
476 |
shortWeekdays = Arrays.copyOf(newShortWeekdays, newShortWeekdays.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
477 |
cachedHashCode = 0; |
2 | 478 |
} |
479 |
||
480 |
/** |
|
481 |
* Gets ampm strings. For example: "AM" and "PM". |
|
482 |
* @return the ampm strings. |
|
483 |
*/ |
|
484 |
public String[] getAmPmStrings() { |
|
485 |
return Arrays.copyOf(ampms, ampms.length); |
|
486 |
} |
|
487 |
||
488 |
/** |
|
489 |
* Sets ampm strings. For example: "AM" and "PM". |
|
490 |
* @param newAmpms the new ampm strings. |
|
491 |
*/ |
|
492 |
public void setAmPmStrings(String[] newAmpms) { |
|
493 |
ampms = Arrays.copyOf(newAmpms, newAmpms.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
494 |
cachedHashCode = 0; |
2 | 495 |
} |
496 |
||
497 |
/** |
|
498 |
* Gets time zone strings. Use of this method is discouraged; use |
|
499 |
* {@link java.util.TimeZone#getDisplayName() TimeZone.getDisplayName()} |
|
500 |
* instead. |
|
501 |
* <p> |
|
502 |
* The value returned is a |
|
503 |
* two-dimensional array of strings of size <em>n</em> by <em>m</em>, |
|
504 |
* where <em>m</em> is at least 5. Each of the <em>n</em> rows is an |
|
505 |
* entry containing the localized names for a single <code>TimeZone</code>. |
|
506 |
* Each such row contains (with <code>i</code> ranging from |
|
507 |
* 0..<em>n</em>-1): |
|
508 |
* <ul> |
|
509 |
* <li><code>zoneStrings[i][0]</code> - time zone ID</li> |
|
510 |
* <li><code>zoneStrings[i][1]</code> - long name of zone in standard |
|
511 |
* time</li> |
|
512 |
* <li><code>zoneStrings[i][2]</code> - short name of zone in |
|
513 |
* standard time</li> |
|
514 |
* <li><code>zoneStrings[i][3]</code> - long name of zone in daylight |
|
515 |
* saving time</li> |
|
516 |
* <li><code>zoneStrings[i][4]</code> - short name of zone in daylight |
|
517 |
* saving time</li> |
|
518 |
* </ul> |
|
519 |
* The zone ID is <em>not</em> localized; it's one of the valid IDs of |
|
520 |
* the {@link java.util.TimeZone TimeZone} class that are not |
|
521 |
* <a href="../util/TimeZone.html#CustomID">custom IDs</a>. |
|
522 |
* All other entries are localized names. If a zone does not implement |
|
523 |
* daylight saving time, the daylight saving time names should not be used. |
|
524 |
* <p> |
|
525 |
* If {@link #setZoneStrings(String[][]) setZoneStrings} has been called |
|
526 |
* on this <code>DateFormatSymbols</code> instance, then the strings |
|
527 |
* provided by that call are returned. Otherwise, the returned array |
|
528 |
* contains names provided by the Java runtime and by installed |
|
529 |
* {@link java.util.spi.TimeZoneNameProvider TimeZoneNameProvider} |
|
530 |
* implementations. |
|
531 |
* |
|
532 |
* @return the time zone strings. |
|
533 |
* @see #setZoneStrings(String[][]) |
|
534 |
*/ |
|
535 |
public String[][] getZoneStrings() { |
|
536 |
return getZoneStringsImpl(true); |
|
537 |
} |
|
538 |
||
539 |
/** |
|
540 |
* Sets time zone strings. The argument must be a |
|
541 |
* two-dimensional array of strings of size <em>n</em> by <em>m</em>, |
|
542 |
* where <em>m</em> is at least 5. Each of the <em>n</em> rows is an |
|
543 |
* entry containing the localized names for a single <code>TimeZone</code>. |
|
544 |
* Each such row contains (with <code>i</code> ranging from |
|
545 |
* 0..<em>n</em>-1): |
|
546 |
* <ul> |
|
547 |
* <li><code>zoneStrings[i][0]</code> - time zone ID</li> |
|
548 |
* <li><code>zoneStrings[i][1]</code> - long name of zone in standard |
|
549 |
* time</li> |
|
550 |
* <li><code>zoneStrings[i][2]</code> - short name of zone in |
|
551 |
* standard time</li> |
|
552 |
* <li><code>zoneStrings[i][3]</code> - long name of zone in daylight |
|
553 |
* saving time</li> |
|
554 |
* <li><code>zoneStrings[i][4]</code> - short name of zone in daylight |
|
555 |
* saving time</li> |
|
556 |
* </ul> |
|
557 |
* The zone ID is <em>not</em> localized; it's one of the valid IDs of |
|
558 |
* the {@link java.util.TimeZone TimeZone} class that are not |
|
559 |
* <a href="../util/TimeZone.html#CustomID">custom IDs</a>. |
|
560 |
* All other entries are localized names. |
|
561 |
* |
|
562 |
* @param newZoneStrings the new time zone strings. |
|
563 |
* @exception IllegalArgumentException if the length of any row in |
|
564 |
* <code>newZoneStrings</code> is less than 5 |
|
565 |
* @exception NullPointerException if <code>newZoneStrings</code> is null |
|
566 |
* @see #getZoneStrings() |
|
567 |
*/ |
|
568 |
public void setZoneStrings(String[][] newZoneStrings) { |
|
569 |
String[][] aCopy = new String[newZoneStrings.length][]; |
|
570 |
for (int i = 0; i < newZoneStrings.length; ++i) { |
|
571 |
int len = newZoneStrings[i].length; |
|
572 |
if (len < 5) { |
|
573 |
throw new IllegalArgumentException(); |
|
574 |
} |
|
575 |
aCopy[i] = Arrays.copyOf(newZoneStrings[i], len); |
|
576 |
} |
|
577 |
zoneStrings = aCopy; |
|
578 |
isZoneStringsSet = true; |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
579 |
cachedHashCode = 0; |
2 | 580 |
} |
581 |
||
582 |
/** |
|
583 |
* Gets localized date-time pattern characters. For example: 'u', 't', etc. |
|
584 |
* @return the localized date-time pattern characters. |
|
585 |
*/ |
|
586 |
public String getLocalPatternChars() { |
|
6491
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
587 |
return localPatternChars; |
2 | 588 |
} |
589 |
||
590 |
/** |
|
591 |
* Sets localized date-time pattern characters. For example: 'u', 't', etc. |
|
592 |
* @param newLocalPatternChars the new localized date-time |
|
593 |
* pattern characters. |
|
594 |
*/ |
|
595 |
public void setLocalPatternChars(String newLocalPatternChars) { |
|
6491
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
596 |
// Call toString() to throw an NPE in case the argument is null |
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
597 |
localPatternChars = newLocalPatternChars.toString(); |
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
598 |
cachedHashCode = 0; |
2 | 599 |
} |
600 |
||
601 |
/** |
|
602 |
* Overrides Cloneable |
|
603 |
*/ |
|
604 |
public Object clone() |
|
605 |
{ |
|
606 |
try |
|
607 |
{ |
|
608 |
DateFormatSymbols other = (DateFormatSymbols)super.clone(); |
|
609 |
copyMembers(this, other); |
|
610 |
return other; |
|
611 |
} catch (CloneNotSupportedException e) { |
|
10419
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
7003
diff
changeset
|
612 |
throw new InternalError(e); |
2 | 613 |
} |
614 |
} |
|
615 |
||
616 |
/** |
|
617 |
* Override hashCode. |
|
618 |
* Generates a hash code for the DateFormatSymbols object. |
|
619 |
*/ |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
620 |
@Override |
2 | 621 |
public int hashCode() { |
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
622 |
int hashCode = cachedHashCode; |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
623 |
if (hashCode == 0) { |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
624 |
hashCode = 5; |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
625 |
hashCode = 11 * hashCode + Arrays.hashCode(eras); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
626 |
hashCode = 11 * hashCode + Arrays.hashCode(months); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
627 |
hashCode = 11 * hashCode + Arrays.hashCode(shortMonths); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
628 |
hashCode = 11 * hashCode + Arrays.hashCode(weekdays); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
629 |
hashCode = 11 * hashCode + Arrays.hashCode(shortWeekdays); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
630 |
hashCode = 11 * hashCode + Arrays.hashCode(ampms); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
631 |
hashCode = 11 * hashCode + Arrays.deepHashCode(getZoneStringsWrapper()); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
632 |
hashCode = 11 * hashCode + Objects.hashCode(localPatternChars); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
633 |
cachedHashCode = hashCode; |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
634 |
} |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
635 |
|
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
636 |
return hashCode; |
2 | 637 |
} |
638 |
||
639 |
/** |
|
640 |
* Override equals |
|
641 |
*/ |
|
642 |
public boolean equals(Object obj) |
|
643 |
{ |
|
644 |
if (this == obj) return true; |
|
645 |
if (obj == null || getClass() != obj.getClass()) return false; |
|
646 |
DateFormatSymbols that = (DateFormatSymbols) obj; |
|
647 |
return (Arrays.equals(eras, that.eras) |
|
648 |
&& Arrays.equals(months, that.months) |
|
649 |
&& Arrays.equals(shortMonths, that.shortMonths) |
|
650 |
&& Arrays.equals(weekdays, that.weekdays) |
|
651 |
&& Arrays.equals(shortWeekdays, that.shortWeekdays) |
|
652 |
&& Arrays.equals(ampms, that.ampms) |
|
653 |
&& Arrays.deepEquals(getZoneStringsWrapper(), that.getZoneStringsWrapper()) |
|
654 |
&& ((localPatternChars != null |
|
655 |
&& localPatternChars.equals(that.localPatternChars)) |
|
656 |
|| (localPatternChars == null |
|
657 |
&& that.localPatternChars == null))); |
|
658 |
} |
|
659 |
||
660 |
// =======================privates=============================== |
|
661 |
||
662 |
/** |
|
663 |
* Useful constant for defining time zone offsets. |
|
664 |
*/ |
|
665 |
static final int millisPerHour = 60*60*1000; |
|
666 |
||
667 |
/** |
|
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
668 |
* Cache to hold DateFormatSymbols instances per Locale. |
2 | 669 |
*/ |
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
670 |
private static final ConcurrentMap<Locale, SoftReference<DateFormatSymbols>> cachedInstances |
13583 | 671 |
= new ConcurrentHashMap<>(3); |
2 | 672 |
|
12549
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
673 |
private transient int lastZoneIndex = 0; |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
674 |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
675 |
/** |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
676 |
* Cached hash code |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
677 |
*/ |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
678 |
transient volatile int cachedHashCode = 0; |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
679 |
|
2 | 680 |
private void initializeData(Locale desiredLocale) { |
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
681 |
locale = desiredLocale; |
2 | 682 |
|
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
683 |
// Copy values of a cached instance if any. |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
684 |
SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
685 |
DateFormatSymbols dfs; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
686 |
if (ref != null && (dfs = ref.get()) != null) { |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
687 |
copyMembers(dfs, this); |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
688 |
return; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
689 |
} |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
690 |
|
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
691 |
// Initialize the fields from the ResourceBundle for locale. |
13583 | 692 |
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); |
693 |
// Avoid any potential recursions |
|
15260 | 694 |
if (!(adapter instanceof ResourceBundleBasedAdapter)) { |
13583 | 695 |
adapter = LocaleProviderAdapter.getResourceBundleBased(); |
696 |
} |
|
15260 | 697 |
ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale); |
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
698 |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
14172
diff
changeset
|
699 |
// JRE and CLDR use different keys |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
14172
diff
changeset
|
700 |
// JRE: Eras, short.Eras and narrow.Eras |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
14172
diff
changeset
|
701 |
// CLDR: long.Eras, Eras and narrow.Eras |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
14172
diff
changeset
|
702 |
if (resource.containsKey("Eras")) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
14172
diff
changeset
|
703 |
eras = resource.getStringArray("Eras"); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
14172
diff
changeset
|
704 |
} else if (resource.containsKey("long.Eras")) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
14172
diff
changeset
|
705 |
eras = resource.getStringArray("long.Eras"); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
14172
diff
changeset
|
706 |
} else if (resource.containsKey("short.Eras")) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
14172
diff
changeset
|
707 |
eras = resource.getStringArray("short.Eras"); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
14172
diff
changeset
|
708 |
} |
2 | 709 |
months = resource.getStringArray("MonthNames"); |
710 |
shortMonths = resource.getStringArray("MonthAbbreviations"); |
|
711 |
ampms = resource.getStringArray("AmPmMarkers"); |
|
712 |
localPatternChars = resource.getString("DateTimePatternChars"); |
|
713 |
||
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
714 |
// Day of week names are stored in a 1-based array. |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
715 |
weekdays = toOneBasedArray(resource.getStringArray("DayNames")); |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
716 |
shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); |
13583 | 717 |
|
718 |
// Put a clone in the cache |
|
719 |
ref = new SoftReference<>((DateFormatSymbols)this.clone()); |
|
720 |
SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref); |
|
721 |
if (x != null) { |
|
722 |
DateFormatSymbols y = x.get(); |
|
723 |
if (y == null) { |
|
724 |
// Replace the empty SoftReference with ref. |
|
725 |
cachedInstances.put(locale, ref); |
|
726 |
} |
|
727 |
} |
|
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
728 |
} |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
729 |
|
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
730 |
private static String[] toOneBasedArray(String[] src) { |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
731 |
int len = src.length; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
732 |
String[] dst = new String[len + 1]; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
733 |
dst[0] = ""; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
734 |
for (int i = 0; i < len; i++) { |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
735 |
dst[i + 1] = src[i]; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
736 |
} |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
737 |
return dst; |
2 | 738 |
} |
739 |
||
740 |
/** |
|
741 |
* Package private: used by SimpleDateFormat |
|
742 |
* Gets the index for the given time zone ID to obtain the time zone |
|
743 |
* strings for formatting. The time zone ID is just for programmatic |
|
744 |
* lookup. NOT LOCALIZED!!! |
|
745 |
* @param ID the given time zone ID. |
|
746 |
* @return the index of the given time zone ID. Returns -1 if |
|
747 |
* the given time zone ID can't be located in the DateFormatSymbols object. |
|
748 |
* @see java.util.SimpleTimeZone |
|
749 |
*/ |
|
12549
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
750 |
final int getZoneIndex(String ID) { |
2 | 751 |
String[][] zoneStrings = getZoneStringsWrapper(); |
12549
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
752 |
|
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
753 |
/* |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
754 |
* getZoneIndex has been re-written for performance reasons. instead of |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
755 |
* traversing the zoneStrings array every time, we cache the last used zone |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
756 |
* index |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
757 |
*/ |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
758 |
if (lastZoneIndex < zoneStrings.length && ID.equals(zoneStrings[lastZoneIndex][0])) { |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
759 |
return lastZoneIndex; |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
760 |
} |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
761 |
|
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
762 |
/* slow path, search entire list */ |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
763 |
for (int index = 0; index < zoneStrings.length; index++) { |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
764 |
if (ID.equals(zoneStrings[index][0])) { |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
765 |
lastZoneIndex = index; |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
766 |
return index; |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
767 |
} |
2 | 768 |
} |
769 |
||
770 |
return -1; |
|
771 |
} |
|
772 |
||
773 |
/** |
|
774 |
* Wrapper method to the getZoneStrings(), which is called from inside |
|
775 |
* the java.text package and not to mutate the returned arrays, so that |
|
776 |
* it does not need to create a defensive copy. |
|
777 |
*/ |
|
778 |
final String[][] getZoneStringsWrapper() { |
|
779 |
if (isSubclassObject()) { |
|
780 |
return getZoneStrings(); |
|
781 |
} else { |
|
782 |
return getZoneStringsImpl(false); |
|
783 |
} |
|
784 |
} |
|
785 |
||
13583 | 786 |
private String[][] getZoneStringsImpl(boolean needsCopy) { |
2 | 787 |
if (zoneStrings == null) { |
788 |
zoneStrings = TimeZoneNameUtility.getZoneStrings(locale); |
|
789 |
} |
|
790 |
||
791 |
if (!needsCopy) { |
|
792 |
return zoneStrings; |
|
793 |
} |
|
794 |
||
795 |
int len = zoneStrings.length; |
|
796 |
String[][] aCopy = new String[len][]; |
|
797 |
for (int i = 0; i < len; i++) { |
|
798 |
aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length); |
|
799 |
} |
|
800 |
return aCopy; |
|
801 |
} |
|
802 |
||
13583 | 803 |
private boolean isSubclassObject() { |
2 | 804 |
return !getClass().getName().equals("java.text.DateFormatSymbols"); |
805 |
} |
|
806 |
||
807 |
/** |
|
808 |
* Clones all the data members from the source DateFormatSymbols to |
|
809 |
* the target DateFormatSymbols. This is only for subclasses. |
|
810 |
* @param src the source DateFormatSymbols. |
|
811 |
* @param dst the target DateFormatSymbols. |
|
812 |
*/ |
|
13583 | 813 |
private void copyMembers(DateFormatSymbols src, DateFormatSymbols dst) |
2 | 814 |
{ |
815 |
dst.eras = Arrays.copyOf(src.eras, src.eras.length); |
|
816 |
dst.months = Arrays.copyOf(src.months, src.months.length); |
|
817 |
dst.shortMonths = Arrays.copyOf(src.shortMonths, src.shortMonths.length); |
|
818 |
dst.weekdays = Arrays.copyOf(src.weekdays, src.weekdays.length); |
|
819 |
dst.shortWeekdays = Arrays.copyOf(src.shortWeekdays, src.shortWeekdays.length); |
|
820 |
dst.ampms = Arrays.copyOf(src.ampms, src.ampms.length); |
|
821 |
if (src.zoneStrings != null) { |
|
822 |
dst.zoneStrings = src.getZoneStringsImpl(true); |
|
823 |
} else { |
|
824 |
dst.zoneStrings = null; |
|
825 |
} |
|
6491
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
826 |
dst.localPatternChars = src.localPatternChars; |
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
827 |
dst.cachedHashCode = 0; |
2 | 828 |
} |
829 |
||
830 |
/** |
|
831 |
* Write out the default serializable data, after ensuring the |
|
832 |
* <code>zoneStrings</code> field is initialized in order to make |
|
833 |
* sure the backward compatibility. |
|
834 |
* |
|
835 |
* @since 1.6 |
|
836 |
*/ |
|
837 |
private void writeObject(ObjectOutputStream stream) throws IOException { |
|
838 |
if (zoneStrings == null) { |
|
839 |
zoneStrings = TimeZoneNameUtility.getZoneStrings(locale); |
|
840 |
} |
|
841 |
stream.defaultWriteObject(); |
|
842 |
} |
|
843 |
} |