author | pliden |
Tue, 18 Sep 2018 22:46:35 +0200 | |
changeset 51794 | 4129f43607cb |
parent 49904 | cadca99d52e7 |
child 52869 | c5c0db0b7c2f |
permissions | -rw-r--r-- |
13583 | 1 |
/* |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
13583 | 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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
* |
|
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. |
|
24 |
*/ |
|
25 |
||
26 |
package build.tools.cldrconverter; |
|
27 |
||
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Arrays; |
|
30 |
import java.util.EnumSet; |
|
31 |
import java.util.HashMap; |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
32 |
import java.util.Iterator; |
13583 | 33 |
import java.util.List; |
34 |
import java.util.Map; |
|
31263 | 35 |
import java.util.Objects; |
13583 | 36 |
|
37 |
class Bundle { |
|
38 |
static enum Type { |
|
39 |
LOCALENAMES, CURRENCYNAMES, TIMEZONENAMES, CALENDARDATA, FORMATDATA; |
|
40 |
||
41 |
static EnumSet<Type> ALL_TYPES = EnumSet.of(LOCALENAMES, |
|
42 |
CURRENCYNAMES, |
|
43 |
TIMEZONENAMES, |
|
44 |
CALENDARDATA, |
|
45 |
FORMATDATA); |
|
46 |
} |
|
47 |
||
48 |
private final static Map<String, Bundle> bundles = new HashMap<>(); |
|
49 |
||
50 |
private final static String[] NUMBER_PATTERN_KEYS = { |
|
51 |
"NumberPatterns/decimal", |
|
52 |
"NumberPatterns/currency", |
|
53 |
"NumberPatterns/percent" |
|
54 |
}; |
|
55 |
||
56 |
private final static String[] NUMBER_ELEMENT_KEYS = { |
|
57 |
"NumberElements/decimal", |
|
58 |
"NumberElements/group", |
|
59 |
"NumberElements/list", |
|
60 |
"NumberElements/percent", |
|
61 |
"NumberElements/zero", |
|
62 |
"NumberElements/pattern", |
|
63 |
"NumberElements/minus", |
|
64 |
"NumberElements/exponential", |
|
65 |
"NumberElements/permille", |
|
66 |
"NumberElements/infinity", |
|
67 |
"NumberElements/nan" |
|
68 |
}; |
|
69 |
||
70 |
private final static String[] TIME_PATTERN_KEYS = { |
|
71 |
"DateTimePatterns/full-time", |
|
72 |
"DateTimePatterns/long-time", |
|
73 |
"DateTimePatterns/medium-time", |
|
74 |
"DateTimePatterns/short-time", |
|
75 |
}; |
|
76 |
||
77 |
private final static String[] DATE_PATTERN_KEYS = { |
|
78 |
"DateTimePatterns/full-date", |
|
79 |
"DateTimePatterns/long-date", |
|
80 |
"DateTimePatterns/medium-date", |
|
81 |
"DateTimePatterns/short-date", |
|
82 |
}; |
|
83 |
||
84 |
private final static String[] DATETIME_PATTERN_KEYS = { |
|
31263 | 85 |
"DateTimePatterns/full-dateTime", |
86 |
"DateTimePatterns/long-dateTime", |
|
87 |
"DateTimePatterns/medium-dateTime", |
|
88 |
"DateTimePatterns/short-dateTime", |
|
13583 | 89 |
}; |
90 |
||
91 |
private final static String[] ERA_KEYS = { |
|
92 |
"long.Eras", |
|
93 |
"Eras", |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
94 |
"narrow.Eras" |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
95 |
}; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
96 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
97 |
// Keys for individual time zone names |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
98 |
private final static String TZ_GEN_LONG_KEY = "timezone.displayname.generic.long"; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
99 |
private final static String TZ_GEN_SHORT_KEY = "timezone.displayname.generic.short"; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
100 |
private final static String TZ_STD_LONG_KEY = "timezone.displayname.standard.long"; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
101 |
private final static String TZ_STD_SHORT_KEY = "timezone.displayname.standard.short"; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
102 |
private final static String TZ_DST_LONG_KEY = "timezone.displayname.daylight.long"; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
103 |
private final static String TZ_DST_SHORT_KEY = "timezone.displayname.daylight.short"; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
104 |
private final static String[] ZONE_NAME_KEYS = { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
105 |
TZ_STD_LONG_KEY, |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
106 |
TZ_STD_SHORT_KEY, |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
107 |
TZ_DST_LONG_KEY, |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
108 |
TZ_DST_SHORT_KEY, |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
109 |
TZ_GEN_LONG_KEY, |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
110 |
TZ_GEN_SHORT_KEY |
13583 | 111 |
}; |
112 |
||
113 |
private final String id; |
|
114 |
private final String cldrPath; |
|
115 |
private final EnumSet<Type> bundleTypes; |
|
116 |
private final String currencies; |
|
32510
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
117 |
private Map<String, Object> targetMap; |
13583 | 118 |
|
119 |
static Bundle getBundle(String id) { |
|
120 |
return bundles.get(id); |
|
121 |
} |
|
122 |
||
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
123 |
@SuppressWarnings("ConvertToStringSwitch") |
13583 | 124 |
Bundle(String id, String cldrPath, String bundles, String currencies) { |
125 |
this.id = id; |
|
126 |
this.cldrPath = cldrPath; |
|
127 |
if ("localenames".equals(bundles)) { |
|
128 |
bundleTypes = EnumSet.of(Type.LOCALENAMES); |
|
129 |
} else if ("currencynames".equals(bundles)) { |
|
130 |
bundleTypes = EnumSet.of(Type.CURRENCYNAMES); |
|
131 |
} else { |
|
132 |
bundleTypes = Type.ALL_TYPES; |
|
133 |
} |
|
134 |
if (currencies == null) { |
|
135 |
currencies = "local"; |
|
136 |
} |
|
137 |
this.currencies = currencies; |
|
138 |
addBundle(); |
|
139 |
} |
|
140 |
||
141 |
private void addBundle() { |
|
142 |
Bundle.bundles.put(id, this); |
|
143 |
} |
|
144 |
||
145 |
String getID() { |
|
146 |
return id; |
|
147 |
} |
|
148 |
||
32030
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
32015
diff
changeset
|
149 |
String getJavaID() { |
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
32015
diff
changeset
|
150 |
// Tweak ISO compatibility for bundle generation |
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
32015
diff
changeset
|
151 |
return id.replaceFirst("^he", "iw") |
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
32015
diff
changeset
|
152 |
.replaceFirst("^id", "in") |
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
32015
diff
changeset
|
153 |
.replaceFirst("^yi", "ji"); |
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
32015
diff
changeset
|
154 |
} |
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
32015
diff
changeset
|
155 |
|
13583 | 156 |
boolean isRoot() { |
157 |
return "root".equals(id); |
|
158 |
} |
|
159 |
||
160 |
String getCLDRPath() { |
|
161 |
return cldrPath; |
|
162 |
} |
|
163 |
||
164 |
EnumSet<Type> getBundleTypes() { |
|
165 |
return bundleTypes; |
|
166 |
} |
|
167 |
||
168 |
String getCurrencies() { |
|
169 |
return currencies; |
|
170 |
} |
|
171 |
||
172 |
/** |
|
173 |
* Generate a map that contains all the data that should be |
|
174 |
* visible for the bundle's locale |
|
175 |
*/ |
|
176 |
Map<String, Object> getTargetMap() throws Exception { |
|
32510
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
177 |
if (targetMap != null) { |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
178 |
return targetMap; |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
179 |
} |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
180 |
|
13583 | 181 |
String[] cldrBundles = getCLDRPath().split(","); |
182 |
||
183 |
// myMap contains resources for id. |
|
184 |
Map<String, Object> myMap = new HashMap<>(); |
|
185 |
int index; |
|
186 |
for (index = 0; index < cldrBundles.length; index++) { |
|
187 |
if (cldrBundles[index].equals(id)) { |
|
188 |
myMap.putAll(CLDRConverter.getCLDRBundle(cldrBundles[index])); |
|
31263 | 189 |
CLDRConverter.handleAliases(myMap); |
13583 | 190 |
break; |
191 |
} |
|
192 |
} |
|
193 |
||
194 |
// parentsMap contains resources from id's parents. |
|
195 |
Map<String, Object> parentsMap = new HashMap<>(); |
|
196 |
for (int i = cldrBundles.length - 1; i > index; i--) { |
|
197 |
if (!("no".equals(cldrBundles[i]) || cldrBundles[i].startsWith("no_"))) { |
|
198 |
parentsMap.putAll(CLDRConverter.getCLDRBundle(cldrBundles[i])); |
|
31263 | 199 |
CLDRConverter.handleAliases(parentsMap); |
13583 | 200 |
} |
201 |
} |
|
202 |
// Duplicate myMap as parentsMap for "root" so that the |
|
31263 | 203 |
// fallback works. This is a hack, though. |
13583 | 204 |
if ("root".equals(cldrBundles[0])) { |
205 |
assert parentsMap.isEmpty(); |
|
206 |
parentsMap.putAll(myMap); |
|
207 |
} |
|
208 |
||
209 |
// merge individual strings into arrays |
|
210 |
||
211 |
// if myMap has any of the NumberPatterns members |
|
212 |
for (String k : NUMBER_PATTERN_KEYS) { |
|
213 |
if (myMap.containsKey(k)) { |
|
214 |
String[] numberPatterns = new String[NUMBER_PATTERN_KEYS.length]; |
|
215 |
for (int i = 0; i < NUMBER_PATTERN_KEYS.length; i++) { |
|
216 |
String key = NUMBER_PATTERN_KEYS[i]; |
|
217 |
String value = (String) myMap.remove(key); |
|
218 |
if (value == null) { |
|
219 |
value = (String) parentsMap.remove(key); |
|
220 |
} |
|
221 |
if (value.length() == 0) { |
|
222 |
CLDRConverter.warning("empty pattern for " + key); |
|
223 |
} |
|
224 |
numberPatterns[i] = value; |
|
225 |
} |
|
226 |
myMap.put("NumberPatterns", numberPatterns); |
|
227 |
break; |
|
228 |
} |
|
229 |
} |
|
230 |
||
231 |
// if myMap has any of NUMBER_ELEMENT_KEYS, create a complete NumberElements. |
|
232 |
String defaultScript = (String) myMap.get("DefaultNumberingSystem"); |
|
233 |
@SuppressWarnings("unchecked") |
|
234 |
List<String> scripts = (List<String>) myMap.get("numberingScripts"); |
|
235 |
if (defaultScript == null && scripts != null) { |
|
236 |
// Some locale data has no default script for numbering even with mutiple scripts. |
|
237 |
// Take the first one as default in that case. |
|
238 |
defaultScript = scripts.get(0); |
|
239 |
myMap.put("DefaultNumberingSystem", defaultScript); |
|
240 |
} |
|
241 |
if (scripts != null) { |
|
242 |
for (String script : scripts) { |
|
243 |
for (String k : NUMBER_ELEMENT_KEYS) { |
|
244 |
String[] numberElements = new String[NUMBER_ELEMENT_KEYS.length]; |
|
245 |
for (int i = 0; i < NUMBER_ELEMENT_KEYS.length; i++) { |
|
246 |
String key = script + "." + NUMBER_ELEMENT_KEYS[i]; |
|
247 |
String value = (String) myMap.remove(key); |
|
248 |
if (value == null) { |
|
249 |
if (key.endsWith("/pattern")) { |
|
250 |
value = "#"; |
|
251 |
} else { |
|
252 |
value = (String) parentsMap.get(key); |
|
253 |
if (value == null) { |
|
254 |
// the last resort is "latn" |
|
255 |
key = "latn." + NUMBER_ELEMENT_KEYS[i]; |
|
256 |
value = (String) parentsMap.get(key); |
|
257 |
if (value == null) { |
|
258 |
throw new InternalError("NumberElements: null for " + key); |
|
259 |
} |
|
260 |
} |
|
261 |
} |
|
262 |
} |
|
263 |
numberElements[i] = value; |
|
264 |
} |
|
265 |
myMap.put(script + "." + "NumberElements", numberElements); |
|
266 |
break; |
|
267 |
} |
|
268 |
} |
|
269 |
} |
|
270 |
||
271 |
// another hack: parentsMap is not used for date-time resources. |
|
272 |
if ("root".equals(id)) { |
|
273 |
parentsMap = null; |
|
274 |
} |
|
275 |
||
276 |
for (CalendarType calendarType : CalendarType.values()) { |
|
277 |
String calendarPrefix = calendarType.keyElementName(); |
|
278 |
// handle multiple inheritance for month and day names |
|
279 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "MonthNames"); |
|
280 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "MonthAbbreviations"); |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
281 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "MonthNarrows"); |
13583 | 282 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "DayNames"); |
283 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "DayAbbreviations"); |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
284 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "DayNarrows"); |
13583 | 285 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "AmPmMarkers"); |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
286 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "narrow.AmPmMarkers"); |
38747 | 287 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "abbreviated.AmPmMarkers"); |
16852 | 288 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "QuarterNames"); |
289 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "QuarterAbbreviations"); |
|
290 |
handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "QuarterNarrows"); |
|
13583 | 291 |
|
292 |
adjustEraNames(myMap, calendarType); |
|
293 |
||
294 |
handleDateTimeFormatPatterns(TIME_PATTERN_KEYS, myMap, parentsMap, calendarType, "TimePatterns"); |
|
295 |
handleDateTimeFormatPatterns(DATE_PATTERN_KEYS, myMap, parentsMap, calendarType, "DatePatterns"); |
|
296 |
handleDateTimeFormatPatterns(DATETIME_PATTERN_KEYS, myMap, parentsMap, calendarType, "DateTimePatterns"); |
|
297 |
} |
|
298 |
||
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
299 |
// First, weed out any empty timezone or metazone names from myMap. |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
300 |
// Fill in any missing abbreviations if locale is "en". |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
301 |
for (Iterator<String> it = myMap.keySet().iterator(); it.hasNext();) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
302 |
String key = it.next(); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
303 |
if (key.startsWith(CLDRConverter.TIMEZONE_ID_PREFIX) |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
304 |
|| key.startsWith(CLDRConverter.METAZONE_ID_PREFIX)) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
305 |
@SuppressWarnings("unchecked") |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
306 |
Map<String, String> nameMap = (Map<String, String>) myMap.get(key); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
307 |
if (nameMap.isEmpty()) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
308 |
// Some zones have only exemplarCity, which become empty. |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
309 |
// Remove those from the map. |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
310 |
it.remove(); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
311 |
continue; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
312 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
313 |
|
32015 | 314 |
if (id.equals("en")) { |
315 |
fillInJREs(key, nameMap); |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
316 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
317 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
318 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
319 |
for (Iterator<String> it = myMap.keySet().iterator(); it.hasNext();) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
320 |
String key = it.next(); |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
47216
diff
changeset
|
321 |
if (key.startsWith(CLDRConverter.TIMEZONE_ID_PREFIX) |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
322 |
|| key.startsWith(CLDRConverter.METAZONE_ID_PREFIX)) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
323 |
@SuppressWarnings("unchecked") |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
324 |
Map<String, String> nameMap = (Map<String, String>) myMap.get(key); |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
47216
diff
changeset
|
325 |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
326 |
// Convert key/value pairs to an array. |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
327 |
String[] names = new String[ZONE_NAME_KEYS.length]; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
328 |
int ix = 0; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
329 |
for (String nameKey : ZONE_NAME_KEYS) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
330 |
String name = nameMap.get(nameKey); |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
47216
diff
changeset
|
331 |
if (name == null && parentsMap != null) { |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
332 |
@SuppressWarnings("unchecked") |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
333 |
Map<String, String> parentNames = (Map<String, String>) parentsMap.get(key); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
334 |
if (parentNames != null) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
335 |
name = parentNames.get(nameKey); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
336 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
337 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
338 |
names[ix++] = name; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
339 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
340 |
if (hasNulls(names)) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
341 |
String metaKey = toMetaZoneKey(key); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
342 |
if (metaKey != null) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
343 |
Object obj = myMap.get(metaKey); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
344 |
if (obj instanceof String[]) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
345 |
String[] metaNames = (String[]) obj; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
346 |
for (int i = 0; i < names.length; i++) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
347 |
if (names[i] == null) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
348 |
names[i] = metaNames[i]; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
349 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
350 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
351 |
} else if (obj instanceof Map) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
352 |
@SuppressWarnings("unchecked") |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
353 |
Map<String, String> m = (Map<String, String>) obj; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
354 |
for (int i = 0; i < names.length; i++) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
355 |
if (names[i] == null) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
356 |
names[i] = m.get(ZONE_NAME_KEYS[i]); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
357 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
358 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
359 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
360 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
361 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
362 |
// replace the Map with the array |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
363 |
if (names != null) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
364 |
myMap.put(key, names); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
365 |
} else { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
366 |
it.remove(); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
367 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
368 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
369 |
} |
43295
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
370 |
// replace empty era names with parentMap era names |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
371 |
for (String key : ERA_KEYS) { |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
372 |
Object value = myMap.get(key); |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
373 |
if (value != null && value instanceof String[]) { |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
374 |
String[] eraStrings = (String[]) value; |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
375 |
for (String eraString : eraStrings) { |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
376 |
if (eraString == null || eraString.isEmpty()) { |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
377 |
fillInElements(parentsMap, key, value); |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
378 |
} |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
379 |
} |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
380 |
} |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
38747
diff
changeset
|
381 |
} |
31263 | 382 |
|
383 |
// Remove all duplicates |
|
384 |
if (Objects.nonNull(parentsMap)) { |
|
385 |
for (Iterator<String> it = myMap.keySet().iterator(); it.hasNext();) { |
|
386 |
String key = it.next(); |
|
32015 | 387 |
if (!key.equals("numberingScripts") && // real body "NumberElements" may differ |
388 |
Objects.deepEquals(parentsMap.get(key), myMap.get(key))) { |
|
31263 | 389 |
it.remove(); |
390 |
} |
|
391 |
} |
|
392 |
} |
|
393 |
||
32510
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
394 |
targetMap = myMap; |
13583 | 395 |
return myMap; |
396 |
} |
|
397 |
||
398 |
private void handleMultipleInheritance(Map<String, Object> map, Map<String, Object> parents, String key) { |
|
399 |
String formatKey = key + "/format"; |
|
400 |
Object format = map.get(formatKey); |
|
401 |
if (format != null) { |
|
402 |
map.remove(formatKey); |
|
403 |
map.put(key, format); |
|
404 |
if (fillInElements(parents, formatKey, format)) { |
|
405 |
map.remove(key); |
|
406 |
} |
|
407 |
} |
|
408 |
String standaloneKey = key + "/stand-alone"; |
|
409 |
Object standalone = map.get(standaloneKey); |
|
410 |
if (standalone != null) { |
|
411 |
map.remove(standaloneKey); |
|
412 |
String realKey = key; |
|
413 |
if (format != null) { |
|
414 |
realKey = "standalone." + key; |
|
415 |
} |
|
416 |
map.put(realKey, standalone); |
|
417 |
if (fillInElements(parents, standaloneKey, standalone)) { |
|
418 |
map.remove(realKey); |
|
419 |
} |
|
420 |
} |
|
421 |
} |
|
422 |
||
423 |
/** |
|
424 |
* Fills in any empty elements with its parent element. Returns true if the resulting array is |
|
425 |
* identical to its parent array. |
|
426 |
* |
|
427 |
* @param parents |
|
428 |
* @param key |
|
429 |
* @param value |
|
430 |
* @return true if the resulting array is identical to its parent array. |
|
431 |
*/ |
|
432 |
private boolean fillInElements(Map<String, Object> parents, String key, Object value) { |
|
433 |
if (parents == null) { |
|
434 |
return false; |
|
435 |
} |
|
436 |
if (value instanceof String[]) { |
|
437 |
Object pvalue = parents.get(key); |
|
438 |
if (pvalue != null && pvalue instanceof String[]) { |
|
439 |
String[] strings = (String[]) value; |
|
440 |
String[] pstrings = (String[]) pvalue; |
|
441 |
for (int i = 0; i < strings.length; i++) { |
|
442 |
if (strings[i] == null || strings[i].length() == 0) { |
|
443 |
strings[i] = pstrings[i]; |
|
444 |
} |
|
445 |
} |
|
446 |
return Arrays.equals(strings, pstrings); |
|
447 |
} |
|
448 |
} |
|
449 |
return false; |
|
450 |
} |
|
451 |
||
452 |
/* |
|
453 |
* Adjusts String[] for era names because JRE's Calendars use different |
|
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
454 |
* ERA value indexes in the Buddhist, Japanese Imperial, and Islamic calendars. |
13583 | 455 |
*/ |
456 |
private void adjustEraNames(Map<String, Object> map, CalendarType type) { |
|
457 |
String[][] eraNames = new String[ERA_KEYS.length][]; |
|
458 |
String[] realKeys = new String[ERA_KEYS.length]; |
|
459 |
int index = 0; |
|
460 |
for (String key : ERA_KEYS) { |
|
461 |
String realKey = type.keyElementName() + key; |
|
462 |
String[] value = (String[]) map.get(realKey); |
|
463 |
if (value != null) { |
|
464 |
switch (type) { |
|
465 |
case GREGORIAN: |
|
466 |
break; |
|
467 |
||
468 |
case JAPANESE: |
|
469 |
{ |
|
470 |
String[] newValue = new String[value.length + 1]; |
|
471 |
String[] julianEras = (String[]) map.get(key); |
|
472 |
if (julianEras != null && julianEras.length >= 2) { |
|
473 |
newValue[0] = julianEras[1]; |
|
474 |
} else { |
|
475 |
newValue[0] = ""; |
|
476 |
} |
|
477 |
System.arraycopy(value, 0, newValue, 1, value.length); |
|
478 |
value = newValue; |
|
479 |
} |
|
480 |
break; |
|
481 |
||
482 |
case BUDDHIST: |
|
483 |
// Replace the value |
|
484 |
value = new String[] {"BC", value[0]}; |
|
485 |
break; |
|
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
486 |
|
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
487 |
case ISLAMIC: |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
488 |
// Replace the value |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
489 |
value = new String[] {"", value[0]}; |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
490 |
break; |
13583 | 491 |
} |
492 |
if (!key.equals(realKey)) { |
|
493 |
map.put(realKey, value); |
|
494 |
} |
|
495 |
} |
|
496 |
realKeys[index] = realKey; |
|
497 |
eraNames[index++] = value; |
|
498 |
} |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
499 |
for (int i = 0; i < eraNames.length; i++) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
500 |
if (eraNames[i] == null) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
501 |
map.put(realKeys[i], null); |
13583 | 502 |
} |
503 |
} |
|
504 |
} |
|
505 |
||
506 |
private void handleDateTimeFormatPatterns(String[] patternKeys, Map<String, Object> myMap, Map<String, Object> parentsMap, |
|
507 |
CalendarType calendarType, String name) { |
|
508 |
String calendarPrefix = calendarType.keyElementName(); |
|
509 |
for (String k : patternKeys) { |
|
510 |
if (myMap.containsKey(calendarPrefix + k)) { |
|
511 |
int len = patternKeys.length; |
|
16852 | 512 |
List<String> rawPatterns = new ArrayList<>(len); |
513 |
List<String> patterns = new ArrayList<>(len); |
|
13583 | 514 |
for (int i = 0; i < len; i++) { |
515 |
String key = calendarPrefix + patternKeys[i]; |
|
516 |
String pattern = (String) myMap.remove(key); |
|
517 |
if (pattern == null) { |
|
518 |
pattern = (String) parentsMap.remove(key); |
|
519 |
} |
|
16852 | 520 |
rawPatterns.add(i, pattern); |
13583 | 521 |
if (pattern != null) { |
522 |
patterns.add(i, translateDateFormatLetters(calendarType, pattern)); |
|
16852 | 523 |
} else { |
524 |
patterns.add(i, null); |
|
13583 | 525 |
} |
526 |
} |
|
16852 | 527 |
// If patterns is empty or has any nulls, discard patterns. |
13583 | 528 |
if (patterns.isEmpty()) { |
529 |
return; |
|
530 |
} |
|
531 |
String key = calendarPrefix + name; |
|
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
532 |
if (!rawPatterns.equals(patterns)) { |
16852 | 533 |
myMap.put("java.time." + key, rawPatterns.toArray(new String[len])); |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
534 |
} |
13583 | 535 |
myMap.put(key, patterns.toArray(new String[len])); |
536 |
break; |
|
537 |
} |
|
538 |
} |
|
539 |
} |
|
540 |
||
541 |
private String translateDateFormatLetters(CalendarType calendarType, String cldrFormat) { |
|
542 |
String pattern = cldrFormat; |
|
543 |
int length = pattern.length(); |
|
544 |
boolean inQuote = false; |
|
545 |
StringBuilder jrePattern = new StringBuilder(length); |
|
546 |
int count = 0; |
|
547 |
char lastLetter = 0; |
|
548 |
||
549 |
for (int i = 0; i < length; i++) { |
|
550 |
char c = pattern.charAt(i); |
|
551 |
||
552 |
if (c == '\'') { |
|
553 |
// '' is treated as a single quote regardless of being |
|
554 |
// in a quoted section. |
|
555 |
if ((i + 1) < length) { |
|
556 |
char nextc = pattern.charAt(i + 1); |
|
557 |
if (nextc == '\'') { |
|
558 |
i++; |
|
559 |
if (count != 0) { |
|
560 |
convert(calendarType, lastLetter, count, jrePattern); |
|
561 |
lastLetter = 0; |
|
562 |
count = 0; |
|
563 |
} |
|
564 |
jrePattern.append("''"); |
|
565 |
continue; |
|
566 |
} |
|
567 |
} |
|
568 |
if (!inQuote) { |
|
569 |
if (count != 0) { |
|
570 |
convert(calendarType, lastLetter, count, jrePattern); |
|
571 |
lastLetter = 0; |
|
572 |
count = 0; |
|
573 |
} |
|
574 |
inQuote = true; |
|
575 |
} else { |
|
576 |
inQuote = false; |
|
577 |
} |
|
578 |
jrePattern.append(c); |
|
579 |
continue; |
|
580 |
} |
|
581 |
if (inQuote) { |
|
582 |
jrePattern.append(c); |
|
583 |
continue; |
|
584 |
} |
|
585 |
if (!(c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')) { |
|
586 |
if (count != 0) { |
|
587 |
convert(calendarType, lastLetter, count, jrePattern); |
|
588 |
lastLetter = 0; |
|
589 |
count = 0; |
|
590 |
} |
|
591 |
jrePattern.append(c); |
|
592 |
continue; |
|
593 |
} |
|
594 |
||
595 |
if (lastLetter == 0 || lastLetter == c) { |
|
596 |
lastLetter = c; |
|
597 |
count++; |
|
598 |
continue; |
|
599 |
} |
|
600 |
convert(calendarType, lastLetter, count, jrePattern); |
|
601 |
lastLetter = c; |
|
602 |
count = 1; |
|
603 |
} |
|
604 |
||
605 |
if (inQuote) { |
|
606 |
throw new InternalError("Unterminated quote in date-time pattern: " + cldrFormat); |
|
607 |
} |
|
608 |
||
609 |
if (count != 0) { |
|
610 |
convert(calendarType, lastLetter, count, jrePattern); |
|
611 |
} |
|
612 |
if (cldrFormat.contentEquals(jrePattern)) { |
|
613 |
return cldrFormat; |
|
614 |
} |
|
615 |
return jrePattern.toString(); |
|
616 |
} |
|
617 |
||
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
618 |
private String toMetaZoneKey(String tzKey) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
619 |
if (tzKey.startsWith(CLDRConverter.TIMEZONE_ID_PREFIX)) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
620 |
String tz = tzKey.substring(CLDRConverter.TIMEZONE_ID_PREFIX.length()); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
621 |
String meta = CLDRConverter.handlerMetaZones.get(tz); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
622 |
if (meta != null) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
623 |
return CLDRConverter.METAZONE_ID_PREFIX + meta; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
624 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
625 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
626 |
return null; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
627 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
628 |
|
32510
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
629 |
static List<Object[]> jreTimeZoneNames = Arrays.asList(TimeZoneNames.getContents()); |
32015 | 630 |
private void fillInJREs(String key, Map<String, String> map) { |
631 |
String tzid = null; |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
632 |
|
32015 | 633 |
if (key.startsWith(CLDRConverter.METAZONE_ID_PREFIX)) { |
634 |
// Look for tzid |
|
635 |
String meta = key.substring(CLDRConverter.METAZONE_ID_PREFIX.length()); |
|
636 |
if (meta.equals("GMT")) { |
|
637 |
tzid = meta; |
|
638 |
} else { |
|
639 |
for (String tz : CLDRConverter.handlerMetaZones.keySet()) { |
|
640 |
if (CLDRConverter.handlerMetaZones.get(tz).equals(meta)) { |
|
641 |
tzid = tz; |
|
642 |
break; |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
643 |
} |
32015 | 644 |
} |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
47216
diff
changeset
|
645 |
} |
32015 | 646 |
} else { |
647 |
tzid = key.substring(CLDRConverter.TIMEZONE_ID_PREFIX.length()); |
|
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
47216
diff
changeset
|
648 |
} |
32015 | 649 |
|
650 |
if (tzid != null) { |
|
651 |
for (Object[] jreZone : jreTimeZoneNames) { |
|
652 |
if (jreZone[0].equals(tzid)) { |
|
653 |
for (int i = 0; i < ZONE_NAME_KEYS.length; i++) { |
|
654 |
if (map.get(ZONE_NAME_KEYS[i]) == null) { |
|
655 |
String[] jreNames = (String[])jreZone[1]; |
|
656 |
map.put(ZONE_NAME_KEYS[i], jreNames[i]); |
|
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
47216
diff
changeset
|
657 |
} |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
47216
diff
changeset
|
658 |
} |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
47216
diff
changeset
|
659 |
break; |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
660 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
661 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
662 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
663 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
664 |
|
13583 | 665 |
private void convert(CalendarType calendarType, char cldrLetter, int count, StringBuilder sb) { |
666 |
switch (cldrLetter) { |
|
667 |
case 'G': |
|
668 |
if (calendarType != CalendarType.GREGORIAN) { |
|
669 |
// Adjust the number of 'G's for JRE SimpleDateFormat |
|
670 |
if (count == 5) { |
|
671 |
// CLDR narrow -> JRE short |
|
672 |
count = 1; |
|
673 |
} else if (count == 1) { |
|
674 |
// CLDR abbr -> JRE long |
|
675 |
count = 4; |
|
676 |
} |
|
677 |
} |
|
678 |
appendN(cldrLetter, count, sb); |
|
679 |
break; |
|
680 |
||
681 |
// TODO: support 'c' and 'e' in JRE SimpleDateFormat |
|
682 |
// Use 'u' and 'E' for now. |
|
683 |
case 'c': |
|
684 |
case 'e': |
|
685 |
switch (count) { |
|
686 |
case 1: |
|
687 |
sb.append('u'); |
|
688 |
break; |
|
689 |
case 3: |
|
690 |
case 4: |
|
691 |
appendN('E', count, sb); |
|
692 |
break; |
|
693 |
case 5: |
|
694 |
appendN('E', 3, sb); |
|
695 |
break; |
|
696 |
} |
|
697 |
break; |
|
698 |
||
31263 | 699 |
case 'l': |
700 |
// 'l' is deprecated as a pattern character. Should be ignored. |
|
701 |
break; |
|
702 |
||
703 |
case 'u': |
|
704 |
// Use 'y' for now. |
|
705 |
appendN('y', count, sb); |
|
706 |
break; |
|
707 |
||
13583 | 708 |
case 'v': |
709 |
case 'V': |
|
710 |
appendN('z', count, sb); |
|
711 |
break; |
|
712 |
||
713 |
case 'Z': |
|
714 |
if (count == 4 || count == 5) { |
|
715 |
sb.append("XXX"); |
|
716 |
} |
|
717 |
break; |
|
718 |
||
719 |
case 'U': |
|
720 |
case 'q': |
|
721 |
case 'Q': |
|
722 |
case 'g': |
|
723 |
case 'j': |
|
724 |
case 'A': |
|
31263 | 725 |
throw new InternalError(String.format("Unsupported letter: '%c', count=%d, id=%s%n", |
726 |
cldrLetter, count, id)); |
|
13583 | 727 |
default: |
728 |
appendN(cldrLetter, count, sb); |
|
729 |
break; |
|
730 |
} |
|
731 |
} |
|
732 |
||
733 |
private void appendN(char c, int n, StringBuilder sb) { |
|
734 |
for (int i = 0; i < n; i++) { |
|
735 |
sb.append(c); |
|
736 |
} |
|
737 |
} |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
738 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
739 |
private static boolean hasNulls(Object[] array) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
740 |
for (int i = 0; i < array.length; i++) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
741 |
if (array[i] == null) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
742 |
return true; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
743 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
744 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
745 |
return false; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
746 |
} |
13583 | 747 |
} |