src/share/classes/java/text/Collator.java

Print this page
rev 5615 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o Jigsaw. by Naoto Sato and Masayoshi Okutsu)
   1 /*
   2  * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * (C) Copyright Taligent, Inc. 1996-1998 -  All Rights Reserved
  28  * (C) Copyright IBM Corp. 1996-1998 - All Rights Reserved
  29  *
  30  *   The original version of this source code and documentation is copyrighted
  31  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  32  * materials are provided under terms of a License Agreement between Taligent
  33  * and Sun. This technology is protected by multiple US and International
  34  * patents. This notice and attribution to Taligent may not be removed.
  35  *   Taligent is a registered trademark of Taligent, Inc.
  36  *
  37  */
  38 
  39 package java.text;
  40 

  41 import java.text.spi.CollatorProvider;
  42 import java.util.Locale;
  43 import java.util.MissingResourceException;
  44 import java.util.ResourceBundle;
  45 import java.util.spi.LocaleServiceProvider;
  46 import sun.misc.SoftCache;
  47 import sun.util.resources.LocaleData;
  48 import sun.util.LocaleServiceProviderPool;
  49 
  50 
  51 /**
  52  * The <code>Collator</code> class performs locale-sensitive
  53  * <code>String</code> comparison. You use this class to build
  54  * searching and sorting routines for natural language text.
  55  *
  56  * <p>
  57  * <code>Collator</code> is an abstract base class. Subclasses
  58  * implement specific collation strategies. One subclass,
  59  * <code>RuleBasedCollator</code>, is currently provided with
  60  * the Java Platform and is applicable to a wide set of languages. Other
  61  * subclasses may be created to handle more specialized needs.
  62  *
  63  * <p>
  64  * Like other locale-sensitive classes, you can use the static
  65  * factory method, <code>getInstance</code>, to obtain the appropriate
  66  * <code>Collator</code> object for a given locale. You will only need
  67  * to look at the subclasses of <code>Collator</code> if you need
  68  * to understand the details of a particular collation strategy or


 214      */
 215     public final static int FULL_DECOMPOSITION = 2;
 216 
 217     /**
 218      * Gets the Collator for the current default locale.
 219      * The default locale is determined by java.util.Locale.getDefault.
 220      * @return the Collator for the default locale.(for example, en_US)
 221      * @see java.util.Locale#getDefault
 222      */
 223     public static synchronized Collator getInstance() {
 224         return getInstance(Locale.getDefault());
 225     }
 226 
 227     /**
 228      * Gets the Collator for the desired locale.
 229      * @param desiredLocale the desired locale.
 230      * @return the Collator for the desired locale.
 231      * @see java.util.Locale
 232      * @see java.util.ResourceBundle
 233      */
 234     public static synchronized
 235     Collator getInstance(Locale desiredLocale)
 236     {
 237         Collator result = (Collator) cache.get(desiredLocale);
 238         if (result != null) {
 239                  return (Collator)result.clone();  // make the world safe
 240         }
 241 
 242         // Check whether a provider can provide an implementation that's closer
 243         // to the requested locale than what the Java runtime itself can provide.
 244         LocaleServiceProviderPool pool =
 245             LocaleServiceProviderPool.getPool(CollatorProvider.class);
 246         if (pool.hasProviders()) {
 247             Collator providersInstance = pool.getLocalizedObject(
 248                                             CollatorGetter.INSTANCE,
 249                                             desiredLocale,
 250                                             desiredLocale);
 251             if (providersInstance != null) {
 252                 return providersInstance;




 253             }



 254         }
 255 
 256         // Load the resource of the desired locale from resource
 257         // manager.
 258         String colString = "";
 259         try {
 260             ResourceBundle resource = LocaleData.getCollationData(desiredLocale);
 261 
 262             colString = resource.getString("Rule");
 263         } catch (MissingResourceException e) {
 264             // Use default values
 265         }
 266         try
 267         {
 268             result = new RuleBasedCollator( CollationRules.DEFAULTRULES +
 269                                             colString,
 270                                             CANONICAL_DECOMPOSITION );
 271         }
 272         catch(ParseException foo)
 273         {
 274             // predefined tables should contain correct grammar
 275             try {
 276                 result = new RuleBasedCollator( CollationRules.DEFAULTRULES );
 277             } catch (ParseException bar) {
 278                 // do nothing
 279             }




 280         }
 281         // Now that RuleBasedCollator adds expansions for pre-composed characters
 282         // into their decomposed equivalents, the default collators don't need
 283         // to have decomposition turned on.  Laura, 5/5/98, bug 4114077
 284         result.setDecomposition(NO_DECOMPOSITION);
 285 
 286         cache.put(desiredLocale,result);
 287         return (Collator)result.clone();
 288     }



 289 
 290     /**
 291      * Compares the source string to the target string according to the
 292      * collation rules for this Collator.  Returns an integer less than,
 293      * equal to or greater than zero depending on whether the source String is
 294      * less than, equal to or greater than the target string.  See the Collator
 295      * class description for an example of use.
 296      * <p>
 297      * For a one time comparison, this method has the best performance. If a
 298      * given String will be involved in multiple comparisons, CollationKey.compareTo
 299      * has the best performance. See the Collator class description for an example
 300      * using CollationKeys.
 301      * @param source the source string.
 302      * @param target the target string.
 303      * @return Returns an integer value. Value is less than zero if source is less than
 304      * target, value is zero if source and target are equal, value is greater than zero
 305      * if source is greater than target.
 306      * @see java.text.CollationKey
 307      * @see java.text.Collator#getCollationKey
 308      */
 309     public abstract int compare(String source, String target);
 310 
 311     /**
 312      * Compares its two arguments for order.  Returns a negative integer,
 313      * zero, or a positive integer as the first argument is less than, equal
 314      * to, or greater than the second.
 315      * <p>
 316      * This implementation merely returns
 317      *  <code> compare((String)o1, (String)o2) </code>.
 318      *
 319      * @return a negative integer, zero, or a positive integer as the
 320      *         first argument is less than, equal to, or greater than the
 321      *         second.
 322      * @exception ClassCastException the arguments cannot be cast to Strings.
 323      * @see java.util.Comparator
 324      * @since   1.2
 325      */

 326     public int compare(Object o1, Object o2) {
 327     return compare((String)o1, (String)o2);
 328     }
 329 
 330     /**
 331      * Transforms the String into a series of bits that can be compared bitwise
 332      * to other CollationKeys. CollationKeys provide better performance than
 333      * Collator.compare when Strings are involved in multiple comparisons.
 334      * See the Collator class description for an example using CollationKeys.
 335      * @param source the string to be transformed into a collation key.
 336      * @return the CollationKey for the given String based on this Collator's collation
 337      * rules. If the source String is null, a null CollationKey is returned.
 338      * @see java.text.CollationKey
 339      * @see java.text.Collator#compare
 340      */
 341     public abstract CollationKey getCollationKey(String source);
 342 
 343     /**
 344      * Convenience method for comparing the equality of two strings based on
 345      * this Collator's collation rules.


 370         return strength;
 371     }
 372 
 373     /**
 374      * Sets this Collator's strength property.  The strength property determines
 375      * the minimum level of difference considered significant during comparison.
 376      * See the Collator class description for an example of use.
 377      * @param newStrength  the new strength value.
 378      * @see java.text.Collator#getStrength
 379      * @see java.text.Collator#PRIMARY
 380      * @see java.text.Collator#SECONDARY
 381      * @see java.text.Collator#TERTIARY
 382      * @see java.text.Collator#IDENTICAL
 383      * @exception  IllegalArgumentException If the new strength value is not one of
 384      * PRIMARY, SECONDARY, TERTIARY or IDENTICAL.
 385      */
 386     public synchronized void setStrength(int newStrength) {
 387         if ((newStrength != PRIMARY) &&
 388             (newStrength != SECONDARY) &&
 389             (newStrength != TERTIARY) &&
 390             (newStrength != IDENTICAL))
 391             throw new IllegalArgumentException("Incorrect comparison level.");

 392         strength = newStrength;
 393     }
 394 
 395     /**
 396      * Get the decomposition mode of this Collator. Decomposition mode
 397      * determines how Unicode composed characters are handled. Adjusting
 398      * decomposition mode allows the user to select between faster and more
 399      * complete collation behavior.
 400      * <p>The three values for decomposition mode are:
 401      * <UL>
 402      * <LI>NO_DECOMPOSITION,
 403      * <LI>CANONICAL_DECOMPOSITION
 404      * <LI>FULL_DECOMPOSITION.
 405      * </UL>
 406      * See the documentation for these three constants for a description
 407      * of their meaning.
 408      * @return the decomposition mode
 409      * @see java.text.Collator#setDecomposition
 410      * @see java.text.Collator#NO_DECOMPOSITION
 411      * @see java.text.Collator#CANONICAL_DECOMPOSITION
 412      * @see java.text.Collator#FULL_DECOMPOSITION
 413      */
 414     public synchronized int getDecomposition()
 415     {
 416         return decmp;
 417     }
 418     /**
 419      * Set the decomposition mode of this Collator. See getDecomposition
 420      * for a description of decomposition mode.
 421      * @param decompositionMode  the new decomposition mode.
 422      * @see java.text.Collator#getDecomposition
 423      * @see java.text.Collator#NO_DECOMPOSITION
 424      * @see java.text.Collator#CANONICAL_DECOMPOSITION
 425      * @see java.text.Collator#FULL_DECOMPOSITION
 426      * @exception IllegalArgumentException If the given value is not a valid decomposition
 427      * mode.
 428      */
 429     public synchronized void setDecomposition(int decompositionMode) {
 430         if ((decompositionMode != NO_DECOMPOSITION) &&
 431             (decompositionMode != CANONICAL_DECOMPOSITION) &&
 432             (decompositionMode != FULL_DECOMPOSITION))
 433             throw new IllegalArgumentException("Wrong decomposition mode.");

 434         decmp = decompositionMode;
 435     }
 436 
 437     /**
 438      * Returns an array of all locales for which the
 439      * <code>getInstance</code> methods of this class can return
 440      * localized instances.
 441      * The returned array represents the union of locales supported
 442      * by the Java runtime and by installed
 443      * {@link java.text.spi.CollatorProvider CollatorProvider} implementations.
 444      * It must contain at least a Locale instance equal to
 445      * {@link java.util.Locale#US Locale.US}.
 446      *
 447      * @return An array of locales for which localized
 448      *         <code>Collator</code> instances are available.
 449      */
 450     public static synchronized Locale[] getAvailableLocales() {
 451         LocaleServiceProviderPool pool =
 452             LocaleServiceProviderPool.getPool(CollatorProvider.class);
 453         return pool.getAvailableLocales();
 454     }
 455 
 456     /**
 457      * Overrides Cloneable
 458      */

 459     public Object clone()
 460     {
 461         try {
 462             return (Collator)super.clone();
 463         } catch (CloneNotSupportedException e) {
 464             throw new InternalError(e);
 465         }
 466     }
 467 
 468     /**
 469      * Compares the equality of two Collators.
 470      * @param that the Collator to be compared with this.
 471      * @return true if this Collator is the same as that Collator;
 472      * false otherwise.
 473      */

 474     public boolean equals(Object that)
 475     {
 476         if (this == that) return true;
 477         if (that == null) return false;
 478         if (getClass() != that.getClass()) return false;






 479         Collator other = (Collator) that;
 480         return ((strength == other.strength) &&
 481                 (decmp == other.decmp));
 482     }
 483 
 484     /**
 485      * Generates the hash code for this Collator.
 486      */

 487     abstract public int hashCode();
 488 
 489     /**
 490      * Default constructor.  This constructor is
 491      * protected so subclasses can get access to it. Users typically create
 492      * a Collator sub-class by calling the factory method getInstance.
 493      * @see java.text.Collator#getInstance
 494      */
 495     protected Collator()
 496     {
 497         strength = TERTIARY;
 498         decmp = CANONICAL_DECOMPOSITION;
 499     }
 500 
 501     private int strength = 0;
 502     private int decmp = 0;
 503     private static SoftCache cache = new SoftCache();

 504 
 505     //
 506     // FIXME: These three constants should be removed.
 507     //
 508     /**
 509      * LESS is returned if source string is compared to be less than target
 510      * string in the compare() method.
 511      * @see java.text.Collator#compare
 512      */
 513     final static int LESS = -1;
 514     /**
 515      * EQUAL is returned if source string is compared to be equal to target
 516      * string in the compare() method.
 517      * @see java.text.Collator#compare
 518      */
 519     final static int EQUAL = 0;
 520     /**
 521      * GREATER is returned if source string is compared to be greater than
 522      * target string in the compare() method.
 523      * @see java.text.Collator#compare
 524      */
 525     final static int GREATER = 1;
 526 
 527     /**
 528      * Obtains a Collator instance from a CollatorProvider
 529      * implementation.
 530      */
 531     private static class CollatorGetter
 532         implements LocaleServiceProviderPool.LocalizedObjectGetter<CollatorProvider, Collator> {
 533         private static final CollatorGetter INSTANCE = new CollatorGetter();
 534 
 535         public Collator getObject(CollatorProvider collatorProvider,
 536                                 Locale locale,
 537                                 String key,
 538                                 Object... params) {
 539             assert params.length == 1;
 540             Collator result = collatorProvider.getInstance(locale);
 541             if (result != null) {
 542                 // put this Collator instance in the cache for two locales, one
 543                 // is for the desired locale, and the other is for the actual
 544                 // locale where the provider is found, which may be a fall back locale.
 545                 cache.put((Locale)params[0], result);
 546                 cache.put(locale, result);
 547                 return (Collator)result.clone();
 548             }
 549 
 550             return null;
 551         }
 552     }
 553  }
   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * (C) Copyright Taligent, Inc. 1996-1998 -  All Rights Reserved
  28  * (C) Copyright IBM Corp. 1996-1998 - All Rights Reserved
  29  *
  30  *   The original version of this source code and documentation is copyrighted
  31  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  32  * materials are provided under terms of a License Agreement between Taligent
  33  * and Sun. This technology is protected by multiple US and International
  34  * patents. This notice and attribution to Taligent may not be removed.
  35  *   Taligent is a registered trademark of Taligent, Inc.
  36  *
  37  */
  38 
  39 package java.text;
  40 
  41 import java.lang.ref.SoftReference;
  42 import java.text.spi.CollatorProvider;
  43 import java.util.Locale;

  44 import java.util.ResourceBundle;
  45 import java.util.concurrent.ConcurrentHashMap;
  46 import java.util.concurrent.ConcurrentMap;
  47 import sun.util.locale.provider.LocaleProviderAdapter;
  48 import sun.util.locale.provider.LocaleServiceProviderPool;
  49 
  50 
  51 /**
  52  * The <code>Collator</code> class performs locale-sensitive
  53  * <code>String</code> comparison. You use this class to build
  54  * searching and sorting routines for natural language text.
  55  *
  56  * <p>
  57  * <code>Collator</code> is an abstract base class. Subclasses
  58  * implement specific collation strategies. One subclass,
  59  * <code>RuleBasedCollator</code>, is currently provided with
  60  * the Java Platform and is applicable to a wide set of languages. Other
  61  * subclasses may be created to handle more specialized needs.
  62  *
  63  * <p>
  64  * Like other locale-sensitive classes, you can use the static
  65  * factory method, <code>getInstance</code>, to obtain the appropriate
  66  * <code>Collator</code> object for a given locale. You will only need
  67  * to look at the subclasses of <code>Collator</code> if you need
  68  * to understand the details of a particular collation strategy or


 214      */
 215     public final static int FULL_DECOMPOSITION = 2;
 216 
 217     /**
 218      * Gets the Collator for the current default locale.
 219      * The default locale is determined by java.util.Locale.getDefault.
 220      * @return the Collator for the default locale.(for example, en_US)
 221      * @see java.util.Locale#getDefault
 222      */
 223     public static synchronized Collator getInstance() {
 224         return getInstance(Locale.getDefault());
 225     }
 226 
 227     /**
 228      * Gets the Collator for the desired locale.
 229      * @param desiredLocale the desired locale.
 230      * @return the Collator for the desired locale.
 231      * @see java.util.Locale
 232      * @see java.util.ResourceBundle
 233      */
 234     public static Collator getInstance(Locale desiredLocale) {
 235         SoftReference<Collator> ref = cache.get(desiredLocale);
 236         Collator result = (ref != null) ? ref.get() : null;
 237         if (result == null) {
 238             LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(CollatorProvider.class,











 239                                                                      desiredLocale);
 240             CollatorProvider provider = adapter.getCollatorProvider();
 241             result = provider.getInstance(desiredLocale);
 242             if (result == null) {
 243                 if (adapter.getAdapterType() != LocaleProviderAdapter.Type.JRE) {
 244                     result = LocaleProviderAdapter.forJRE()
 245                              .getCollatorProvider().getInstance(desiredLocale);
 246                 }
 247                 if (result == null) {
 248                     throw new InternalError("Collator instance creation failed. (provider="
 249                                            + provider + ")");
 250             }










 251             }
 252             while (true) {
 253                 if (ref != null) {
 254                     // Remove the empty SoftReference if any
 255                     cache.remove(desiredLocale, ref);

 256                 }
 257                 ref = cache.putIfAbsent(desiredLocale, new SoftReference<>(result));
 258                 if (ref == null) {
 259                     break;




 260                 }
 261                 Collator cachedColl = ref.get();
 262                 if (cachedColl != null) {
 263                     result = cachedColl;
 264                     break;
 265                 }







 266             }
 267         }
 268         return (Collator) result.clone(); // make the world safe
 269     }
 270 
 271     /**
 272      * Compares the source string to the target string according to the
 273      * collation rules for this Collator.  Returns an integer less than,
 274      * equal to or greater than zero depending on whether the source String is
 275      * less than, equal to or greater than the target string.  See the Collator
 276      * class description for an example of use.
 277      * <p>
 278      * For a one time comparison, this method has the best performance. If a
 279      * given String will be involved in multiple comparisons, CollationKey.compareTo
 280      * has the best performance. See the Collator class description for an example
 281      * using CollationKeys.
 282      * @param source the source string.
 283      * @param target the target string.
 284      * @return Returns an integer value. Value is less than zero if source is less than
 285      * target, value is zero if source and target are equal, value is greater than zero
 286      * if source is greater than target.
 287      * @see java.text.CollationKey
 288      * @see java.text.Collator#getCollationKey
 289      */
 290     public abstract int compare(String source, String target);
 291 
 292     /**
 293      * Compares its two arguments for order.  Returns a negative integer,
 294      * zero, or a positive integer as the first argument is less than, equal
 295      * to, or greater than the second.
 296      * <p>
 297      * This implementation merely returns
 298      *  <code> compare((String)o1, (String)o2) </code>.
 299      *
 300      * @return a negative integer, zero, or a positive integer as the
 301      *         first argument is less than, equal to, or greater than the
 302      *         second.
 303      * @exception ClassCastException the arguments cannot be cast to Strings.
 304      * @see java.util.Comparator
 305      * @since   1.2
 306      */
 307     @Override
 308     public int compare(Object o1, Object o2) {
 309     return compare((String)o1, (String)o2);
 310     }
 311 
 312     /**
 313      * Transforms the String into a series of bits that can be compared bitwise
 314      * to other CollationKeys. CollationKeys provide better performance than
 315      * Collator.compare when Strings are involved in multiple comparisons.
 316      * See the Collator class description for an example using CollationKeys.
 317      * @param source the string to be transformed into a collation key.
 318      * @return the CollationKey for the given String based on this Collator's collation
 319      * rules. If the source String is null, a null CollationKey is returned.
 320      * @see java.text.CollationKey
 321      * @see java.text.Collator#compare
 322      */
 323     public abstract CollationKey getCollationKey(String source);
 324 
 325     /**
 326      * Convenience method for comparing the equality of two strings based on
 327      * this Collator's collation rules.


 352         return strength;
 353     }
 354 
 355     /**
 356      * Sets this Collator's strength property.  The strength property determines
 357      * the minimum level of difference considered significant during comparison.
 358      * See the Collator class description for an example of use.
 359      * @param newStrength  the new strength value.
 360      * @see java.text.Collator#getStrength
 361      * @see java.text.Collator#PRIMARY
 362      * @see java.text.Collator#SECONDARY
 363      * @see java.text.Collator#TERTIARY
 364      * @see java.text.Collator#IDENTICAL
 365      * @exception  IllegalArgumentException If the new strength value is not one of
 366      * PRIMARY, SECONDARY, TERTIARY or IDENTICAL.
 367      */
 368     public synchronized void setStrength(int newStrength) {
 369         if ((newStrength != PRIMARY) &&
 370             (newStrength != SECONDARY) &&
 371             (newStrength != TERTIARY) &&
 372             (newStrength != IDENTICAL)) {
 373             throw new IllegalArgumentException("Incorrect comparison level.");
 374         }
 375         strength = newStrength;
 376     }
 377 
 378     /**
 379      * Get the decomposition mode of this Collator. Decomposition mode
 380      * determines how Unicode composed characters are handled. Adjusting
 381      * decomposition mode allows the user to select between faster and more
 382      * complete collation behavior.
 383      * <p>The three values for decomposition mode are:
 384      * <UL>
 385      * <LI>NO_DECOMPOSITION,
 386      * <LI>CANONICAL_DECOMPOSITION
 387      * <LI>FULL_DECOMPOSITION.
 388      * </UL>
 389      * See the documentation for these three constants for a description
 390      * of their meaning.
 391      * @return the decomposition mode
 392      * @see java.text.Collator#setDecomposition
 393      * @see java.text.Collator#NO_DECOMPOSITION
 394      * @see java.text.Collator#CANONICAL_DECOMPOSITION
 395      * @see java.text.Collator#FULL_DECOMPOSITION
 396      */
 397     public synchronized int getDecomposition()
 398     {
 399         return decmp;
 400     }
 401     /**
 402      * Set the decomposition mode of this Collator. See getDecomposition
 403      * for a description of decomposition mode.
 404      * @param decompositionMode  the new decomposition mode.
 405      * @see java.text.Collator#getDecomposition
 406      * @see java.text.Collator#NO_DECOMPOSITION
 407      * @see java.text.Collator#CANONICAL_DECOMPOSITION
 408      * @see java.text.Collator#FULL_DECOMPOSITION
 409      * @exception IllegalArgumentException If the given value is not a valid decomposition
 410      * mode.
 411      */
 412     public synchronized void setDecomposition(int decompositionMode) {
 413         if ((decompositionMode != NO_DECOMPOSITION) &&
 414             (decompositionMode != CANONICAL_DECOMPOSITION) &&
 415             (decompositionMode != FULL_DECOMPOSITION)) {
 416             throw new IllegalArgumentException("Wrong decomposition mode.");
 417         }
 418         decmp = decompositionMode;
 419     }
 420 
 421     /**
 422      * Returns an array of all locales for which the
 423      * <code>getInstance</code> methods of this class can return
 424      * localized instances.
 425      * The returned array represents the union of locales supported
 426      * by the Java runtime and by installed
 427      * {@link java.text.spi.CollatorProvider CollatorProvider} implementations.
 428      * It must contain at least a Locale instance equal to
 429      * {@link java.util.Locale#US Locale.US}.
 430      *
 431      * @return An array of locales for which localized
 432      *         <code>Collator</code> instances are available.
 433      */
 434     public static synchronized Locale[] getAvailableLocales() {
 435         LocaleServiceProviderPool pool =
 436             LocaleServiceProviderPool.getPool(CollatorProvider.class);
 437         return pool.getAvailableLocales();
 438     }
 439 
 440     /**
 441      * Overrides Cloneable
 442      */
 443     @Override
 444     public Object clone()
 445     {
 446         try {
 447             return (Collator)super.clone();
 448         } catch (CloneNotSupportedException e) {
 449             throw new InternalError(e);
 450         }
 451     }
 452 
 453     /**
 454      * Compares the equality of two Collators.
 455      * @param that the Collator to be compared with this.
 456      * @return true if this Collator is the same as that Collator;
 457      * false otherwise.
 458      */
 459     @Override
 460     public boolean equals(Object that)
 461     {
 462         if (this == that) {
 463             return true;
 464         }
 465         if (that == null) {
 466             return false;
 467         }
 468         if (getClass() != that.getClass()) {
 469             return false;
 470         }
 471         Collator other = (Collator) that;
 472         return ((strength == other.strength) &&
 473                 (decmp == other.decmp));
 474     }
 475 
 476     /**
 477      * Generates the hash code for this Collator.
 478      */
 479     @Override
 480     abstract public int hashCode();
 481 
 482     /**
 483      * Default constructor.  This constructor is
 484      * protected so subclasses can get access to it. Users typically create
 485      * a Collator sub-class by calling the factory method getInstance.
 486      * @see java.text.Collator#getInstance
 487      */
 488     protected Collator()
 489     {
 490         strength = TERTIARY;
 491         decmp = CANONICAL_DECOMPOSITION;
 492     }
 493 
 494     private int strength = 0;
 495     private int decmp = 0;
 496     private static final ConcurrentMap<Locale, SoftReference<Collator>> cache
 497             = new ConcurrentHashMap<>();
 498 
 499     //
 500     // FIXME: These three constants should be removed.
 501     //
 502     /**
 503      * LESS is returned if source string is compared to be less than target
 504      * string in the compare() method.
 505      * @see java.text.Collator#compare
 506      */
 507     final static int LESS = -1;
 508     /**
 509      * EQUAL is returned if source string is compared to be equal to target
 510      * string in the compare() method.
 511      * @see java.text.Collator#compare
 512      */
 513     final static int EQUAL = 0;
 514     /**
 515      * GREATER is returned if source string is compared to be greater than
 516      * target string in the compare() method.
 517      * @see java.text.Collator#compare
 518      */
 519     final static int GREATER = 1;



























 520  }