1 /*
2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
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
198 + " * accompanied this code).\n"
199 + " *\n"
200 + " * You should have received a copy of the GNU General Public License version\n"
201 + " * 2 along with this work; if not, write to the Free Software Foundation,\n"
202 + " * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\n"
203 + " *\n"
204 + " * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\n"
205 + " * or visit www.oracle.com if you need additional information or have any\n"
206 + " * questions.\n"
207 + "*/\n\n";
208
209 private static final String headerText =
210 "package sun.util.locale;\n\n"
211 + "import java.util.HashMap;\n"
212 + "import java.util.Map;\n\n"
213 + "final class LocaleEquivalentMaps {\n\n"
214 + " static final Map<String, String> singleEquivMap;\n"
215 + " static final Map<String, String[]> multiEquivsMap;\n"
216 + " static final Map<String, String> regionVariantEquivMap;\n\n"
217 + " static {\n"
218 + " singleEquivMap = new HashMap<>();\n"
219 + " multiEquivsMap = new HashMap<>();\n"
220 + " regionVariantEquivMap = new HashMap<>();\n\n"
221 + " // This is an auto-generated file and should not be manually edited.\n";
222
223 private static final String footerText =
224 " }\n\n"
225 + "}";
226
227 private static String getOpenJDKCopyright() {
228 int year = ZonedDateTime.now(ZoneId
229 .of("America/Los_Angeles")).getYear();
230 return String.format(Locale.US, COPYRIGHT, year);
231 }
232
233 /**
234 * The input lsr data file is in UTF-8, so theoretically for the characters
235 * beyond US-ASCII, the generated Java String literals need to be Unicode
236 * escaped (\\uXXXX) while writing to a file. But as of now, there is not
237 * the case since we don't use "description", "comment" or alike.
238 */
239 private static void generateSourceCode(String fileName) {
240
241 try (BufferedWriter writer = Files.newBufferedWriter(
242 Paths.get(fileName))) {
243 writer.write(getOpenJDKCopyright());
244 writer.write(headerText
245 + " // LSR Revision: " + LSRrevisionDate);
246 writer.newLine();
247
248 for (String key : sortedLanguageMap1.keySet()) {
249 String value = sortedLanguageMap1.get(key);
250 writer.write(" singleEquivMap.put(\""
251 + key + "\", \"" + value + "\");");
252 writer.newLine();
253 }
254
255 writer.newLine();
256 for (String key : sortedLanguageMap2.keySet()) {
257 String[] values = sortedLanguageMap2.get(key);
258
259 if (values.length >= 2) {
260 writer.write(" multiEquivsMap.put(\""
261 + key + "\", new String[] {"
262 + generateValuesString(values) + "});");
263 writer.newLine();
264 }
|
1 /*
2 * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
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
198 + " * accompanied this code).\n"
199 + " *\n"
200 + " * You should have received a copy of the GNU General Public License version\n"
201 + " * 2 along with this work; if not, write to the Free Software Foundation,\n"
202 + " * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\n"
203 + " *\n"
204 + " * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\n"
205 + " * or visit www.oracle.com if you need additional information or have any\n"
206 + " * questions.\n"
207 + "*/\n\n";
208
209 private static final String headerText =
210 "package sun.util.locale;\n\n"
211 + "import java.util.HashMap;\n"
212 + "import java.util.Map;\n\n"
213 + "final class LocaleEquivalentMaps {\n\n"
214 + " static final Map<String, String> singleEquivMap;\n"
215 + " static final Map<String, String[]> multiEquivsMap;\n"
216 + " static final Map<String, String> regionVariantEquivMap;\n\n"
217 + " static {\n"
218 + " singleEquivMap = new HashMap<>(";
219
220 private static final String footerText =
221 " }\n\n"
222 + "}";
223
224 private static String getOpenJDKCopyright() {
225 int year = ZonedDateTime.now(ZoneId
226 .of("America/Los_Angeles")).getYear();
227 return String.format(Locale.US, COPYRIGHT, year);
228 }
229
230 /**
231 * The input lsr data file is in UTF-8, so theoretically for the characters
232 * beyond US-ASCII, the generated Java String literals need to be Unicode
233 * escaped (\\uXXXX) while writing to a file. But as of now, there is not
234 * the case since we don't use "description", "comment" or alike.
235 */
236 private static void generateSourceCode(String fileName) {
237
238 try (BufferedWriter writer = Files.newBufferedWriter(
239 Paths.get(fileName))) {
240 writer.write(getOpenJDKCopyright());
241 writer.write(headerText
242 + (int)(sortedLanguageMap1.size() / 0.75f + 1) + ");\n"
243 + " multiEquivsMap = new HashMap<>("
244 + (int)(sortedLanguageMap2.size() / 0.75f + 1) + ");\n"
245 + " regionVariantEquivMap = new HashMap<>("
246 + (int)(sortedRegionVariantMap.size() / 0.75f + 1) + ");\n\n"
247 + " // This is an auto-generated file and should not be manually edited.\n"
248 + " // LSR Revision: " + LSRrevisionDate);
249 writer.newLine();
250
251 for (String key : sortedLanguageMap1.keySet()) {
252 String value = sortedLanguageMap1.get(key);
253 writer.write(" singleEquivMap.put(\""
254 + key + "\", \"" + value + "\");");
255 writer.newLine();
256 }
257
258 writer.newLine();
259 for (String key : sortedLanguageMap2.keySet()) {
260 String[] values = sortedLanguageMap2.get(key);
261
262 if (values.length >= 2) {
263 writer.write(" multiEquivsMap.put(\""
264 + key + "\", new String[] {"
265 + generateValuesString(values) + "});");
266 writer.newLine();
267 }
|