jdk/test/java/util/Locale/tools/EquivMapsGenerator.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 23010 6dadb192ad81
child 38875 84d61f32a894
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14009
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21596
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
14009
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
     4
 *
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 14009
diff changeset
     7
 * published by the Free Software Foundation.
14009
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
     8
 *
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    13
 * accompanied this code).
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    14
 *
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    18
 *
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    21
 * questions.
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    22
 */
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    23
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    24
import java.io.*;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    25
import java.nio.charset.*;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    26
import java.nio.file.*;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    27
import java.util.*;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    28
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    29
public class EquivMapsGenerator {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    30
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    31
    /*
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    32
     * IANA Language Subtag Registry file downloaded from
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    33
     *     http://www.iana.org/assignments/language-subtag-registry
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    34
     */
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    35
    private static final String DEFAULT_LSR_FILE =
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    36
        "language-subtag-registry.txt";
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    37
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    38
    private static boolean verbose = false;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    39
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    41
        String fileLSR = DEFAULT_LSR_FILE;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    42
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    43
        for (int i = 0; i < args.length; i++) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    44
            String s = args[i];
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    45
            if (s.equals("-lsr")) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    46
                fileLSR = args[++i];
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    47
            } else if (s.equals("-verbose")) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    48
                verbose = true;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    49
            }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    50
        }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    51
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    52
        readLSRfile(fileLSR);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    53
        generateEquivalentMap();
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    54
        generateSourceCode();
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    55
    }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    56
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    57
    private static String LSRrevisionDate;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    58
    private static Map<String, StringBuilder> initialLanguageMap =
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    59
        new TreeMap<>();
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    60
    private static Map<String, StringBuilder> initialRegionVariantMap =
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    61
        new TreeMap<>();
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    62
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    63
    private static Map<String, String> sortedLanguageMap1 = new TreeMap<>();
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    64
    private static Map<String, String[]> sortedLanguageMap2 = new TreeMap<>();
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    65
    private static Map<String, String> sortedRegionVariantMap =
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    66
        new TreeMap<>();
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    67
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    68
    private static void readLSRfile(String filename) throws Exception {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    69
        String type = null;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    70
        String tag = null;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    71
        String preferred = null;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    72
        int mappingNum = 0;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    73
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    74
        for (String line : Files.readAllLines(Paths.get(filename),
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    75
                                              Charset.forName("UTF-8"))) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    76
            line = line.toLowerCase();
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    77
            int index = line.indexOf(' ')+1;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    78
            if (line.startsWith("file-date:")) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    79
                LSRrevisionDate = line.substring(index);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    80
                if (verbose) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    81
                    System.out.println("LSR revision date=" + LSRrevisionDate);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    82
                }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    83
            } else if (line.startsWith("type:")) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    84
                type = line.substring(index);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    85
            } else if (line.startsWith("tag:") || line.startsWith("subtag:")) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    86
                tag = line.substring(index);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    87
            } else if (line.startsWith("preferred-value:")
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    88
                       && !type.equals("extlang")) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    89
                preferred = line.substring(index);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    90
                mappingNum++;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    91
                processDeprecatedData(type, tag, preferred);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    92
            } else if (line.equals("%%")) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    93
                type = null;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    94
                tag = null;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    95
                preferred = null;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    96
            }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    97
        }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    98
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
    99
        if (verbose) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   100
            System.out.println("readLSRfile(" + filename + ")");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   101
            System.out.println("  Total number of mapping=" + mappingNum);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   102
            System.out.println("\n  Map for language. Size="
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   103
                + initialLanguageMap.size());
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   104
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   105
            for (String key : initialLanguageMap.keySet()) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   106
                System.out.println("    " + key + ": \""
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   107
                    + initialLanguageMap.get(key) + "\"");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   108
            }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   109
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   110
            System.out.println("\n  Map for region and variant. Size="
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   111
                + initialRegionVariantMap.size());
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   112
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   113
            for (String key : initialRegionVariantMap.keySet()) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   114
                System.out.println("    " + key + ": \""
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   115
                    + initialRegionVariantMap.get(key) + "\"");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   116
            }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   117
        }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   118
    }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   119
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   120
    private static void processDeprecatedData(String type,
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   121
                                              String tag,
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   122
                                              String preferred) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   123
        StringBuilder sb;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   124
        if (type.equals("region") || type.equals("variant")) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   125
            if (!initialRegionVariantMap.containsKey(preferred)) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   126
                sb = new StringBuilder("-");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   127
                sb.append(preferred);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   128
                sb.append(",-");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   129
                sb.append(tag);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   130
                initialRegionVariantMap.put("-"+preferred, sb);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   131
            } else {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   132
                throw new RuntimeException("New case, need implementation."
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   133
                    + " A region/variant subtag \"" + preferred
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   134
                    + "\" is registered for more than one subtags.");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   135
            }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   136
        } else { // language, grandfahered, and redundant
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   137
            if (!initialLanguageMap.containsKey(preferred)) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   138
                sb = new StringBuilder(preferred);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   139
                sb.append(',');
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   140
                sb.append(tag);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   141
                initialLanguageMap.put(preferred, sb);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   142
            } else {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   143
                sb = initialLanguageMap.get(preferred);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   144
                sb.append(',');
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   145
                sb.append(tag);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   146
                initialLanguageMap.put(preferred, sb);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   147
            }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   148
        }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   149
    }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   150
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   151
    private static void generateEquivalentMap() {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   152
        String[] subtags;
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   153
        for (String preferred : initialLanguageMap.keySet()) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   154
            subtags = initialLanguageMap.get(preferred).toString().split(",");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   155
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   156
            if (subtags.length == 2) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   157
                sortedLanguageMap1.put(subtags[0], subtags[1]);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   158
                sortedLanguageMap1.put(subtags[1], subtags[0]);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   159
            } else if (subtags.length == 3) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   160
                sortedLanguageMap2.put(subtags[0],
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   161
                                     new String[]{subtags[1], subtags[2]});
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   162
                sortedLanguageMap2.put(subtags[1],
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   163
                                     new String[]{subtags[0], subtags[2]});
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   164
                sortedLanguageMap2.put(subtags[2],
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   165
                                     new String[]{subtags[0], subtags[1]});
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   166
            } else {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   167
                    throw new RuntimeException("New case, need implementation."
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   168
                        + " A language subtag \"" + preferred
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   169
                        + "\" is registered for more than two subtags. ");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   170
            }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   171
        }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   172
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   173
        for (String preferred : initialRegionVariantMap.keySet()) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   174
            subtags =
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   175
                initialRegionVariantMap.get(preferred).toString().split(",");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   176
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   177
            sortedRegionVariantMap.put(subtags[0], subtags[1]);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   178
            sortedRegionVariantMap.put(subtags[1], subtags[0]);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   179
        }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   180
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   181
        if (verbose) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   182
            System.out.println("generateEquivalentMap()");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   183
            System.out.println("  \nSorted map for language subtags which have only one equivalent. Size="
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   184
                + sortedLanguageMap1.size());
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   185
            for (String key : sortedLanguageMap1.keySet()) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   186
                System.out.println("    " + key + ": \""
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   187
                    + sortedLanguageMap1.get(key) + "\"");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   188
            }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   189
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   190
            System.out.println("\n  Sorted map for language subtags which have multiple equivalents. Size="
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   191
                + sortedLanguageMap2.size());
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   192
            for (String key : sortedLanguageMap2.keySet()) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   193
                String[] s = sortedLanguageMap2.get(key);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   194
                System.out.println("    " + key + ": \""
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   195
                    + s[0] + "\", \"" + s[1] + "\"");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   196
            }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   197
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   198
            System.out.println("\n  Sorted map for region and variant subtags. Size="
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   199
                + sortedRegionVariantMap.size());
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   200
            for (String key : sortedRegionVariantMap.keySet()) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   201
                System.out.println("    " + key + ": \""
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   202
                    + sortedRegionVariantMap.get(key) + "\"");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   203
            }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   204
        }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   205
        System.out.println();
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   206
    }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   207
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 23010
diff changeset
   208
    private static final String headerText =
