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