make/jdk/src/classes/build/tools/generatecharacter/SpecialCaseMap.java
author pliden
Thu, 26 Sep 2019 13:56:58 +0200
changeset 58355 de246fd65587
parent 47216 71c04702a3d5
permissions -rw-r--r--
8231294: ZGC: vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted002 fails Reviewed-by: shade, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21805
diff changeset
     2
 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package build.tools.generatecharacter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * SpecialCaseMap has the responsibility of storing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * 1:M, locale-sensitive, and context sensitive case mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * that occur when uppercasing Unicode 4.0 characters. This class can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * read and parse the SpecialCasing.txt file that contains those mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * A single SpecialCaseMap contains the mapping for one character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author John O'Conner
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
    42
public class SpecialCaseMap implements Comparable<SpecialCaseMap> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    SpecialCaseMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        chSource = 0xFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Read and parse a Unicode special case map file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * @param file   a file specifying the Unicode special case mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @return  an array of SpecialCaseMap objects, one for each line of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *          special case map data file that could be successfully parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static SpecialCaseMap[] readSpecFile(File file, int plane) throws FileNotFoundException {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
    58
        ArrayList<SpecialCaseMap> caseMaps = new ArrayList<>(150);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        BufferedReader f = new BufferedReader(new FileReader(file));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                String line = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        while(true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                line = f.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            catch (IOException e) { break loop; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                if (line == null) break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                SpecialCaseMap item = parse(line.trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                if (item != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                if(item.getCharSource() >> 16 < plane) continue;
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
    72
                                if(item.getCharSource() >> 16 > plane) break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                caseMaps.add(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                ++count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        caseMaps.trimToSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        SpecialCaseMap[] result = new SpecialCaseMap[caseMaps.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        caseMaps.toArray(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        Arrays.sort(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
    86
   /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    * Given one line of a Unicode special casing data file as a String, parse the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    * and return a SpecialCaseMap object that contains the case mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    * @param s a line of the Unicode special case map data file to be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    * @return a SpecialCaseMap object, or null if the parsing process failed for some reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static SpecialCaseMap parse(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        SpecialCaseMap spec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        String[] tokens = new String[REQUIRED_FIELDS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if ( s != null && s.length() != 0 && s.charAt(0) != '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                int x = 0, tokenStart = 0, tokenEnd = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                for (x=0; x<REQUIRED_FIELDS-1; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    tokenEnd = s.indexOf(';', tokenStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    tokens[x] = s.substring(tokenStart, tokenEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    tokenStart = tokenEnd+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                tokens[x] = s.substring(tokenStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                if(tokens[FIELD_CONDITIONS].indexOf(';') == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    spec = new SpecialCaseMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    spec.setCharSource(parseChar(tokens[FIELD_SOURCE]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    spec.setUpperCaseMap(parseCaseMap(tokens[FIELD_UPPERCASE]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                    spec.setLowerCaseMap(parseCaseMap(tokens[FIELD_LOWERCASE]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    spec.setTitleCaseMap(parseCaseMap(tokens[FIELD_TITLECASE]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    spec.setLocale(parseLocale(tokens[FIELD_CONDITIONS]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    spec.setContext(parseContext(tokens[FIELD_CONDITIONS]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                spec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                System.out.println("Error parsing spec line.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    static int parseChar(String token) throws NumberFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return Integer.parseInt(token, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    static char[] parseCaseMap(String token ) throws NumberFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        int pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        StringBuffer buff = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        int start = 0, end = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        while(pos < token.length() ){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            while(Character.isSpaceChar(token.charAt(pos++)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            --pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            start = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            while(pos < token.length() && !Character.isSpaceChar(token.charAt(pos))) pos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            end = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            int ch = parseChar(token.substring(start,end));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                        if (ch > 0xFFFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                buff.append(getHighSurrogate(ch));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                buff.append(getLowSurrogate(ch));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                buff.append((char)ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        char[] map = new char[buff.length()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        buff.getChars(0, buff.length(), map, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    static Locale parseLocale(String token) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    static String[] parseContext(String token) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    static  int find(int ch, SpecialCaseMap[] map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if ((map == null) || (map.length == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        int top, bottom, current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        bottom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        top = map.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        current = top/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        // invariant: top > current >= bottom && ch >= map.chSource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        while (top - bottom > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            if (ch >= map[current].getCharSource()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                bottom = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                top = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            current = (top + bottom) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (ch == map[current].getCharSource()) return current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        else return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   180
    /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Extracts and returns the high surrogate value from a UTF-32 code point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * If argument is a BMP character, then it is converted to a char and returned;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * otherwise the high surrogate value is extracted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param codePoint a UTF-32 codePoint with value greater than 0xFFFF.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @return the high surrogate value that helps create <code>codePoint</code>; else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *         the char representation of <code>codePoint</code> if it is a BMP character.
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   187
     * @since 1.5
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   189
    static char getHighSurrogate(int codePoint) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   190
        char high = (char)codePoint;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   191
        if (codePoint > 0xFFFF) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   192
            high = (char)((codePoint - 0x10000)/0x0400 + 0xD800);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   194
        return high;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   195
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   198
    /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Extracts and returns the low surrogate value from a UTF-32 code point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * If argument is a BMP character, then it is converted to a char and returned;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * otherwise the high surrogate value is extracted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param codePoint a UTF-32 codePoint with value greater than 0xFFFF.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return the low surrogate value that helps create <code>codePoint</code>; else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *         the char representation of <code>codePoint</code> if it is a BMP character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   207
    static char getLowSurrogate(int codePoint) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   208
        char low = (char)codePoint;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   209
        if(codePoint > 0xFFFF) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   210
                low = (char)((codePoint - 0x10000)%0x0400 + 0xDC00);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   212
        return low;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   213
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   215
    static String hex6(int n) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   216
        String str = Integer.toHexString(n & 0xFFFFFF).toUpperCase();
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   217
        return "000000".substring(Math.min(6, str.length())) + str;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   218
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   220
    static String hex6(char[] map){
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   221
        StringBuffer buff = new StringBuffer();
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   222
        int x=0;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   223
        buff.append(hex6(map[x++]));
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   224
        while(x<map.length) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   225
            buff.append(" " + hex6(map[x++]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   227
        return buff.toString();
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   228
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    void setCharSource(int ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        chSource = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    void setLowerCaseMap(char[] map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        lowerCaseMap = map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    void setUpperCaseMap(char[] map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        upperCaseMap = map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    void setTitleCaseMap(char[] map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        titleCaseMap = map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    void setLocale(Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        this.locale = locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    void setContext(String[] context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        this.context = context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public int getCharSource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return chSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public char[] getLowerCaseMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return lowerCaseMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public char[] getUpperCaseMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return upperCaseMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public char[] getTitleCaseMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return titleCaseMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public String[] getContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    int chSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    Locale locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    char[] lowerCaseMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    char[] upperCaseMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    char[] titleCaseMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    String[] context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Fields that can be found in the SpecialCasing.txt file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    static int REQUIRED_FIELDS = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    static int FIELD_SOURCE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    static int FIELD_LOWERCASE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    static int FIELD_TITLECASE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    static int FIELD_UPPERCASE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    static int FIELD_CONDITIONS = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Context values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    static String CONTEXT_FINAL = "FINAL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    static String CONTEXT_NONFINAL = "NON_FINAL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    static String CONTEXT_MODERN = "MODERN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    static String CONTEXT_NONMODERN = "NON_MODERN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   304
    public int compareTo(SpecialCaseMap otherObject) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   305
        if (chSource < otherObject.chSource) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   308
        else if (chSource > otherObject.chSource) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        else return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public boolean equals(Object o1) {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   315
        if (this == o1) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   316
            return true;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   317
        }
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   318
        if (o1 == null || !(o1 instanceof SpecialCaseMap)) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   319
            return false;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   320
        }
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   321
        SpecialCaseMap other = (SpecialCaseMap)o1;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   322
        boolean bEqual = false;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   323
        if (0 == compareTo(other)) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   324
            bEqual = true;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   325
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return bEqual;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   329
    public String toString() {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   330
        StringBuffer buff = new StringBuffer();
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   331
        buff.append(hex6(getCharSource()));
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   332
        buff.append("|" + hex6(lowerCaseMap));
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   333
        buff.append("|" + hex6(upperCaseMap));
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   334
        buff.append("|" + hex6(titleCaseMap));
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   335
        buff.append("|" + context);
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   336
        return buff.toString();
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   337
    }
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   338
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   339
    public int hashCode() {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   340
        return chSource;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   341
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   343
    public static void main(String[] args) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   344
        SpecialCaseMap[] spec = null;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   345
        if (args.length == 2 ) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   346
            try {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   347
                File file = new File(args[0]);
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   348
                int plane = Integer.parseInt(args[1]);
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   349
                spec = SpecialCaseMap.readSpecFile(file, plane);
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   350
                System.out.println("SpecialCaseMap[" + spec.length + "]:");
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   351
                for (int x=0; x<spec.length; x++) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   352
                    System.out.println(spec[x].toString());
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   353
                }
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   354
            }
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   355
            catch(Exception e) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   356
                e.printStackTrace();
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   357
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   360
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
}