author | mli |
Wed, 31 May 2017 19:54:16 -0700 | |
changeset 45434 | 4582657c7260 |
parent 42930 | b878b7b2788e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
36951
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
2 |
* Copyright (c) 1996, 2016, 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; |
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
50 |
import java.util.concurrent.ConcurrentHashMap; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
51 |
import java.util.concurrent.ConcurrentMap; |
13583 | 52 |
import sun.util.locale.provider.LocaleProviderAdapter; |
53 |
import sun.util.locale.provider.LocaleServiceProviderPool; |
|
15260 | 54 |
import sun.util.locale.provider.ResourceBundleBasedAdapter; |
13583 | 55 |
import sun.util.locale.provider.TimeZoneNameUtility; |
2 | 56 |
|
57 |
/** |
|
58 |
* <code>DateFormatSymbols</code> is a public class for encapsulating |
|
59 |
* localizable date-time formatting data, such as the names of the |
|
60 |
* 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
|
61 |
* <code>SimpleDateFormat</code> uses |
2 | 62 |
* <code>DateFormatSymbols</code> to encapsulate this information. |
63 |
* |
|
64 |
* <p> |
|
65 |
* Typically you shouldn't use <code>DateFormatSymbols</code> directly. |
|
66 |
* Rather, you are encouraged to create a date-time formatter with the |
|
67 |
* <code>DateFormat</code> class's factory methods: <code>getTimeInstance</code>, |
|
68 |
* <code>getDateInstance</code>, or <code>getDateTimeInstance</code>. |
|
69 |
* These methods automatically create a <code>DateFormatSymbols</code> for |
|
70 |
* the formatter so that you don't have to. After the |
|
71 |
* formatter is created, you may modify its format pattern using the |
|
72 |
* <code>setPattern</code> method. For more information about |
|
73 |
* creating formatters using <code>DateFormat</code>'s factory methods, |
|
74 |
* see {@link DateFormat}. |
|
75 |
* |
|
76 |
* <p> |
|
77 |
* If you decide to create a date-time formatter with a specific |
|
78 |
* format pattern for a specific locale, you can do so with: |
|
79 |
* <blockquote> |
|
80 |
* <pre> |
|
81 |
* new SimpleDateFormat(aPattern, DateFormatSymbols.getInstance(aLocale)). |
|
82 |
* </pre> |
|
83 |
* </blockquote> |
|
84 |
* |
|
85 |
* <p> |
|
86 |
* <code>DateFormatSymbols</code> objects are cloneable. When you obtain |
|
87 |
* a <code>DateFormatSymbols</code> object, feel free to modify the |
|
88 |
* date-time formatting data. For instance, you can replace the localized |
|
89 |
* date-time format pattern characters with the ones that you feel easy |
|
90 |
* to remember. Or you can change the representative cities |
|
91 |
* to your favorite ones. |
|
92 |
* |
|
93 |
* <p> |
|
94 |
* New <code>DateFormatSymbols</code> subclasses may be added to support |
|
95 |
* <code>SimpleDateFormat</code> for date-time formatting for additional locales. |
|
96 |
||
97 |
* @see DateFormat |
|
98 |
* @see SimpleDateFormat |
|
99 |
* @see java.util.SimpleTimeZone |
|
100 |
* @author Chen-Lieh Huang |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
42930
diff
changeset
|
101 |
* @since 1.1 |
2 | 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 |
/** |
|
36951
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
150 |
* Constructs an uninitialized DateFormatSymbols. |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
151 |
*/ |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
152 |
private DateFormatSymbols(boolean flag) { |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
153 |
} |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
154 |
|
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
155 |
/** |
2 | 156 |
* Era strings. For example: "AD" and "BC". An array of 2 strings, |
157 |
* indexed by <code>Calendar.BC</code> and <code>Calendar.AD</code>. |
|
158 |
* @serial |
|
159 |
*/ |
|
160 |
String eras[] = null; |
|
161 |
||
162 |
/** |
|
163 |
* Month strings. For example: "January", "February", etc. An array |
|
164 |
* of 13 strings (some calendars have 13 months), indexed by |
|
165 |
* <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc. |
|
166 |
* @serial |
|
167 |
*/ |
|
168 |
String months[] = null; |
|
169 |
||
170 |
/** |
|
171 |
* Short month strings. For example: "Jan", "Feb", etc. An array of |
|
172 |
* 13 strings (some calendars have 13 months), indexed by |
|
173 |
* <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc. |
|
174 |
||
175 |
* @serial |
|
176 |
*/ |
|
177 |
String shortMonths[] = null; |
|
178 |
||
179 |
/** |
|
180 |
* Weekday strings. For example: "Sunday", "Monday", etc. An array |
|
181 |
* of 8 strings, indexed by <code>Calendar.SUNDAY</code>, |
|
182 |
* <code>Calendar.MONDAY</code>, etc. |
|
183 |
* The element <code>weekdays[0]</code> is ignored. |
|
184 |
* @serial |
|
185 |
*/ |
|
186 |
String weekdays[] = null; |
|
187 |
||
188 |
/** |
|
189 |
* Short weekday strings. For example: "Sun", "Mon", etc. An array |
|
190 |
* of 8 strings, indexed by <code>Calendar.SUNDAY</code>, |
|
191 |
* <code>Calendar.MONDAY</code>, etc. |
|
192 |
* The element <code>shortWeekdays[0]</code> is ignored. |
|
193 |
* @serial |
|
194 |
*/ |
|
195 |
String shortWeekdays[] = null; |
|
196 |
||
197 |
/** |
|
198 |
* AM and PM strings. For example: "AM" and "PM". An array of |
|
199 |
* 2 strings, indexed by <code>Calendar.AM</code> and |
|
200 |
* <code>Calendar.PM</code>. |
|
201 |
* @serial |
|
202 |
*/ |
|
203 |
String ampms[] = null; |
|
204 |
||
205 |
/** |
|
206 |
* Localized names of time zones in this locale. This is a |
|
207 |
* two-dimensional array of strings of size <em>n</em> by <em>m</em>, |
|
208 |
* where <em>m</em> is at least 5. Each of the <em>n</em> rows is an |
|
209 |
* entry containing the localized names for a single <code>TimeZone</code>. |
|
210 |
* Each such row contains (with <code>i</code> ranging from |
|
211 |
* 0..<em>n</em>-1): |
|
212 |
* <ul> |
|
213 |
* <li><code>zoneStrings[i][0]</code> - time zone ID</li> |
|
214 |
* <li><code>zoneStrings[i][1]</code> - long name of zone in standard |
|
215 |
* time</li> |
|
216 |
* <li><code>zoneStrings[i][2]</code> - short name of zone in |
|
217 |
* standard time</li> |
|
218 |
* <li><code>zoneStrings[i][3]</code> - long name of zone in daylight |
|
219 |
* saving time</li> |
|
220 |
* <li><code>zoneStrings[i][4]</code> - short name of zone in daylight |
|
221 |
* saving time</li> |
|
222 |
* </ul> |
|
223 |
* The zone ID is <em>not</em> localized; it's one of the valid IDs of |
|
224 |
* the {@link java.util.TimeZone TimeZone} class that are not |
|
39319
d32c7b64cb93
7090039: Wrong link in comment of java.text.DateFormatSymbols
peytoia
parents:
36951
diff
changeset
|
225 |
* <a href="../util/TimeZone.html#CustomID">custom IDs</a>. |
2 | 226 |
* All other entries are localized names. |
227 |
* @see java.util.TimeZone |
|
228 |
* @serial |
|
229 |
*/ |
|
230 |
String zoneStrings[][] = null; |
|
231 |
||
232 |
/** |
|
233 |
* Indicates that zoneStrings is set externally with setZoneStrings() method. |
|
234 |
*/ |
|
235 |
transient boolean isZoneStringsSet = false; |
|
236 |
||
237 |
/** |
|
238 |
* Unlocalized date-time pattern characters. For example: 'y', 'd', etc. |
|
239 |
* All locales use the same these unlocalized pattern characters. |
|
240 |
*/ |
|
13583 | 241 |
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
|
242 |
|
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_ERA = 0; // G |
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_YEAR = 1; // y |
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_MONTH = 2; // M |
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_MONTH = 3; // d |
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_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
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
static final int PATTERN_ISO_ZONE = 21; // X |
13583 | 265 |
static final int PATTERN_MONTH_STANDALONE = 22; // L |
2 | 266 |
|
267 |
/** |
|
268 |
* Localized date-time pattern characters. For example, a locale may |
|
269 |
* wish to use 'u' rather than 'y' to represent years in its date format |
|
270 |
* pattern strings. |
|
271 |
* This string must be exactly 18 characters long, with the index of |
|
272 |
* the characters described by <code>DateFormat.ERA_FIELD</code>, |
|
273 |
* <code>DateFormat.YEAR_FIELD</code>, etc. Thus, if the string were |
|
274 |
* "Xz...", then localized patterns would use 'X' for era and 'z' for year. |
|
275 |
* @serial |
|
276 |
*/ |
|
277 |
String localPatternChars = null; |
|
278 |
||
279 |
/** |
|
280 |
* The locale which is used for initializing this DateFormatSymbols object. |
|
281 |
* |
|
282 |
* @since 1.6 |
|
283 |
* @serial |
|
284 |
*/ |
|
285 |
Locale locale = null; |
|
286 |
||
287 |
/* use serialVersionUID from JDK 1.1.4 for interoperability */ |
|
288 |
static final long serialVersionUID = -5987973545549424702L; |
|
289 |
||
290 |
/** |
|
291 |
* Returns an array of all locales for which the |
|
292 |
* <code>getInstance</code> methods of this class can return |
|
293 |
* localized instances. |
|
294 |
* The returned array represents the union of locales supported by the |
|
295 |
* Java runtime and by installed |
|
296 |
* {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider} |
|
297 |
* implementations. It must contain at least a <code>Locale</code> |
|
298 |
* instance equal to {@link java.util.Locale#US Locale.US}. |
|
299 |
* |
|
300 |
* @return An array of locales for which localized |
|
301 |
* <code>DateFormatSymbols</code> instances are available. |
|
302 |
* @since 1.6 |
|
303 |
*/ |
|
304 |
public static Locale[] getAvailableLocales() { |
|
305 |
LocaleServiceProviderPool pool= |
|
306 |
LocaleServiceProviderPool.getPool(DateFormatSymbolsProvider.class); |
|
307 |
return pool.getAvailableLocales(); |
|
308 |
} |
|
309 |
||
310 |
/** |
|
311 |
* Gets the <code>DateFormatSymbols</code> instance for the default |
|
312 |
* locale. This method provides access to <code>DateFormatSymbols</code> |
|
313 |
* instances for locales supported by the Java runtime itself as well |
|
314 |
* as for those supported by installed |
|
315 |
* {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider} |
|
316 |
* implementations. |
|
16010
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
317 |
* <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
|
318 |
* getInstance(Locale.getDefault(Locale.Category.FORMAT))}. |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
319 |
* @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
|
320 |
* @see java.util.Locale.Category#FORMAT |
2 | 321 |
* @return a <code>DateFormatSymbols</code> instance. |
322 |
* @since 1.6 |
|
323 |
*/ |
|
324 |
public static final DateFormatSymbols getInstance() { |
|
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
325 |
return getInstance(Locale.getDefault(Locale.Category.FORMAT)); |
2 | 326 |
} |
327 |
||
328 |
/** |
|
329 |
* Gets the <code>DateFormatSymbols</code> instance for the specified |
|
330 |
* locale. This method provides access to <code>DateFormatSymbols</code> |
|
331 |
* instances for locales supported by the Java runtime itself as well |
|
332 |
* as for those supported by installed |
|
333 |
* {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider} |
|
334 |
* implementations. |
|
335 |
* @param locale the given locale. |
|
336 |
* @return a <code>DateFormatSymbols</code> instance. |
|
337 |
* @exception NullPointerException if <code>locale</code> is null |
|
338 |
* @since 1.6 |
|
339 |
*/ |
|
340 |
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
|
341 |
DateFormatSymbols dfs = getProviderInstance(locale); |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
342 |
if (dfs != null) { |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
343 |
return dfs; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
344 |
} |
13583 | 345 |
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
|
346 |
} |
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 |
/** |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
349 |
* 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
|
350 |
* 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
|
351 |
* 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
|
352 |
* an application. |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
353 |
*/ |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
354 |
static final DateFormatSymbols getInstanceRef(Locale locale) { |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
355 |
DateFormatSymbols dfs = getProviderInstance(locale); |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
356 |
if (dfs != null) { |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
357 |
return dfs; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
358 |
} |
13583 | 359 |
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
|
360 |
} |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
361 |
|
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
362 |
private static DateFormatSymbols getProviderInstance(Locale locale) { |
13583 | 363 |
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); |
364 |
DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider(); |
|
365 |
DateFormatSymbols dfsyms = provider.getInstance(locale); |
|
366 |
if (dfsyms == null) { |
|
367 |
provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider(); |
|
368 |
dfsyms = provider.getInstance(locale); |
|
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
369 |
} |
13583 | 370 |
return dfsyms; |
2 | 371 |
} |
372 |
||
373 |
/** |
|
374 |
* Gets era strings. For example: "AD" and "BC". |
|
375 |
* @return the era strings. |
|
376 |
*/ |
|
377 |
public String[] getEras() { |
|
378 |
return Arrays.copyOf(eras, eras.length); |
|
379 |
} |
|
380 |
||
381 |
/** |
|
382 |
* Sets era strings. For example: "AD" and "BC". |
|
383 |
* @param newEras the new era strings. |
|
384 |
*/ |
|
385 |
public void setEras(String[] newEras) { |
|
386 |
eras = Arrays.copyOf(newEras, newEras.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
387 |
cachedHashCode = 0; |
2 | 388 |
} |
389 |
||
390 |
/** |
|
391 |
* Gets month strings. For example: "January", "February", etc. |
|
13583 | 392 |
* |
393 |
* <p>If the language requires different forms for formatting and |
|
394 |
* stand-alone usages, this method returns month names in the |
|
395 |
* formatting form. For example, the preferred month name for |
|
396 |
* January in the Czech language is <em>ledna</em> in the |
|
397 |
* formatting form, while it is <em>leden</em> in the stand-alone |
|
398 |
* form. This method returns {@code "ledna"} in this case. Refer |
|
399 |
* to the <a href="http://unicode.org/reports/tr35/#Calendar_Elements"> |
|
400 |
* Calendar Elements in the Unicode Locale Data Markup Language |
|
401 |
* (LDML) specification</a> for more details. |
|
402 |
* |
|
40391
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
403 |
* @return the month strings. Use |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
404 |
* {@link java.util.Calendar#JANUARY Calendar.JANUARY}, |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
405 |
* {@link java.util.Calendar#FEBRUARY Calendar.FEBRUARY}, |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
406 |
* etc. to index the result array. |
2 | 407 |
*/ |
408 |
public String[] getMonths() { |
|
409 |
return Arrays.copyOf(months, months.length); |
|
410 |
} |
|
411 |
||
412 |
/** |
|
413 |
* Sets month strings. For example: "January", "February", etc. |
|
40391
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
414 |
* @param newMonths the new month strings. The array should |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
415 |
* be indexed by {@link java.util.Calendar#JANUARY Calendar.JANUARY}, |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
416 |
* {@link java.util.Calendar#FEBRUARY Calendar.FEBRUARY}, etc. |
2 | 417 |
*/ |
418 |
public void setMonths(String[] newMonths) { |
|
419 |
months = Arrays.copyOf(newMonths, newMonths.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
420 |
cachedHashCode = 0; |
2 | 421 |
} |
422 |
||
423 |
/** |
|
424 |
* Gets short month strings. For example: "Jan", "Feb", etc. |
|
13583 | 425 |
* |
426 |
* <p>If the language requires different forms for formatting and |
|
39490
1450367e1082
8055900: j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
nishjain
parents:
39319
diff
changeset
|
427 |
* stand-alone usages, this method returns short month names in |
13583 | 428 |
* the formatting form. For example, the preferred abbreviation |
429 |
* for January in the Catalan language is <em>de gen.</em> in the |
|
430 |
* formatting form, while it is <em>gen.</em> in the stand-alone |
|
431 |
* form. This method returns {@code "de gen."} in this case. Refer |
|
432 |
* to the <a href="http://unicode.org/reports/tr35/#Calendar_Elements"> |
|
433 |
* Calendar Elements in the Unicode Locale Data Markup Language |
|
434 |
* (LDML) specification</a> for more details. |
|
435 |
* |
|
40391
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
436 |
* @return the short month strings. Use |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
437 |
* {@link java.util.Calendar#JANUARY Calendar.JANUARY}, |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
438 |
* {@link java.util.Calendar#FEBRUARY Calendar.FEBRUARY}, |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
439 |
* etc. to index the result array. |
2 | 440 |
*/ |
441 |
public String[] getShortMonths() { |
|
442 |
return Arrays.copyOf(shortMonths, shortMonths.length); |
|
443 |
} |
|
444 |
||
445 |
/** |
|
446 |
* Sets short month strings. For example: "Jan", "Feb", etc. |
|
40391
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
447 |
* @param newShortMonths the new short month strings. The array should |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
448 |
* be indexed by {@link java.util.Calendar#JANUARY Calendar.JANUARY}, |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
449 |
* {@link java.util.Calendar#FEBRUARY Calendar.FEBRUARY}, etc. |
2 | 450 |
*/ |
451 |
public void setShortMonths(String[] newShortMonths) { |
|
452 |
shortMonths = Arrays.copyOf(newShortMonths, newShortMonths.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
453 |
cachedHashCode = 0; |
2 | 454 |
} |
455 |
||
456 |
/** |
|
457 |
* Gets weekday strings. For example: "Sunday", "Monday", etc. |
|
40391
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
458 |
* @return the weekday strings. Use |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
459 |
* {@link java.util.Calendar#SUNDAY Calendar.SUNDAY}, |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
460 |
* {@link java.util.Calendar#MONDAY Calendar.MONDAY}, etc. to index |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
461 |
* the result array. |
2 | 462 |
*/ |
463 |
public String[] getWeekdays() { |
|
464 |
return Arrays.copyOf(weekdays, weekdays.length); |
|
465 |
} |
|
466 |
||
467 |
/** |
|
468 |
* Sets weekday strings. For example: "Sunday", "Monday", etc. |
|
469 |
* @param newWeekdays the new weekday strings. The array should |
|
40391
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
470 |
* be indexed by {@link java.util.Calendar#SUNDAY Calendar.SUNDAY}, |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
471 |
* {@link java.util.Calendar#MONDAY Calendar.MONDAY}, etc. |
2 | 472 |
*/ |
473 |
public void setWeekdays(String[] newWeekdays) { |
|
474 |
weekdays = Arrays.copyOf(newWeekdays, newWeekdays.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
475 |
cachedHashCode = 0; |
2 | 476 |
} |
477 |
||
478 |
/** |
|
479 |
* Gets short weekday strings. For example: "Sun", "Mon", etc. |
|
40391
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
480 |
* @return the short weekday strings. Use |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
481 |
* {@link java.util.Calendar#SUNDAY Calendar.SUNDAY}, |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
482 |
* {@link java.util.Calendar#MONDAY Calendar.MONDAY}, etc. to index |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
483 |
* the result array. |
2 | 484 |
*/ |
485 |
public String[] getShortWeekdays() { |
|
486 |
return Arrays.copyOf(shortWeekdays, shortWeekdays.length); |
|
487 |
} |
|
488 |
||
489 |
/** |
|
490 |
* Sets short weekday strings. For example: "Sun", "Mon", etc. |
|
491 |
* @param newShortWeekdays the new short weekday strings. The array should |
|
40391
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
492 |
* be indexed by {@link java.util.Calendar#SUNDAY Calendar.SUNDAY}, |
7c0d6665aef9
8129555: DateFormatSymbols: month-related methods must refer to Calendar constants
nishjain
parents:
39490
diff
changeset
|
493 |
* {@link java.util.Calendar#MONDAY Calendar.MONDAY}, etc. |
2 | 494 |
*/ |
495 |
public void setShortWeekdays(String[] newShortWeekdays) { |
|
496 |
shortWeekdays = Arrays.copyOf(newShortWeekdays, newShortWeekdays.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
497 |
cachedHashCode = 0; |
2 | 498 |
} |
499 |
||
500 |
/** |
|
501 |
* Gets ampm strings. For example: "AM" and "PM". |
|
502 |
* @return the ampm strings. |
|
503 |
*/ |
|
504 |
public String[] getAmPmStrings() { |
|
505 |
return Arrays.copyOf(ampms, ampms.length); |
|
506 |
} |
|
507 |
||
508 |
/** |
|
509 |
* Sets ampm strings. For example: "AM" and "PM". |
|
510 |
* @param newAmpms the new ampm strings. |
|
511 |
*/ |
|
512 |
public void setAmPmStrings(String[] newAmpms) { |
|
513 |
ampms = Arrays.copyOf(newAmpms, newAmpms.length); |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
514 |
cachedHashCode = 0; |
2 | 515 |
} |
516 |
||
517 |
/** |
|
518 |
* Gets time zone strings. Use of this method is discouraged; use |
|
519 |
* {@link java.util.TimeZone#getDisplayName() TimeZone.getDisplayName()} |
|
520 |
* instead. |
|
521 |
* <p> |
|
522 |
* The value returned is a |
|
523 |
* two-dimensional array of strings of size <em>n</em> by <em>m</em>, |
|
524 |
* where <em>m</em> is at least 5. Each of the <em>n</em> rows is an |
|
525 |
* entry containing the localized names for a single <code>TimeZone</code>. |
|
526 |
* Each such row contains (with <code>i</code> ranging from |
|
527 |
* 0..<em>n</em>-1): |
|
528 |
* <ul> |
|
529 |
* <li><code>zoneStrings[i][0]</code> - time zone ID</li> |
|
530 |
* <li><code>zoneStrings[i][1]</code> - long name of zone in standard |
|
531 |
* time</li> |
|
532 |
* <li><code>zoneStrings[i][2]</code> - short name of zone in |
|
533 |
* standard time</li> |
|
534 |
* <li><code>zoneStrings[i][3]</code> - long name of zone in daylight |
|
535 |
* saving time</li> |
|
536 |
* <li><code>zoneStrings[i][4]</code> - short name of zone in daylight |
|
537 |
* saving time</li> |
|
538 |
* </ul> |
|
539 |
* The zone ID is <em>not</em> localized; it's one of the valid IDs of |
|
540 |
* the {@link java.util.TimeZone TimeZone} class that are not |
|
541 |
* <a href="../util/TimeZone.html#CustomID">custom IDs</a>. |
|
542 |
* All other entries are localized names. If a zone does not implement |
|
543 |
* daylight saving time, the daylight saving time names should not be used. |
|
544 |
* <p> |
|
545 |
* If {@link #setZoneStrings(String[][]) setZoneStrings} has been called |
|
546 |
* on this <code>DateFormatSymbols</code> instance, then the strings |
|
547 |
* provided by that call are returned. Otherwise, the returned array |
|
548 |
* contains names provided by the Java runtime and by installed |
|
549 |
* {@link java.util.spi.TimeZoneNameProvider TimeZoneNameProvider} |
|
550 |
* implementations. |
|
551 |
* |
|
552 |
* @return the time zone strings. |
|
553 |
* @see #setZoneStrings(String[][]) |
|
554 |
*/ |
|
555 |
public String[][] getZoneStrings() { |
|
556 |
return getZoneStringsImpl(true); |
|
557 |
} |
|
558 |
||
559 |
/** |
|
560 |
* Sets time zone strings. The argument must be a |
|
561 |
* two-dimensional array of strings of size <em>n</em> by <em>m</em>, |
|
562 |
* where <em>m</em> is at least 5. Each of the <em>n</em> rows is an |
|
563 |
* entry containing the localized names for a single <code>TimeZone</code>. |
|
564 |
* Each such row contains (with <code>i</code> ranging from |
|
565 |
* 0..<em>n</em>-1): |
|
566 |
* <ul> |
|
567 |
* <li><code>zoneStrings[i][0]</code> - time zone ID</li> |
|
568 |
* <li><code>zoneStrings[i][1]</code> - long name of zone in standard |
|
569 |
* time</li> |
|
570 |
* <li><code>zoneStrings[i][2]</code> - short name of zone in |
|
571 |
* standard time</li> |
|
572 |
* <li><code>zoneStrings[i][3]</code> - long name of zone in daylight |
|
573 |
* saving time</li> |
|
574 |
* <li><code>zoneStrings[i][4]</code> - short name of zone in daylight |
|
575 |
* saving time</li> |
|
576 |
* </ul> |
|
577 |
* The zone ID is <em>not</em> localized; it's one of the valid IDs of |
|
578 |
* the {@link java.util.TimeZone TimeZone} class that are not |
|
579 |
* <a href="../util/TimeZone.html#CustomID">custom IDs</a>. |
|
580 |
* All other entries are localized names. |
|
581 |
* |
|
582 |
* @param newZoneStrings the new time zone strings. |
|
583 |
* @exception IllegalArgumentException if the length of any row in |
|
584 |
* <code>newZoneStrings</code> is less than 5 |
|
585 |
* @exception NullPointerException if <code>newZoneStrings</code> is null |
|
586 |
* @see #getZoneStrings() |
|
587 |
*/ |
|
588 |
public void setZoneStrings(String[][] newZoneStrings) { |
|
589 |
String[][] aCopy = new String[newZoneStrings.length][]; |
|
590 |
for (int i = 0; i < newZoneStrings.length; ++i) { |
|
591 |
int len = newZoneStrings[i].length; |
|
592 |
if (len < 5) { |
|
593 |
throw new IllegalArgumentException(); |
|
594 |
} |
|
595 |
aCopy[i] = Arrays.copyOf(newZoneStrings[i], len); |
|
596 |
} |
|
597 |
zoneStrings = aCopy; |
|
598 |
isZoneStringsSet = true; |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
599 |
cachedHashCode = 0; |
2 | 600 |
} |
601 |
||
602 |
/** |
|
603 |
* Gets localized date-time pattern characters. For example: 'u', 't', etc. |
|
604 |
* @return the localized date-time pattern characters. |
|
605 |
*/ |
|
606 |
public String getLocalPatternChars() { |
|
6491
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
607 |
return localPatternChars; |
2 | 608 |
} |
609 |
||
610 |
/** |
|
611 |
* Sets localized date-time pattern characters. For example: 'u', 't', etc. |
|
612 |
* @param newLocalPatternChars the new localized date-time |
|
613 |
* pattern characters. |
|
614 |
*/ |
|
615 |
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
|
616 |
// 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
|
617 |
localPatternChars = newLocalPatternChars.toString(); |
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
618 |
cachedHashCode = 0; |
2 | 619 |
} |
620 |
||
621 |
/** |
|
622 |
* Overrides Cloneable |
|
623 |
*/ |
|
624 |
public Object clone() |
|
625 |
{ |
|
626 |
try |
|
627 |
{ |
|
628 |
DateFormatSymbols other = (DateFormatSymbols)super.clone(); |
|
36253 | 629 |
copyMembers(this, other); |
2 | 630 |
return other; |
631 |
} catch (CloneNotSupportedException e) { |
|
10419
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
7003
diff
changeset
|
632 |
throw new InternalError(e); |
2 | 633 |
} |
634 |
} |
|
635 |
||
636 |
/** |
|
637 |
* Override hashCode. |
|
638 |
* Generates a hash code for the DateFormatSymbols object. |
|
639 |
*/ |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
640 |
@Override |
2 | 641 |
public int hashCode() { |
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
642 |
int hashCode = cachedHashCode; |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
643 |
if (hashCode == 0) { |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
644 |
hashCode = 5; |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
645 |
hashCode = 11 * hashCode + Arrays.hashCode(eras); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
646 |
hashCode = 11 * hashCode + Arrays.hashCode(months); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
647 |
hashCode = 11 * hashCode + Arrays.hashCode(shortMonths); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
648 |
hashCode = 11 * hashCode + Arrays.hashCode(weekdays); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
649 |
hashCode = 11 * hashCode + Arrays.hashCode(shortWeekdays); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
650 |
hashCode = 11 * hashCode + Arrays.hashCode(ampms); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
651 |
hashCode = 11 * hashCode + Arrays.deepHashCode(getZoneStringsWrapper()); |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
652 |
hashCode = 11 * hashCode + Objects.hashCode(localPatternChars); |
34774
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
25859
diff
changeset
|
653 |
if (hashCode != 0) { |
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
25859
diff
changeset
|
654 |
cachedHashCode = hashCode; |
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
25859
diff
changeset
|
655 |
} |
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
656 |
} |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
657 |
|
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
658 |
return hashCode; |
2 | 659 |
} |
660 |
||
661 |
/** |
|
662 |
* Override equals |
|
663 |
*/ |
|
664 |
public boolean equals(Object obj) |
|
665 |
{ |
|
666 |
if (this == obj) return true; |
|
667 |
if (obj == null || getClass() != obj.getClass()) return false; |
|
668 |
DateFormatSymbols that = (DateFormatSymbols) obj; |
|
669 |
return (Arrays.equals(eras, that.eras) |
|
670 |
&& Arrays.equals(months, that.months) |
|
671 |
&& Arrays.equals(shortMonths, that.shortMonths) |
|
672 |
&& Arrays.equals(weekdays, that.weekdays) |
|
673 |
&& Arrays.equals(shortWeekdays, that.shortWeekdays) |
|
674 |
&& Arrays.equals(ampms, that.ampms) |
|
675 |
&& Arrays.deepEquals(getZoneStringsWrapper(), that.getZoneStringsWrapper()) |
|
676 |
&& ((localPatternChars != null |
|
677 |
&& localPatternChars.equals(that.localPatternChars)) |
|
678 |
|| (localPatternChars == null |
|
679 |
&& that.localPatternChars == null))); |
|
680 |
} |
|
681 |
||
682 |
// =======================privates=============================== |
|
683 |
||
684 |
/** |
|
685 |
* Useful constant for defining time zone offsets. |
|
686 |
*/ |
|
687 |
static final int millisPerHour = 60*60*1000; |
|
688 |
||
689 |
/** |
|
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
690 |
* Cache to hold DateFormatSymbols instances per Locale. |
2 | 691 |
*/ |
36253 | 692 |
private static final ConcurrentMap<Locale, SoftReference<DateFormatSymbols>> cachedInstances |
13583 | 693 |
= new ConcurrentHashMap<>(3); |
2 | 694 |
|
34774
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
25859
diff
changeset
|
695 |
private transient int lastZoneIndex; |
12549
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
696 |
|
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
697 |
/** |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
698 |
* Cached hash code |
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
699 |
*/ |
34774
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
25859
diff
changeset
|
700 |
transient volatile int cachedHashCode; |
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
701 |
|
36951
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
702 |
/** |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
703 |
* Initializes this DateFormatSymbols with the locale data. This method uses |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
704 |
* a cached DateFormatSymbols instance for the given locale if available. If |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
705 |
* there's no cached one, this method creates an uninitialized instance and |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
706 |
* populates its fields from the resource bundle for the locale, and caches |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
707 |
* the instance. Note: zoneStrings isn't initialized in this method. |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
708 |
*/ |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
709 |
private void initializeData(Locale locale) { |
36253 | 710 |
SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); |
711 |
DateFormatSymbols dfs; |
|
36951
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
712 |
if (ref == null || (dfs = ref.get()) == null) { |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
713 |
if (ref != null) { |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
714 |
// Remove the empty SoftReference |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
715 |
cachedInstances.remove(locale, ref); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
716 |
} |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
717 |
dfs = new DateFormatSymbols(false); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
718 |
|
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
719 |
// Initialize the fields from the ResourceBundle for locale. |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
720 |
LocaleProviderAdapter adapter |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
721 |
= LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
722 |
// Avoid any potential recursions |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
723 |
if (!(adapter instanceof ResourceBundleBasedAdapter)) { |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
724 |
adapter = LocaleProviderAdapter.getResourceBundleBased(); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
725 |
} |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
726 |
ResourceBundle resource |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
727 |
= ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
728 |
|
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
729 |
dfs.locale = locale; |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
730 |
// JRE and CLDR use different keys |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
731 |
// JRE: Eras, short.Eras and narrow.Eras |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
732 |
// CLDR: long.Eras, Eras and narrow.Eras |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
733 |
if (resource.containsKey("Eras")) { |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
734 |
dfs.eras = resource.getStringArray("Eras"); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
735 |
} else if (resource.containsKey("long.Eras")) { |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
736 |
dfs.eras = resource.getStringArray("long.Eras"); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
737 |
} else if (resource.containsKey("short.Eras")) { |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
738 |
dfs.eras = resource.getStringArray("short.Eras"); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
739 |
} |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
740 |
dfs.months = resource.getStringArray("MonthNames"); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
741 |
dfs.shortMonths = resource.getStringArray("MonthAbbreviations"); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
742 |
dfs.ampms = resource.getStringArray("AmPmMarkers"); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
743 |
dfs.localPatternChars = resource.getString("DateTimePatternChars"); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
744 |
|
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
745 |
// Day of week names are stored in a 1-based array. |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
746 |
dfs.weekdays = toOneBasedArray(resource.getStringArray("DayNames")); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
747 |
dfs.shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
748 |
|
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
749 |
// Put dfs in the cache |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
750 |
ref = new SoftReference<>(dfs); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
751 |
SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
752 |
if (x != null) { |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
753 |
DateFormatSymbols y = x.get(); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
754 |
if (y == null) { |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
755 |
// Replace the empty SoftReference with ref. |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
756 |
cachedInstances.replace(locale, x, ref); |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
757 |
} else { |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
758 |
ref = x; |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
759 |
dfs = y; |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
760 |
} |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
761 |
} |
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
762 |
} |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
763 |
|
36951
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
764 |
// Copy the field values from dfs to this instance. |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
765 |
copyMembers(dfs, this); |
7003
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
766 |
} |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
767 |
|
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
768 |
private static String[] toOneBasedArray(String[] src) { |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
769 |
int len = src.length; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
770 |
String[] dst = new String[len + 1]; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
771 |
dst[0] = ""; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
772 |
for (int i = 0; i < len; i++) { |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
773 |
dst[i + 1] = src[i]; |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
774 |
} |
7d8d9506b4ee
6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents:
6497
diff
changeset
|
775 |
return dst; |
2 | 776 |
} |
777 |
||
778 |
/** |
|
779 |
* Package private: used by SimpleDateFormat |
|
780 |
* Gets the index for the given time zone ID to obtain the time zone |
|
781 |
* strings for formatting. The time zone ID is just for programmatic |
|
782 |
* lookup. NOT LOCALIZED!!! |
|
783 |
* @param ID the given time zone ID. |
|
784 |
* @return the index of the given time zone ID. Returns -1 if |
|
785 |
* the given time zone ID can't be located in the DateFormatSymbols object. |
|
786 |
* @see java.util.SimpleTimeZone |
|
787 |
*/ |
|
12549
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
788 |
final int getZoneIndex(String ID) { |
2 | 789 |
String[][] zoneStrings = getZoneStringsWrapper(); |
12549
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
790 |
|
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
791 |
/* |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
792 |
* getZoneIndex has been re-written for performance reasons. instead of |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
793 |
* 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
|
794 |
* index |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
795 |
*/ |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
796 |
if (lastZoneIndex < zoneStrings.length && ID.equals(zoneStrings[lastZoneIndex][0])) { |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
797 |
return lastZoneIndex; |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
798 |
} |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
799 |
|
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
800 |
/* slow path, search entire list */ |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
801 |
for (int index = 0; index < zoneStrings.length; index++) { |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
802 |
if (ID.equals(zoneStrings[index][0])) { |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
803 |
lastZoneIndex = index; |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
804 |
return index; |
db2c42dabfa4
7163865: Performance improvement for DateFormatSymbols.getZoneIndex(String)
youdwei
parents:
10419
diff
changeset
|
805 |
} |
2 | 806 |
} |
807 |
||
808 |
return -1; |
|
809 |
} |
|
810 |
||
811 |
/** |
|
812 |
* Wrapper method to the getZoneStrings(), which is called from inside |
|
813 |
* the java.text package and not to mutate the returned arrays, so that |
|
814 |
* it does not need to create a defensive copy. |
|
815 |
*/ |
|
816 |
final String[][] getZoneStringsWrapper() { |
|
817 |
if (isSubclassObject()) { |
|
818 |
return getZoneStrings(); |
|
819 |
} else { |
|
820 |
return getZoneStringsImpl(false); |
|
821 |
} |
|
822 |
} |
|
823 |
||
13583 | 824 |
private String[][] getZoneStringsImpl(boolean needsCopy) { |
2 | 825 |
if (zoneStrings == null) { |
826 |
zoneStrings = TimeZoneNameUtility.getZoneStrings(locale); |
|
827 |
} |
|
828 |
||
829 |
if (!needsCopy) { |
|
830 |
return zoneStrings; |
|
831 |
} |
|
832 |
||
833 |
int len = zoneStrings.length; |
|
834 |
String[][] aCopy = new String[len][]; |
|
835 |
for (int i = 0; i < len; i++) { |
|
836 |
aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length); |
|
837 |
} |
|
838 |
return aCopy; |
|
839 |
} |
|
840 |
||
13583 | 841 |
private boolean isSubclassObject() { |
2 | 842 |
return !getClass().getName().equals("java.text.DateFormatSymbols"); |
843 |
} |
|
844 |
||
845 |
/** |
|
846 |
* Clones all the data members from the source DateFormatSymbols to |
|
36951
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
847 |
* the target DateFormatSymbols. |
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
848 |
* |
2 | 849 |
* @param src the source DateFormatSymbols. |
850 |
* @param dst the target DateFormatSymbols. |
|
851 |
*/ |
|
36253 | 852 |
private void copyMembers(DateFormatSymbols src, DateFormatSymbols dst) |
2 | 853 |
{ |
36951
0953f2a2cb14
8151431: DateFormatSymbols triggers this.clone() in the constructor
okutsu
parents:
36253
diff
changeset
|
854 |
dst.locale = src.locale; |
2 | 855 |
dst.eras = Arrays.copyOf(src.eras, src.eras.length); |
856 |
dst.months = Arrays.copyOf(src.months, src.months.length); |
|
857 |
dst.shortMonths = Arrays.copyOf(src.shortMonths, src.shortMonths.length); |
|
858 |
dst.weekdays = Arrays.copyOf(src.weekdays, src.weekdays.length); |
|
859 |
dst.shortWeekdays = Arrays.copyOf(src.shortWeekdays, src.shortWeekdays.length); |
|
860 |
dst.ampms = Arrays.copyOf(src.ampms, src.ampms.length); |
|
861 |
if (src.zoneStrings != null) { |
|
36253 | 862 |
dst.zoneStrings = src.getZoneStringsImpl(true); |
2 | 863 |
} else { |
864 |
dst.zoneStrings = null; |
|
865 |
} |
|
6491
cd1bcc5057f4
4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents:
6489
diff
changeset
|
866 |
dst.localPatternChars = src.localPatternChars; |
14172
fad44417edf8
7200341: DateFormatSymbols.hashCode() throws ArrayIndexOutOfBoundsException in some circumstances
naoto
parents:
13583
diff
changeset
|
867 |
dst.cachedHashCode = 0; |
2 | 868 |
} |
869 |
||
870 |
/** |
|
871 |
* Write out the default serializable data, after ensuring the |
|
872 |
* <code>zoneStrings</code> field is initialized in order to make |
|
873 |
* sure the backward compatibility. |
|
874 |
* |
|
875 |
* @since 1.6 |
|
876 |
*/ |
|
877 |
private void writeObject(ObjectOutputStream stream) throws IOException { |
|
878 |
if (zoneStrings == null) { |
|
879 |
zoneStrings = TimeZoneNameUtility.getZoneStrings(locale); |
|
880 |
} |
|
881 |
stream.defaultWriteObject(); |
|
882 |
} |
|
883 |
} |