14009
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   209
        "final class LocaleEquivalentMaps {\n\n"
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   210
        + "    static final Map<String, String> singleEquivMap;\n"
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   211
        + "    static final Map<String, String[]> multiEquivsMap;\n"
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   212
        + "    static final Map<String, String> regionVariantEquivMap;\n\n"
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   213
        + "    static {\n"
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   214
        + "        singleEquivMap = new HashMap<>();\n"
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   215
        + "        multiEquivsMap = new HashMap<>();\n"
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   216
        + "        regionVariantEquivMap = new HashMap<>();\n\n"
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   217
        + "        // This is an auto-generated file and should not be manually edited.\n";
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   218
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 23010
diff changeset
   219
    private static final String footerText =
14009
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   220
        "    }\n\n"
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   221
        + "}";
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   222
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   223
    private static void generateSourceCode() {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   224
        System.out.println(headerText
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   225
            + "        //   LSR Revision: " + LSRrevisionDate);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   226
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   227
        for (String key : sortedLanguageMap1.keySet()) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   228
            String value = sortedLanguageMap1.get(key);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   229
            System.out.println("        singleEquivMap.put(\""
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   230
                + key + "\", \"" + value + "\");");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   231
        }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   232
        System.out.println();
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   233
        for (String key : sortedLanguageMap2.keySet()) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   234
            String[] values = sortedLanguageMap2.get(key);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   235
            System.out.println("        multiEquivsMap.put(\""
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   236
                + key + "\", new String[] {\"" + values[0] + "\", \""
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   237
                + values[1] + "\"});");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   238
        }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   239
        System.out.println();
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   240
        for (String key : sortedRegionVariantMap.keySet()) {
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   241
            String value = sortedRegionVariantMap.get(key);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   242
            System.out.println("        regionVariantEquivMap.put(\""
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   243
                + key + "\", \"" + value + "\");");
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   244
        }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   245
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   246
        System.out.println(footerText);
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   247
    }
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   248
21856a20cc1d 7069824: Support for BCP47 locale matching
peytoia
parents:
diff changeset
   249
}