src/java.base/share/classes/java/text/RBTableBuilder.java
author jboes
Fri, 20 Sep 2019 11:07:52 +0100
changeset 58242 94bb65cb37d3
parent 53018 8bf9268df0e2
permissions -rw-r--r--
8230648: Replace @exception tag with @throws in java.base Summary: Minor coding style update of javadoc tag in any file in java.base Reviewed-by: prappo, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 53018
diff changeset
     2
 * Copyright (c) 1999, 2019, 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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996-1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *   The original version of this source code and documentation is copyrighted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * materials are provided under terms of a License Agreement between Taligent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * and Sun. This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * patents. This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
package java.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.text.UCompactIntArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.text.IntHashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.text.ComposedCharIter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.text.CollatorUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.text.normalizer.NormalizerImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * This class contains all the code to parse a RuleBasedCollator pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * and build a RBCollationTables object from it.  A particular instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * of tis class exists only during the actual build process-- once an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * RBCollationTables object has been built, the RBTableBuilder object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * goes away.  This object carries all of the state which is only needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * during the build process, plus a "shadow" copy of all of the state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * that will go into the tables object itself.  This object communicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * with RBCollationTables through a separate class, RBCollationTables.BuildAPI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * this is an inner class of RBCollationTables and provides a separate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * private API for communication with RBTableBuilder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * This class isn't just an inner class of RBCollationTables itself because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * of its large size.  For source-code readability, it seemed better for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * builder to have its own source file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
final class RBTableBuilder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public RBTableBuilder(RBCollationTables.BuildAPI tables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this.tables = tables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Create a table-based collation object with the given rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * This is the main function that actually builds the tables and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * stores them back in the RBCollationTables object.  It is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * ONLY by the RBCollationTables constructor.
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 12848
diff changeset
    74
     * @see RuleBasedCollator#RuleBasedCollator
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 53018
diff changeset
    75
     * @throws    ParseException If the rules format is incorrect.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
    78
    public void build(String pattern, int decmp) throws ParseException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        String expChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        String groupChars;
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
    81
        if (pattern.isEmpty())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            throw new ParseException("Build rules empty.", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        // This array maps Unicode characters to their collation ordering
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
    85
        mapping = new UCompactIntArray(RBCollationTables.UNMAPPED);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // Normalize the build rules.  Find occurances of all decomposed characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // and normalize the rules before feeding into the builder.  By "normalize",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // we mean that all precomposed Unicode characters must be converted into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // a base character and one or more combining characters (such as accents).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        // When there are multiple combining characters attached to a base character,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        // the combining characters must be in their canonical order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // sherman/Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        //(1)decmp will be NO_DECOMPOSITION only in ko locale to prevent decompose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        //hangual syllables to jamos, so we can actually just call decompose with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        //normalizer's IGNORE_HANGUL option turned on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        //(2)just call the "special version" in NormalizerImpl directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        //pattern = Normalizer.decompose(pattern, false, Normalizer.IGNORE_HANGUL, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        //Normalizer.Mode mode = CollatorUtilities.toNormalizerMode(decmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        //pattern = Normalizer.normalize(pattern, mode, 0, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        pattern = NormalizerImpl.canonicalDecomposeWithSingleQuotation(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        // Build the merged collation entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // Since rules can be specified in any order in the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // (e.g. "c , C < d , D < e , E .... C < CH")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // this splits all of the rules in the string out into separate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // objects and then sorts them.  In the above example, it merges the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // "C < CH" rule in just before the "C < D" rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        mPattern = new MergeCollation(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        int order = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        // Now walk though each entry and add it to my own tables
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   119
        for (int i = 0; i < mPattern.getCount(); ++i) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            PatternEntry entry = mPattern.getItemAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if (entry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                groupChars = entry.getChars();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                if (groupChars.length() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    switch(groupChars.charAt(groupChars.length()-1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    case '@':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                        frenchSec = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                        groupChars = groupChars.substring(0, groupChars.length()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    case '!':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                        seAsianSwapping = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                        groupChars = groupChars.substring(0, groupChars.length()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                order = increment(entry.getStrength(), order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                expChars = entry.getExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   139
                if (!expChars.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    addExpandOrder(groupChars, expChars, order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                } else if (groupChars.length() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    char ch = groupChars.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    if (Character.isHighSurrogate(ch) && groupChars.length() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                        addOrder(Character.toCodePoint(ch, groupChars.charAt(1)), order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                        addContractOrder(groupChars, order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    char ch = groupChars.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    addOrder(ch, order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        addComposedChars();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        commit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        mapping.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        System.out.println("mappingSize=" + mapping.getKSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        for (int j = 0; j < 0xffff; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            int value = mapping.elementAt(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if (value != RBCollationTables.UNMAPPED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                System.out.println("index=" + Integer.toString(j, 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                           + ", value=" + Integer.toString(value, 16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        tables.fillInTables(frenchSec, seAsianSwapping, mapping, contractTable, expandTable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    contractFlags, maxSecOrder, maxTerOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /** Add expanding entries for pre-composed unicode characters so that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * collator can be used reasonably well with decomposition turned off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    private void addComposedChars() throws ParseException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // Iterate through all of the pre-composed characters in Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        ComposedCharIter iter = new ComposedCharIter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        while ((c = iter.next()) != ComposedCharIter.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (getCharOrder(c) == RBCollationTables.UNMAPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                // We don't already have an ordering for this pre-composed character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                // First, see if the decomposed string is already in our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                // tables as a single contracting-string ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                // If so, just map the precomposed character to that order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                // TODO: What we should really be doing here is trying to find the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                // longest initial substring of the decomposition that is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                // in the tables as a contracting character sequence, and find its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                // ordering.  Then do this recursively with the remaining chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                // so that we build a list of orderings, and add that list to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                // the expansion table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                // That would be more correct but also significantly slower, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                // I'm not totally sure it's worth doing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                String s = iter.decomposition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                //sherman/Note: if this is 1 character decomposed string, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                //only thing need to do is to check if this decomposed character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                //has an entry in our order table, this order is not necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                //to be a contraction order, if it does have one, add an entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                //for the precomposed character by using the same order, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                //previous impl unnecessarily adds a single character expansion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                //entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                if (s.length() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    int order = getCharOrder(s.charAt(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    if (order != RBCollationTables.UNMAPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        addOrder(c, order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                } else if (s.length() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    char ch0 = s.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    if (Character.isHighSurrogate(ch0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        int order = getCharOrder(s.codePointAt(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        if (order != RBCollationTables.UNMAPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                            addOrder(c, order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                int contractOrder = getContractOrder(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                if (contractOrder != RBCollationTables.UNMAPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    addOrder(c, contractOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    // We don't have a contracting ordering for the entire string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    // that results from the decomposition, but if we have orders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    // for each individual character, we can add an expanding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    // table entry for the pre-composed character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    boolean allThere = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    for (int i = 0; i < s.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        if (getCharOrder(s.charAt(i)) == RBCollationTables.UNMAPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                            allThere = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    if (allThere) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        addExpandOrder(c, s, RBCollationTables.UNMAPPED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Look up for unmapped values in the expanded character table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * When the expanding character tables are built by addExpandOrder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * it doesn't know what the final ordering of each character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * in the expansion will be.  Instead, it just puts the raw character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * code into the table, adding CHARINDEX as a flag.  Now that we've
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * finished building the mapping table, we can go back and look up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * that character to see what its real collation order is and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * stick that into the expansion table.  That lets us avoid doing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * a two-stage lookup later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    private final void commit()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (expandTable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            for (int i = 0; i < expandTable.size(); i++) {
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   262
                int[] valueList = expandTable.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                for (int j = 0; j < valueList.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    int order = valueList[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    if (order < RBCollationTables.EXPANDCHARINDEX && order > CHARINDEX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        // found a expanding character that isn't filled in yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                        int ch = order - CHARINDEX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        // Get the real values for the non-filled entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                        int realValue = getCharOrder(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                        if (realValue == RBCollationTables.UNMAPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                            // The real value is still unmapped, maybe it's ignorable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                            valueList[j] = IGNORABLEMASK & ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                            // just fill in the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                            valueList[j] = realValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *  Increment of the last order based on the comparison level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    private final int increment(int aStrength, int lastValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        switch(aStrength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        case Collator.PRIMARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            // increment priamry order  and mask off secondary and tertiary difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            lastValue += PRIMARYORDERINCREMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            lastValue &= RBCollationTables.PRIMARYORDERMASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            isOverIgnore = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        case Collator.SECONDARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            // increment secondary order and mask off tertiary difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            lastValue += SECONDARYORDERINCREMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            lastValue &= RBCollationTables.SECONDARYDIFFERENCEONLY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            // record max # of ignorable chars with secondary difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (!isOverIgnore)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                maxSecOrder++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        case Collator.TERTIARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            // increment tertiary order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            lastValue += TERTIARYORDERINCREMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            // record max # of ignorable chars with tertiary difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            if (!isOverIgnore)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                maxTerOrder++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return lastValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *  Adds a character and its designated order into the collation table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    private final void addOrder(int ch, int anOrder)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        // See if the char already has an order in the mapping table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        int order = mapping.elementAt(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        if (order >= RBCollationTables.CONTRACTCHARINDEX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            // There's already an entry for this character that points to a contracting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            // character table.  Instead of adding the character directly to the mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            // table, we must add it to the contract table instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            int length = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            if (Character.isSupplementaryCodePoint(ch)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                length = Character.toChars(ch, keyBuf, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                keyBuf[0] = (char)ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            addContractOrder(new String(keyBuf, 0, length), anOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            // add the entry to the mapping table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            // the same later entry replaces the previous one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            mapping.setElementAt(ch, anOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    private final void addContractOrder(String groupChars, int anOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        addContractOrder(groupChars, anOrder, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *  Adds the contracting string into the collation table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    private final void addContractOrder(String groupChars, int anOrder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                          boolean fwd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (contractTable == null) {
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   353
            contractTable = new Vector<>(INITIALTABLESIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        //initial character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        int ch = groupChars.codePointAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        char ch0 = groupChars.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        int ch = Character.isHighSurrogate(ch0)?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
          Character.toCodePoint(ch0, groupChars.charAt(1)):ch0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        // See if the initial character of the string already has a contract table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        int entry = mapping.elementAt(ch);
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   365
        Vector<EntryPair> entryTable = getContractValuesImpl(entry - RBCollationTables.CONTRACTCHARINDEX);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (entryTable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            // We need to create a new table of contract entries for this base char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            int tableIndex = RBCollationTables.CONTRACTCHARINDEX + contractTable.size();
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   370
            entryTable = new Vector<>(INITIALTABLESIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            contractTable.addElement(entryTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            // Add the initial character's current ordering first. then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            // update its mapping to point to this contract table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            entryTable.addElement(new EntryPair(groupChars.substring(0,Character.charCount(ch)), entry));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            mapping.setElementAt(ch, tableIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        // Now add (or replace) this string in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        int index = RBCollationTables.getEntry(entryTable, groupChars, fwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (index != RBCollationTables.UNMAPPED) {
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   382
            EntryPair pair = entryTable.elementAt(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            pair.value = anOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        } else {
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   385
            EntryPair pair = entryTable.lastElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            // NOTE:  This little bit of logic is here to speed CollationElementIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            // .nextContractChar().  This code ensures that the longest sequence in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            // this list is always the _last_ one in the list.  This keeps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            // nextContractChar() from having to search the entire list for the longest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            // sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            if (groupChars.length() > pair.entryName.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                entryTable.addElement(new EntryPair(groupChars, anOrder, fwd));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                entryTable.insertElementAt(new EntryPair(groupChars, anOrder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                        fwd), entryTable.size() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        // If this was a forward mapping for a contracting string, also add a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        // reverse mapping for it, so that CollationElementIterator.previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        // can work right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (fwd && groupChars.length() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            addContractFlags(groupChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            addContractOrder(new StringBuffer(groupChars).reverse().toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                             anOrder, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * If the given string has been specified as a contracting string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * in this collation table, return its ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Otherwise return UNMAPPED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    private int getContractOrder(String groupChars)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        int result = RBCollationTables.UNMAPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        if (contractTable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            int ch = groupChars.codePointAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            char ch0 = groupChars.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            int ch = Character.isHighSurrogate(ch0)?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
              Character.toCodePoint(ch0, groupChars.charAt(1)):ch0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
              */
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   425
            Vector<EntryPair> entryTable = getContractValues(ch);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            if (entryTable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                int index = RBCollationTables.getEntry(entryTable, groupChars, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                if (index != RBCollationTables.UNMAPPED) {
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   429
                    EntryPair pair = entryTable.elementAt(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    result = pair.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    private final int getCharOrder(int ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        int order = mapping.elementAt(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (order >= RBCollationTables.CONTRACTCHARINDEX) {
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   441
            Vector<EntryPair> groupList = getContractValuesImpl(order - RBCollationTables.CONTRACTCHARINDEX);
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   442
            EntryPair pair = groupList.firstElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            order = pair.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        return order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *  Get the entry of hash table of the contracting string in the collation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *  table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *  @param ch the starting character of the contracting string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   453
    private Vector<EntryPair> getContractValues(int ch)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        int index = mapping.elementAt(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        return getContractValuesImpl(index - RBCollationTables.CONTRACTCHARINDEX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   459
    private Vector<EntryPair> getContractValuesImpl(int index)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (index >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        {
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   463
            return contractTable.elementAt(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        else // not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *  Adds the expanding string into the collation table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    private final void addExpandOrder(String contractChars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                                String expandChars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                                int anOrder) throws ParseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        // Create an expansion table entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        int tableIndex = addExpansion(anOrder, expandChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        // And add its index into the main mapping table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (contractChars.length() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            char ch = contractChars.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            if (Character.isHighSurrogate(ch) && contractChars.length() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                char ch2 = contractChars.charAt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                if (Character.isLowSurrogate(ch2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    //only add into table when it is a legal surrogate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    addOrder(Character.toCodePoint(ch, ch2), tableIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                addContractOrder(contractChars, tableIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            addOrder(contractChars.charAt(0), tableIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    private final void addExpandOrder(int ch, String expandChars, int anOrder)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
      throws ParseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        int tableIndex = addExpansion(anOrder, expandChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        addOrder(ch, tableIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Create a new entry in the expansion table that contains the orderings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * for the given characers.  If anOrder is valid, it is added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * beginning of the expanded list of orders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    private int addExpansion(int anOrder, String expandChars) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        if (expandTable == null) {
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   512
            expandTable = new Vector<>(INITIALTABLESIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        // If anOrder is valid, we want to add it at the beginning of the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        int offset = (anOrder == RBCollationTables.UNMAPPED) ? 0 : 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        int[] valueList = new int[expandChars.length() + offset];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (offset == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            valueList[0] = anOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        int j = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        for (int i = 0; i < expandChars.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            char ch0 = expandChars.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            char ch1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            int ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            if (Character.isHighSurrogate(ch0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                if (++i == expandChars.length() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    !Character.isLowSurrogate(ch1=expandChars.charAt(i))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    //ether we are missing the low surrogate or the next char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    //is not a legal low surrogate, so stop loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                ch = Character.toCodePoint(ch0, ch1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                ch = ch0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            int mapValue = getCharOrder(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            if (mapValue != RBCollationTables.UNMAPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                valueList[j++] = mapValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                // can't find it in the table, will be filled in by commit().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                valueList[j++] = CHARINDEX + ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (j < valueList.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            //we had at least one supplementary character, the size of valueList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            //is bigger than it really needs...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            int[] tmpBuf = new int[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            while (--j >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                tmpBuf[j] = valueList[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            valueList = tmpBuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        // Add the expanding char list into the expansion table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        int tableIndex = RBCollationTables.EXPANDCHARINDEX + expandTable.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        expandTable.addElement(valueList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        return tableIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    private void addContractFlags(String chars) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        char c0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        int len = chars.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            c0 = chars.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            c = Character.isHighSurrogate(c0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                          ?Character.toCodePoint(c0, chars.charAt(++i))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                          :c0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            contractFlags.put(c, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    // ==============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    // constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    // ==============================================================
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   582
    static final int CHARINDEX = 0x70000000;  // need look up in .commit()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   584
    private static final int IGNORABLEMASK = 0x0000ffff;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   585
    private static final int PRIMARYORDERINCREMENT = 0x00010000;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   586
    private static final int SECONDARYORDERINCREMENT = 0x00000100;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   587
    private static final int TERTIARYORDERINCREMENT = 0x00000001;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   588
    private static final int INITIALTABLESIZE = 20;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   589
    private static final int MAXKEYSIZE = 5;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    // ==============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    // instance variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    // ==============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    // variables used by the build process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    private RBCollationTables.BuildAPI tables = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    private MergeCollation mPattern = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    private boolean isOverIgnore = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    private char[] keyBuf = new char[MAXKEYSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    private IntHashtable contractFlags = new IntHashtable(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    // "shadow" copies of the instance variables in RBCollationTables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    // (the values in these variables are copied back into RBCollationTables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    // at the end of the build process)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    private boolean frenchSec = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    private boolean seAsianSwapping = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    private UCompactIntArray mapping = null;
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   609
    private Vector<Vector<EntryPair>>   contractTable = null;
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 5506
diff changeset
   610
    private Vector<int[]>   expandTable = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    private short maxSecOrder = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    private short maxTerOrder = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
}