src/java.base/share/classes/java/text/Collator.java
author jboes
Fri, 20 Sep 2019 11:07:52 +0100
changeset 58242 94bb65cb37d3
parent 47216 71c04702a3d5
child 58288 48e480e56aad
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: 47216
diff changeset
     2
 * Copyright (c) 1997, 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-1998 -  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
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
    41
import java.lang.ref.SoftReference;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.text.spi.CollatorProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.ResourceBundle;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
    45
import java.util.concurrent.ConcurrentHashMap;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
    46
import java.util.concurrent.ConcurrentMap;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
    47
import sun.util.locale.provider.LocaleProviderAdapter;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
    48
import sun.util.locale.provider.LocaleServiceProviderPool;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The <code>Collator</code> class performs locale-sensitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <code>String</code> comparison. You use this class to build
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * searching and sorting routines for natural language text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <code>Collator</code> is an abstract base class. Subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * implement specific collation strategies. One subclass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <code>RuleBasedCollator</code>, is currently provided with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * the Java Platform and is applicable to a wide set of languages. Other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * subclasses may be created to handle more specialized needs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Like other locale-sensitive classes, you can use the static
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * factory method, <code>getInstance</code>, to obtain the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <code>Collator</code> object for a given locale. You will only need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * to look at the subclasses of <code>Collator</code> if you need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * to understand the details of a particular collation strategy or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * if you need to modify that strategy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * The following example shows how to compare two strings using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * the <code>Collator</code> for the default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <blockquote>
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13583
diff changeset
    75
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * // Compare two strings in the default locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Collator myCollator = Collator.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * if( myCollator.compare("abc", "ABC") < 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *     System.out.println("abc is less than ABC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *     System.out.println("abc is greater than or equal to ABC");
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13583
diff changeset
    82
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * You can set a <code>Collator</code>'s <em>strength</em> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * to determine the level of difference considered significant in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * comparisons. Four strengths are provided: <code>PRIMARY</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <code>SECONDARY</code>, <code>TERTIARY</code>, and <code>IDENTICAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * The exact assignment of strengths to language features is
47020
2c55106dc37b 8186851: fix misspellings of "dependent" and "independent" in the JDK repo
smarks
parents: 45434
diff changeset
    91
 * locale dependent.  For example, in Czech, "e" and "f" are considered
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * primary differences, while "e" and "&#283;" are secondary differences,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * "e" and "E" are tertiary differences and "e" and "e" are identical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * The following shows how both case and accents could be ignored for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * US English.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * //Get the Collator for US English and set its strength to PRIMARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * Collator usCollator = Collator.getInstance(Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * usCollator.setStrength(Collator.PRIMARY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * if( usCollator.compare("abc", "ABC") == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *     System.out.println("Strings are equivalent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * For comparing <code>String</code>s exactly once, the <code>compare</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * method provides the best performance. When sorting a list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <code>String</code>s however, it is generally necessary to compare each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <code>String</code> multiple times. In this case, <code>CollationKey</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * provide better performance. The <code>CollationKey</code> class converts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * a <code>String</code> to a series of bits that can be compared bitwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * against other <code>CollationKey</code>s. A <code>CollationKey</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * created by a <code>Collator</code> object for a given <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <strong>Note:</strong> <code>CollationKey</code>s from different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <code>Collator</code>s can not be compared. See the class description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * for {@link CollationKey}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * for an example using <code>CollationKey</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * @see         RuleBasedCollator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @see         CollationKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @see         CollationElementIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * @see         Locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * @author      Helena Shih, Laura Werner, Richard Gillam
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 32649
diff changeset
   126
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
public abstract class Collator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    implements java.util.Comparator<Object>, Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Collator strength value.  When set, only PRIMARY differences are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * considered significant during comparison. The assignment of strengths
47020
2c55106dc37b 8186851: fix misspellings of "dependent" and "independent" in the JDK repo
smarks
parents: 45434
diff changeset
   135
     * to language features is locale dependent. A common example is for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * different base letters ("a" vs "b") to be considered a PRIMARY difference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see java.text.Collator#setStrength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see java.text.Collator#getStrength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   140
    public static final int PRIMARY = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Collator strength value.  When set, only SECONDARY and above differences are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * considered significant during comparison. The assignment of strengths
47020
2c55106dc37b 8186851: fix misspellings of "dependent" and "independent" in the JDK repo
smarks
parents: 45434
diff changeset
   144
     * to language features is locale dependent. A common example is for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * different accented forms of the same base letter ("a" vs "\u00E4") to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * considered a SECONDARY difference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @see java.text.Collator#setStrength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see java.text.Collator#getStrength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   150
    public static final int SECONDARY = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Collator strength value.  When set, only TERTIARY and above differences are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * considered significant during comparison. The assignment of strengths
47020
2c55106dc37b 8186851: fix misspellings of "dependent" and "independent" in the JDK repo
smarks
parents: 45434
diff changeset
   154
     * to language features is locale dependent. A common example is for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * case differences ("a" vs "A") to be considered a TERTIARY difference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @see java.text.Collator#setStrength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @see java.text.Collator#getStrength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   159
    public static final int TERTIARY = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Collator strength value.  When set, all differences are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * considered significant during comparison. The assignment of strengths
47020
2c55106dc37b 8186851: fix misspellings of "dependent" and "independent" in the JDK repo
smarks
parents: 45434
diff changeset
   164
     * to language features is locale dependent. A common example is for control
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * characters ("&#092;u0001" vs "&#092;u0002") to be considered equal at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * PRIMARY, SECONDARY, and TERTIARY levels but different at the IDENTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * level.  Additionally, differences between pre-composed accents such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * "&#092;u00C0" (A-grave) and combining accents such as "A&#092;u0300"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * (A, combining-grave) will be considered significant at the IDENTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * level if decomposition is set to NO_DECOMPOSITION.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   172
    public static final int IDENTICAL = 3;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Decomposition mode value. With NO_DECOMPOSITION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * set, accented characters will not be decomposed for collation. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * is the default setting and provides the fastest collation but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * will only produce correct results for languages that do not use accents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see java.text.Collator#getDecomposition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @see java.text.Collator#setDecomposition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   182
    public static final int NO_DECOMPOSITION = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Decomposition mode value. With CANONICAL_DECOMPOSITION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * set, characters that are canonical variants according to Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * standard will be decomposed for collation. This should be used to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * correct collation of accented characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * CANONICAL_DECOMPOSITION corresponds to Normalization Form D as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * <a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Technical Report #15</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see java.text.Collator#getDecomposition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @see java.text.Collator#setDecomposition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   197
    public static final int CANONICAL_DECOMPOSITION = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Decomposition mode value. With FULL_DECOMPOSITION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * set, both Unicode canonical variants and Unicode compatibility variants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * will be decomposed for collation.  This causes not only accented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * characters to be collated, but also characters that have special formats
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * to be collated with their norminal form. For example, the half-width and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * full-width ASCII and Katakana characters are then collated together.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * FULL_DECOMPOSITION is the most complete and therefore the slowest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * decomposition mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * FULL_DECOMPOSITION corresponds to Normalization Form KD as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Technical Report #15</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @see java.text.Collator#getDecomposition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @see java.text.Collator#setDecomposition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   216
    public static final int FULL_DECOMPOSITION = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Gets the Collator for the current default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * The default locale is determined by java.util.Locale.getDefault.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @return the Collator for the default locale.(for example, en_US)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @see java.util.Locale#getDefault
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public static synchronized Collator getInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return getInstance(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Gets the Collator for the desired locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @param desiredLocale the desired locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @return the Collator for the desired locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see java.util.Locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see java.util.ResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   235
    public static Collator getInstance(Locale desiredLocale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   236
        SoftReference<Collator> ref = cache.get(desiredLocale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   237
        Collator result = (ref != null) ? ref.get() : null;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   238
        if (result == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   239
            LocaleProviderAdapter adapter;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   240
            adapter = LocaleProviderAdapter.getAdapter(CollatorProvider.class,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   241
                                                       desiredLocale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   242
            CollatorProvider provider = adapter.getCollatorProvider();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   243
            result = provider.getInstance(desiredLocale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   244
            if (result == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   245
                result = LocaleProviderAdapter.forJRE()
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   246
                             .getCollatorProvider().getInstance(desiredLocale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   247
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   248
            while (true) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   249
                if (ref != null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   250
                    // Remove the empty SoftReference if any
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   251
                    cache.remove(desiredLocale, ref);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   252
                }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   253
                ref = cache.putIfAbsent(desiredLocale, new SoftReference<>(result));
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   254
                if (ref == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   255
                    break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   256
                }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   257
                Collator cachedColl = ref.get();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   258
                if (cachedColl != null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   259
                    result = cachedColl;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   260
                    break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   261
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   264
        return (Collator) result.clone(); // make the world safe
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Compares the source string to the target string according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * collation rules for this Collator.  Returns an integer less than,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * equal to or greater than zero depending on whether the source String is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * less than, equal to or greater than the target string.  See the Collator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * class description for an example of use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * For a one time comparison, this method has the best performance. If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * given String will be involved in multiple comparisons, CollationKey.compareTo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * has the best performance. See the Collator class description for an example
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * using CollationKeys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param source the source string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param target the target string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return Returns an integer value. Value is less than zero if source is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * target, value is zero if source and target are equal, value is greater than zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * if source is greater than target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @see java.text.CollationKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @see java.text.Collator#getCollationKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public abstract int compare(String source, String target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Compares its two arguments for order.  Returns a negative integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * zero, or a positive integer as the first argument is less than, equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * to, or greater than the second.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * This implementation merely returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *  <code> compare((String)o1, (String)o2) </code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @return a negative integer, zero, or a positive integer as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *         first argument is less than, equal to, or greater than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *         second.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   299
     * @throws    ClassCastException the arguments cannot be cast to Strings.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @see java.util.Comparator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @since   1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   303
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public int compare(Object o1, Object o2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    return compare((String)o1, (String)o2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Transforms the String into a series of bits that can be compared bitwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * to other CollationKeys. CollationKeys provide better performance than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Collator.compare when Strings are involved in multiple comparisons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * See the Collator class description for an example using CollationKeys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @param source the string to be transformed into a collation key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @return the CollationKey for the given String based on this Collator's collation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * rules. If the source String is null, a null CollationKey is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @see java.text.CollationKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @see java.text.Collator#compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public abstract CollationKey getCollationKey(String source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Convenience method for comparing the equality of two strings based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * this Collator's collation rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @param source the source string to be compared with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @param target the target string to be compared with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @return true if the strings are equal according to the collation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * rules.  false, otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @see java.text.Collator#compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public boolean equals(String source, String target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return (compare(source, target) == Collator.EQUAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Returns this Collator's strength property.  The strength property determines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * the minimum level of difference considered significant during comparison.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * See the Collator class description for an example of use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @return this Collator's current strength property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @see java.text.Collator#setStrength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see java.text.Collator#PRIMARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see java.text.Collator#SECONDARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see java.text.Collator#TERTIARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see java.text.Collator#IDENTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public synchronized int getStrength()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return strength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Sets this Collator's strength property.  The strength property determines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * the minimum level of difference considered significant during comparison.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * See the Collator class description for an example of use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @param newStrength  the new strength value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @see java.text.Collator#getStrength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @see java.text.Collator#PRIMARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @see java.text.Collator#SECONDARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @see java.text.Collator#TERTIARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @see java.text.Collator#IDENTICAL
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   361
     * @throws     IllegalArgumentException If the new strength value is not one of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * PRIMARY, SECONDARY, TERTIARY or IDENTICAL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public synchronized void setStrength(int newStrength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        if ((newStrength != PRIMARY) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            (newStrength != SECONDARY) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            (newStrength != TERTIARY) &&
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   368
            (newStrength != IDENTICAL)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            throw new IllegalArgumentException("Incorrect comparison level.");
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   370
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        strength = newStrength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Get the decomposition mode of this Collator. Decomposition mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * determines how Unicode composed characters are handled. Adjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * decomposition mode allows the user to select between faster and more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * complete collation behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * <p>The three values for decomposition mode are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * <LI>NO_DECOMPOSITION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * <LI>CANONICAL_DECOMPOSITION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * <LI>FULL_DECOMPOSITION.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * See the documentation for these three constants for a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * of their meaning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @return the decomposition mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @see java.text.Collator#setDecomposition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @see java.text.Collator#NO_DECOMPOSITION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @see java.text.Collator#CANONICAL_DECOMPOSITION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @see java.text.Collator#FULL_DECOMPOSITION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public synchronized int getDecomposition()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return decmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Set the decomposition mode of this Collator. See getDecomposition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * for a description of decomposition mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @param decompositionMode  the new decomposition mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @see java.text.Collator#getDecomposition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @see java.text.Collator#NO_DECOMPOSITION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @see java.text.Collator#CANONICAL_DECOMPOSITION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see java.text.Collator#FULL_DECOMPOSITION
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   405
     * @throws    IllegalArgumentException If the given value is not a valid decomposition
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public synchronized void setDecomposition(int decompositionMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        if ((decompositionMode != NO_DECOMPOSITION) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            (decompositionMode != CANONICAL_DECOMPOSITION) &&
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   411
            (decompositionMode != FULL_DECOMPOSITION)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            throw new IllegalArgumentException("Wrong decomposition mode.");
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   413
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        decmp = decompositionMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Returns an array of all locales for which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * <code>getInstance</code> methods of this class can return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * localized instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * The returned array represents the union of locales supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * by the Java runtime and by installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * {@link java.text.spi.CollatorProvider CollatorProvider} implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * It must contain at least a Locale instance equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * {@link java.util.Locale#US Locale.US}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @return An array of locales for which localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *         <code>Collator</code> instances are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    public static synchronized Locale[] getAvailableLocales() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        LocaleServiceProviderPool pool =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            LocaleServiceProviderPool.getPool(CollatorProvider.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return pool.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * Overrides Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   439
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public Object clone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            return (Collator)super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        } catch (CloneNotSupportedException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   445
            throw new InternalError(e);
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Compares the equality of two Collators.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @param that the Collator to be compared with this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @return true if this Collator is the same as that Collator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   455
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public boolean equals(Object that)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   458
        if (this == that) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   459
            return true;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   460
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   461
        if (that == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   462
            return false;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   463
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   464
        if (getClass() != that.getClass()) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   465
            return false;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   466
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        Collator other = (Collator) that;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return ((strength == other.strength) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                (decmp == other.decmp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * Generates the hash code for this Collator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   475
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   476
    public abstract int hashCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * Default constructor.  This constructor is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * protected so subclasses can get access to it. Users typically create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * a Collator sub-class by calling the factory method getInstance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @see java.text.Collator#getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    protected Collator()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        strength = TERTIARY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        decmp = CANONICAL_DECOMPOSITION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    private int strength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    private int decmp = 0;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   492
    private static final ConcurrentMap<Locale, SoftReference<Collator>> cache
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 10419
diff changeset
   493
            = new ConcurrentHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    // FIXME: These three constants should be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * LESS is returned if source string is compared to be less than target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * string in the compare() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @see java.text.Collator#compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   503
    static final int LESS = -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * EQUAL is returned if source string is compared to be equal to target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * string in the compare() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @see java.text.Collator#compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   509
    static final int EQUAL = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * GREATER is returned if source string is compared to be greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * target string in the compare() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @see java.text.Collator#compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   515
    static final int GREATER = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
 }