12ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/* GENERATED SOURCE. DO NOT MODIFY. */ 2f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// © 2016 and later: Unicode, Inc. and others. 3f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html#License 42ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/** 52ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller******************************************************************************* 6bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin* Copyright (C) 1996-2016, International Business Machines Corporation and 72ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* others. All Rights Reserved. 82ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller******************************************************************************* 92ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller*/ 102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpackage android.icu.text; 112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.util.Comparator; 132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.util.LinkedList; 142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.util.Locale; 152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.util.MissingResourceException; 162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.util.Set; 172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 18f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubertimport android.icu.impl.ICUData; 192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.impl.ICUDebug; 202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.impl.ICUResourceBundle; 21f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubertimport android.icu.impl.UResource; 222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.impl.coll.CollationData; 232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.impl.coll.CollationRoot; 242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.lang.UCharacter; 252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.lang.UProperty; 262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.lang.UScript; 272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.util.Freezable; 282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.util.ICUException; 292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.util.ULocale; 302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.util.ULocale.Category; 312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.util.UResourceBundle; 322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.util.VersionInfo; 332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/** 351537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller* <strong>[icu enhancement]</strong> ICU's replacement for {@link java.text.Collator}. Methods, fields, and other functionality specific to ICU are labeled '<strong>[icu]</strong>'. 362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* 372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <p>Collator performs locale-sensitive string comparison. A concrete 382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* subclass, RuleBasedCollator, allows customization of the collation 39bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin* ordering by the use of rule sets. 402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* 415cf9d333bc032f332a812665fc8a9824765f01c9Fredrik Roubert* <p>A Collator is thread-safe only when frozen. See {@link #isFrozen()} and {@link Freezable}. 422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* 432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <p>Following the <a href=http://www.unicode.org>Unicode 442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Consortium</a>'s specifications for the 452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <a href="http://www.unicode.org/unicode/reports/tr10/">Unicode Collation 462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Algorithm (UCA)</a>, there are 5 different levels of strength used 472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* in comparisons: 482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* 492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <ul> 502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <li>PRIMARY strength: Typically, this is used to denote differences between 512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* base characters (for example, "a" < "b"). 522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* It is the strongest difference. For example, dictionaries are divided 532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* into different sections by base character. 542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <li>SECONDARY strength: Accents in the characters are considered secondary 552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* differences (for example, "as" < "às" < "at"). Other 562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* differences 572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* between letters can also be considered secondary differences, depending 582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* on the language. A secondary difference is ignored when there is a 592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* primary difference anywhere in the strings. 602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <li>TERTIARY strength: Upper and lower case differences in characters are 612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* distinguished at tertiary strength (for example, "ao" < "Ao" < 622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* "aò"). In addition, a variant of a letter differs from the base 6387a901bc03907f93227b639419364ac8befe9930Fredrik Roubert* form on the tertiary strength (such as "A" and "Ⓐ"). Another 642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* example is the 652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* difference between large and small Kana. A tertiary difference is ignored 662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* when there is a primary or secondary difference anywhere in the strings. 672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <li>QUATERNARY strength: When punctuation is ignored 682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* (see <a href="http://userguide.icu-project.org/collation/concepts#TOC-Ignoring-Punctuation"> 692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Ignoring Punctuations in the User Guide</a>) at PRIMARY to TERTIARY 702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* strength, an additional strength level can 712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* be used to distinguish words with and without punctuation (for example, 722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* "ab" < "a-b" < "aB"). 732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* This difference is ignored when there is a PRIMARY, SECONDARY or TERTIARY 742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* difference. The QUATERNARY strength should only be used if ignoring 752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* punctuation is required. 762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <li>IDENTICAL strength: 772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* When all other strengths are equal, the IDENTICAL strength is used as a 782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* tiebreaker. The Unicode code point values of the NFD form of each string 792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* are compared, just in case there is no difference. 802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* For example, Hebrew cantellation marks are only distinguished at this 812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* strength. This strength should be used sparingly, as only code point 822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* value differences between two strings is an extremely rare occurrence. 832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Using this strength substantially decreases the performance for both 842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* comparison and collation key generation APIs. This strength also 852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* increases the size of the collation key. 862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* </ul> 872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* 882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Unlike the JDK, ICU4J's Collator deals only with 2 decomposition modes, 892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* the canonical decomposition mode and one that does not use any decomposition. 902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* The compatibility decomposition mode, java.text.Collator.FULL_DECOMPOSITION 912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* is not supported here. If the canonical 922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* decomposition mode is set, the Collator handles un-normalized text properly, 932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* producing the same results as if the text were normalized in NFD. If 942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* canonical decomposition is turned off, it is the user's responsibility to 952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* ensure that all text is already in the appropriate form before performing 96bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin* a comparison or before getting a CollationKey. 972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* 982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <p>For more information about the collation service see the 99bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin* <a href="http://userguide.icu-project.org/collation">User Guide</a>. 1002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* 1012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <p>Examples of use 1022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* <pre> 1032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* // Get the Collator for US English and set its strength to PRIMARY 1042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Collator usCollator = Collator.getInstance(Locale.US); 1052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* usCollator.setStrength(Collator.PRIMARY); 1062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* if (usCollator.compare("abc", "ABC") == 0) { 1072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* System.out.println("Strings are equivalent"); 1082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* } 1092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* 1102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* The following example shows how to compare two strings using the 1112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Collator for the default locale. 1122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* 1132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* // Compare two strings in the default locale 1142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Collator myCollator = Collator.getInstance(); 1152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* myCollator.setDecomposition(NO_DECOMPOSITION); 1162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* if (myCollator.compare("à\u0325", "a\u0325̀") != 0) { 1172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* System.out.println("à\u0325 is not equals to a\u0325̀ without decomposition"); 1182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* myCollator.setDecomposition(CANONICAL_DECOMPOSITION); 1192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* if (myCollator.compare("à\u0325", "a\u0325̀") != 0) { 1202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* System.out.println("Error: à\u0325 should be equals to a\u0325̀ with decomposition"); 1212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* } 1222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* else { 1232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* System.out.println("à\u0325 is equals to a\u0325̀ with decomposition"); 1242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* } 1252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* } 1262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* else { 1272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* System.out.println("Error: à\u0325 should be not equals to a\u0325̀ without decomposition"); 1282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* } 1292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* </pre> 130bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin* 1312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* @see RuleBasedCollator 1322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* @see CollationKey 1332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* @author Syn Wee Quek 1342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller*/ 1352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpublic abstract class Collator implements Comparator<Object>, Freezable<Collator>, Cloneable 1362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller{ 1372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // public data members --------------------------------------------------- 1382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Strongest collator strength value. Typically used to denote differences 1412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * between base characters. See class documentation for more explanation. 1422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setStrength 1432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getStrength 1442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int PRIMARY = 0; 1462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Second level collator strength value. 1492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Accents in the characters are considered secondary differences. 1502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Other differences between letters can also be considered secondary 1512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * differences, depending on the language. 1522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * See class documentation for more explanation. 1532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setStrength 1542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getStrength 1552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int SECONDARY = 1; 1572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Third level collator strength value. 1602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Upper and lower case differences in characters are distinguished at this 1612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * strength level. In addition, a variant of a letter differs from the base 1622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * form on the tertiary level. 1632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * See class documentation for more explanation. 1642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setStrength 1652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getStrength 1662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int TERTIARY = 2; 1682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1701537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Fourth level collator strength value. 1712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * When punctuation is ignored 1722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * (see <a href="http://userguide.icu-project.org/collation/concepts#TOC-Ignoring-Punctuation"> 1732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Ignoring Punctuation in the User Guide</a>) at PRIMARY to TERTIARY 1742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * strength, an additional strength level can 1752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * be used to distinguish words with and without punctuation. 1762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * See class documentation for more explanation. 1772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setStrength 1782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getStrength 1792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int QUATERNARY = 3; 1812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Smallest Collator strength value. When all other strengths are equal, 1842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the IDENTICAL strength is used as a tiebreaker. The Unicode code point 1852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * values of the NFD form of each string are compared, just in case there 1862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * is no difference. 1872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * See class documentation for more explanation. 1882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p> 1892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Note this value is different from JDK's 1902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int IDENTICAL = 15; 1922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1941537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu] Note:</strong> This is for backwards compatibility with Java APIs only. It 1952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * should not be used, IDENTICAL should be used instead. ICU's 1962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * collation does not support Java's FULL_DECOMPOSITION mode. 1972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int FULL_DECOMPOSITION = IDENTICAL; 1992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Decomposition mode value. With NO_DECOMPOSITION set, Strings 2022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * will not be decomposed for collation. This is the default 2032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * decomposition setting unless otherwise specified by the locale 204bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * used to create the Collator. 2052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 206bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * <p><strong>Note</strong> this value is different from the JDK's. 2072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #CANONICAL_DECOMPOSITION 2082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getDecomposition 2092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setDecomposition 2102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int NO_DECOMPOSITION = 16; 2122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Decomposition mode value. With CANONICAL_DECOMPOSITION set, 2152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * characters that are canonical variants according to the Unicode standard 216bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * will be decomposed for collation. 2172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 2182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>CANONICAL_DECOMPOSITION corresponds to Normalization Form D as 2192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * described in <a href="http://www.unicode.org/unicode/reports/tr15/"> 2202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Unicode Technical Report #15</a>. 221bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * 2222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #NO_DECOMPOSITION 2232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getDecomposition 2242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setDecomposition 2252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int CANONICAL_DECOMPOSITION = 17; 2272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Reordering codes for non-script groups that can be reordered under collation. 230f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * 2312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getReorderCodes 2322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setReorderCodes 2332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getEquivalentReorderCodes 2342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static interface ReorderCodes { 2362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * A special reordering code that is used to specify the default reordering codes for a locale. 2382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int DEFAULT = -1; // == UScript.INVALID_CODE 2402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * A special reordering code that is used to specify no reordering codes. 2422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int NONE = UScript.UNKNOWN; 2442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 245f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * A special reordering code that is used to specify all other codes used for reordering except 2462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for the codes listed as ReorderingCodes and those listed explicitly in a reordering. 2472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int OTHERS = UScript.UNKNOWN; 2492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Characters with the space property. 2512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This is equivalent to the rule value "space". 2522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int SPACE = 0x1000; 2542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The first entry in the enumeration of reordering groups. This is intended for use in 2562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * range checking and enumeration of the reorder codes. 2572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int FIRST = SPACE; 2592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Characters with the punctuation property. 2612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This is equivalent to the rule value "punct". 2622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int PUNCTUATION = 0x1001; 2642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Characters with the symbol property. 2662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This is equivalent to the rule value "symbol". 2672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int SYMBOL = 0x1002; 2692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Characters with the currency property. 2712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This is equivalent to the rule value "currency". 2722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int CURRENCY = 0x1003; 2742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Characters with the digit property. 2762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This is equivalent to the rule value "digit". 2772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final static int DIGIT = 0x1004; 2792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 280f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * One more than the highest normal ReorderCodes value. 281f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 2829e940603a29cf07f50ffda6201b0b1b202459035Paul Duffin * @hide unsupported on Android 2832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 284f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Deprecated 285f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert public final static int LIMIT = 0x1005; 2862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 287f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert 2882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // public methods -------------------------------------------------------- 2892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Compares the equality of two Collator objects. Collator objects are equal if they have the same 292bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * collation (sorting & searching) behavior. 2932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 2942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The base class checks for null and for equal types. 2952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Subclasses should override. 2962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 2972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param obj the Collator to compare to. 2982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return true if this Collator has exactly the same collation behavior as obj, false otherwise. 2992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Override 3012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public boolean equals(Object obj) { 3022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Subclasses: Call this method and then add more specific checks. 3032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return this == obj || (obj != null && getClass() == obj.getClass()); 3042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 306f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert /** 307f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * Generates a hash code for this Collator object. 308f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * 309f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * <p>The implementation exists just for consistency with {@link #equals(Object)} 310f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * implementation in this class and does not generate a useful hash code. 311f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * Subclasses should override this implementation. 312f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * 313f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * @return a hash code value. 314f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert */ 315f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Override 316f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert public int hashCode() { 317f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert // Dummy return to prevent compile warnings. 318f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert return 0; 319f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert } 320f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert 3212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // public setters -------------------------------------------------------- 3222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 3232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private void checkNotFrozen() { 3242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (isFrozen()) { 3252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new UnsupportedOperationException("Attempt to modify frozen Collator"); 3262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 3292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 3302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Sets this Collator's strength attribute. The strength attribute 3312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * determines the minimum level of difference considered significant 332bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * during comparison. 3332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 3342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The base class method does nothing. Subclasses should override it if appropriate. 3352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 336bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * <p>See the Collator class description for an example of use. 3372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param newStrength the new strength value. 3382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getStrength 3392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #PRIMARY 3402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #SECONDARY 3412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #TERTIARY 3422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #QUATERNARY 3432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #IDENTICAL 3442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws IllegalArgumentException if the new strength value is not valid. 3452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public void setStrength(int newStrength) 3472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 3482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller checkNotFrozen(); 3492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 3512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 3522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return this, for chaining 3532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 35493cf604e9dd0525f15bc0a7450b2a35f3884c298Neil Fuller * @hide original deprecated declaration 355836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 3562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 3582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public Collator setStrength2(int newStrength) 3592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 3602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller setStrength(newStrength); 3612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return this; 3622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 3642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 3652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Sets the decomposition mode of this Collator. Setting this 3662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * decomposition attribute with CANONICAL_DECOMPOSITION allows the 3672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Collator to handle un-normalized text properly, producing the 3682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * same results as if the text were normalized. If 3692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * NO_DECOMPOSITION is set, it is the user's responsibility to 3702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * insure that all text is already in the appropriate form before 3712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * a comparison or before getting a CollationKey. Adjusting 3722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * decomposition mode allows the user to select between faster and 373bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * more complete collation behavior. 3742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 3752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>Since a great many of the world's languages do not require 3762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * text normalization, most locales set NO_DECOMPOSITION as the 377bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * default decomposition mode. 3782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 3792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The base class method does nothing. Subclasses should override it if appropriate. 3802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 3812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>See getDecomposition for a description of decomposition 382bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * mode. 3832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 3842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param decomposition the new decomposition mode 3852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getDecomposition 3862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #NO_DECOMPOSITION 3872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #CANONICAL_DECOMPOSITION 3882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws IllegalArgumentException If the given value is not a valid 3892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * decomposition mode. 3902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public void setDecomposition(int decomposition) 3922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 3932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller checkNotFrozen(); 3942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 396f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert /** 3972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Sets the reordering codes for this collator. 3982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Collation reordering allows scripts and some other groups of characters 3992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * to be moved relative to each other. This reordering is done on top of 400f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * the DUCET/CLDR standard collation order. Reordering can specify groups to be placed 4012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * at the start and/or the end of the collation order. These groups are specified using 4022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * UScript codes and {@link Collator.ReorderCodes} entries. 4032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 404f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * <p>By default, reordering codes specified for the start of the order are placed in the 405f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * order given after several special non-script blocks. These special groups of characters 4062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * are space, punctuation, symbol, currency, and digit. These special groups are represented with 4072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * {@link Collator.ReorderCodes} entries. Script groups can be intermingled with 4082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * these special non-script groups if those special groups are explicitly specified in the reordering. 4092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 4102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The special code {@link Collator.ReorderCodes#OTHERS OTHERS} 4112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * stands for any script that is not explicitly 4122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * mentioned in the list of reordering codes given. Anything that is after OTHERS 4132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * will go at the very end of the reordering in the order given. 4142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 4152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The special reorder code {@link Collator.ReorderCodes#DEFAULT DEFAULT} 4162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * will reset the reordering for this collator 4172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * to the default for this collator. The default reordering may be the DUCET/CLDR order or may be a reordering that 418f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * was specified when this collator was created from resource data or from rules. The 4192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * DEFAULT code <b>must</b> be the sole code supplied when it is used. 4202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * If not, then an {@link IllegalArgumentException} will be thrown. 4212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 4222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The special reorder code {@link Collator.ReorderCodes#NONE NONE} 4232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * will remove any reordering for this collator. 424f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * The result of setting no reordering will be to have the DUCET/CLDR ordering used. The 4252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * NONE code <b>must</b> be the sole code supplied when it is used. 4262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 4272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param order the reordering codes to apply to this collator; if this is null or an empty array 4282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * then this clears any existing reordering 4292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getReorderCodes 4302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getEquivalentReorderCodes 4312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see Collator.ReorderCodes 4322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see UScript 433f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert */ 434f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert public void setReorderCodes(int... order) 435f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert { 436f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert throw new UnsupportedOperationException("Needs to be implemented by the subclass."); 437f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert } 4382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // public getters -------------------------------------------------------- 4402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns the Collator for the current default locale. 4432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The default locale is determined by java.util.Locale.getDefault(). 4442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the Collator for the default locale (for example, en_US) if it 4452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * is created successfully. Otherwise if there is no Collator 4462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * associated with the current locale, the root collator 4472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * will be returned. 4482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see java.util.Locale#getDefault() 4492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getInstance(Locale) 4502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final Collator getInstance() 4522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 4532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getInstance(ULocale.getDefault()); 4542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 4552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Clones the collator. 4582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return a clone of this collator. 4592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 460f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Override 4612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public Object clone() throws CloneNotSupportedException { 4622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return super.clone(); 4632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 4642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // begin registry stuff 4662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * A factory used with registerFactory to register multiple collators and provide 4692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * display names for them. If standard locale display names are sufficient, 4702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Collator instances may be registered instead. 4712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p><b>Note:</b> as of ICU4J 3.2, the default API for CollatorFactory uses 4722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * ULocale instead of Locale. Instead of overriding createCollator(Locale), 4732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * new implementations should override createCollator(ULocale). Note that 4742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * one of these two methods <b>MUST</b> be overridden or else an infinite 4752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * loop will occur. 476ee0f20f8e03a1df95ced34550ed1b0ee06238ecaNeil Fuller * @hide unsupported on Android 4772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static abstract class CollatorFactory { 4792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Return true if this factory will be visible. Default is true. 4812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * If not visible, the locales supported by this factory will not 4822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * be listed by getAvailableLocales. 4832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 4842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return true if this factory is visible 4852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public boolean visible() { 4872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return true; 4882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 4892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Return an instance of the appropriate collator. If the locale 4922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * is not supported, return null. 4932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <b>Note:</b> as of ICU4J 3.2, implementations should override 4942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * this method instead of createCollator(Locale). 4952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param loc the locale for which this collator is to be created. 4962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the newly created collator. 4972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public Collator createCollator(ULocale loc) { 4992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return createCollator(loc.toLocale()); 5002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Return an instance of the appropriate collator. If the locale 5042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * is not supported, return null. 5052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p><b>Note:</b> as of ICU4J 3.2, implementations should override 5062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * createCollator(ULocale) instead of this method, and inherit this 5072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * method's implementation. This method is no longer abstract 5082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * and instead delegates to createCollator(ULocale). 5092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param loc the locale for which this collator is to be created. 5102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the newly created collator. 5112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public Collator createCollator(Locale loc) { 5132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return createCollator(ULocale.forLocale(loc)); 5142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Return the name of the collator for the objectLocale, localized for the displayLocale. 5182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * If objectLocale is not visible or not defined by the factory, return null. 5192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param objectLocale the locale identifying the collator 5202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param displayLocale the locale for which the display name of the collator should be localized 5212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the display name 5222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public String getDisplayName(Locale objectLocale, Locale displayLocale) { 5242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getDisplayName(ULocale.forLocale(objectLocale), ULocale.forLocale(displayLocale)); 5252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Return the name of the collator for the objectLocale, localized for the displayLocale. 5292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * If objectLocale is not visible or not defined by the factory, return null. 5302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param objectLocale the locale identifying the collator 5312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param displayLocale the locale for which the display name of the collator should be localized 5322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the display name 5332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public String getDisplayName(ULocale objectLocale, ULocale displayLocale) { 5352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (visible()) { 5362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller Set<String> supported = getSupportedLocaleIDs(); 5372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller String name = objectLocale.getBaseName(); 5382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (supported.contains(name)) { 5392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return objectLocale.getDisplayName(displayLocale); 5402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return null; 5432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Return an unmodifiable collection of the locale names directly 5472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * supported by this factory. 5482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 5492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the set of supported locale IDs. 5502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract Set<String> getSupportedLocaleIDs(); 5522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Empty default constructor. 5552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller protected CollatorFactory() { 5572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller static abstract class ServiceShim { 5612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller abstract Collator getInstance(ULocale l); 5622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller abstract Object registerInstance(Collator c, ULocale l); 5632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller abstract Object registerFactory(CollatorFactory f); 5642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller abstract boolean unregister(Object k); 5652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller abstract Locale[] getAvailableLocales(); // TODO remove 5662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller abstract ULocale[] getAvailableULocales(); 5672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller abstract String getDisplayName(ULocale ol, ULocale dl); 5682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static ServiceShim shim; 5712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static ServiceShim getShim() { 5722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Note: this instantiation is safe on loose-memory-model configurations 5732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // despite lack of synchronization, since the shim instance has no state-- 5742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // it's all in the class init. The worst problem is we might instantiate 5752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // two shim instances, but they'll share the same state so that's ok. 5762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (shim == null) { 5772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller try { 5782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller Class<?> cls = Class.forName("android.icu.text.CollatorServiceShim"); 5792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller shim = (ServiceShim)cls.newInstance(); 5802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller catch (MissingResourceException e) 5822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 5832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:OFF 5842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw e; 5852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:ON 5862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller catch (Exception e) { 5882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:OFF 5892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if(DEBUG){ 5902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller e.printStackTrace(); 5912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new ICUException(e); 5932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:ON 5942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return shim; 5972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 6002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Simpler/faster methods for ASCII than ones based on Unicode data. 6012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * TODO: There should be code like this somewhere already?? 6022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 6032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static final class ASCII { 6042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller static boolean equalIgnoreCase(CharSequence left, CharSequence right) { 6052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int length = left.length(); 6062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (length != right.length()) { return false; } 6072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller for (int i = 0; i < length; ++i) { 6082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller char lc = left.charAt(i); 6092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller char rc = right.charAt(i); 6102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (lc == rc) { continue; } 6112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if ('A' <= lc && lc <= 'Z') { 6122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if ((lc + 0x20) == rc) { continue; } 6132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } else if ('A' <= rc && rc <= 'Z') { 6142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if ((rc + 0x20) == lc) { continue; } 6152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return false; 6172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return true; 6192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static final boolean getYesOrNo(String keyword, String s) { 6232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (ASCII.equalIgnoreCase(s, "yes")) { 6242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return true; 6252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (ASCII.equalIgnoreCase(s, "no")) { 6272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return false; 6282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new IllegalArgumentException("illegal locale keyword=value: " + keyword + "=" + s); 6302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static final int getIntValue(String keyword, String s, String... values) { 6332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller for (int i = 0; i < values.length; ++i) { 6342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (ASCII.equalIgnoreCase(s, values[i])) { 6352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return i; 6362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new IllegalArgumentException("illegal locale keyword=value: " + keyword + "=" + s); 6392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static final int getReorderCode(String keyword, String s) { 6422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return Collator.ReorderCodes.FIRST + 6432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller getIntValue(keyword, s, "space", "punct", "symbol", "currency", "digit"); 6442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Not supporting "others" = UCOL_REORDER_CODE_OTHERS 6452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // as a synonym for Zzzz = USCRIPT_UNKNOWN for now: 6462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Avoid introducing synonyms/aliases. 6472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 6502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Sets collation attributes according to locale keywords. See 6512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * http://www.unicode.org/reports/tr35/tr35-collation.html#Collation_Settings 6522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 6532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Using "alias" keywords and values where defined: 6542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * http://www.unicode.org/reports/tr35/tr35.html#Old_Locale_Extension_Syntax 6552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * http://unicode.org/repos/cldr/trunk/common/bcp47/collation.xml 6562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 6572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static void setAttributesFromKeywords(ULocale loc, Collator coll, RuleBasedCollator rbc) { 6582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Check for collation keywords that were already deprecated 6592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // before any were supported in createInstance() (except for "collation"). 6602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller String value = loc.getKeywordValue("colHiraganaQuaternary"); 6612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (value != null) { 6622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new UnsupportedOperationException("locale keyword kh/colHiraganaQuaternary"); 6632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller value = loc.getKeywordValue("variableTop"); 6652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (value != null) { 6662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new UnsupportedOperationException("locale keyword vt/variableTop"); 6672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Parse known collation keywords, ignore others. 6692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller value = loc.getKeywordValue("colStrength"); 6702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (value != null) { 6712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Note: Not supporting typo "quarternary" because it was never supported in locale IDs. 6722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int strength = getIntValue("colStrength", value, 6732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller "primary", "secondary", "tertiary", "quaternary", "identical"); 6742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller coll.setStrength(strength <= Collator.QUATERNARY ? strength : Collator.IDENTICAL); 6752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller value = loc.getKeywordValue("colBackwards"); 6772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (value != null) { 6782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (rbc != null) { 6792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller rbc.setFrenchCollation(getYesOrNo("colBackwards", value)); 6802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } else { 6812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new UnsupportedOperationException( 6822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller "locale keyword kb/colBackwards only settable for RuleBasedCollator"); 6832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller value = loc.getKeywordValue("colCaseLevel"); 6862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (value != null) { 6872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (rbc != null) { 6882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller rbc.setCaseLevel(getYesOrNo("colCaseLevel", value)); 6892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } else { 6902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new UnsupportedOperationException( 6912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller "locale keyword kb/colBackwards only settable for RuleBasedCollator"); 6922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller value = loc.getKeywordValue("colCaseFirst"); 6952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (value != null) { 6962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (rbc != null) { 6972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int cf = getIntValue("colCaseFirst", value, "no", "lower", "upper"); 6982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (cf == 0) { 6992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller rbc.setLowerCaseFirst(false); 7002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller rbc.setUpperCaseFirst(false); 7012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } else if (cf == 1) { 7022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller rbc.setLowerCaseFirst(true); 7032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } else /* cf == 2 */ { 7042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller rbc.setUpperCaseFirst(true); 7052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } else { 7072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new UnsupportedOperationException( 7082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller "locale keyword kf/colCaseFirst only settable for RuleBasedCollator"); 7092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller value = loc.getKeywordValue("colAlternate"); 7122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (value != null) { 7132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (rbc != null) { 7142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller rbc.setAlternateHandlingShifted( 7152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller getIntValue("colAlternate", value, "non-ignorable", "shifted") != 0); 7162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } else { 7172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new UnsupportedOperationException( 7182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller "locale keyword ka/colAlternate only settable for RuleBasedCollator"); 7192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller value = loc.getKeywordValue("colNormalization"); 7222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (value != null) { 7232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller coll.setDecomposition(getYesOrNo("colNormalization", value) ? 7242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller Collator.CANONICAL_DECOMPOSITION : Collator.NO_DECOMPOSITION); 7252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller value = loc.getKeywordValue("colNumeric"); 7272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (value != null) { 7282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (rbc != null) { 7292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller rbc.setNumericCollation(getYesOrNo("colNumeric", value)); 7302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } else { 7312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new UnsupportedOperationException( 7322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller "locale keyword kn/colNumeric only settable for RuleBasedCollator"); 7332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller value = loc.getKeywordValue("colReorder"); 7362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (value != null) { 7372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int[] codes = new int[UScript.CODE_LIMIT + Collator.ReorderCodes.LIMIT - Collator.ReorderCodes.FIRST]; 7382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int codesLength = 0; 7392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int scriptNameStart = 0; 7402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller for (;;) { 7412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (codesLength == codes.length) { 7422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new IllegalArgumentException( 7432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller "too many script codes for colReorder locale keyword: " + value); 7442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int limit = scriptNameStart; 7462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller while (limit < value.length() && value.charAt(limit) != '-') { ++limit; } 7472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller String scriptName = value.substring(scriptNameStart, limit); 7482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int code; 7492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (scriptName.length() == 4) { 7502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Strict parsing, accept only 4-letter script codes, not long names. 7512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller code = UCharacter.getPropertyValueEnum(UProperty.SCRIPT, scriptName); 7522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } else { 7532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller code = getReorderCode("colReorder", scriptName); 7542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller codes[codesLength++] = code; 7562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (limit == value.length()) { break; } 7572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller scriptNameStart = limit + 1; 7582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (codesLength == 0) { 7602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new IllegalArgumentException("no script codes for colReorder locale keyword"); 7612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int[] args = new int[codesLength]; 7632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller System.arraycopy(codes, 0, args, 0, codesLength); 7642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller coll.setReorderCodes(args); 7652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller value = loc.getKeywordValue("kv"); 7672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (value != null) { 7682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller coll.setMaxVariable(getReorderCode("kv", value)); 7692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 7722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 7731537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the Collator for the desired locale. 7742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 7752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>For some languages, multiple collation types are available; 7762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for example, "de@collation=phonebook". 7772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Starting with ICU 54, collation attributes can be specified via locale keywords as well, 7782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * in the old locale extension syntax ("el@colCaseFirst=upper") 7792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * or in language tag syntax ("el-u-kf-upper"). 7802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * See <a href="http://userguide.icu-project.org/collation/api">User Guide: Collation API</a>. 7812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 7822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param locale the desired locale. 7832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return Collator for the desired locale if it is created successfully. 7842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Otherwise if there is no Collator 7852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * associated with the current locale, the root collator will 7862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * be returned. 7872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see java.util.Locale 7882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see java.util.ResourceBundle 7892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getInstance(Locale) 7902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getInstance() 7912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 7922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final Collator getInstance(ULocale locale) { 7932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // fetching from service cache is faster than instantiation 7942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (locale == null) { 7952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller locale = ULocale.getDefault(); 7962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller Collator coll = getShim().getInstance(locale); 7982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (!locale.getName().equals(locale.getBaseName())) { // any keywords? 7992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller setAttributesFromKeywords(locale, coll, 8002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller (coll instanceof RuleBasedCollator) ? (RuleBasedCollator)coll : null); 8012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return coll; 8032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 8062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns the Collator for the desired locale. 8072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 8082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>For some languages, multiple collation types are available; 8092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for example, "de-u-co-phonebk". 8102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Starting with ICU 54, collation attributes can be specified via locale keywords as well, 8112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * in the old locale extension syntax ("el@colCaseFirst=upper", only with {@link ULocale}) 8122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * or in language tag syntax ("el-u-kf-upper"). 8132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * See <a href="http://userguide.icu-project.org/collation/api">User Guide: Collation API</a>. 8142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 8152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param locale the desired locale. 8162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return Collator for the desired locale if it is created successfully. 8172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Otherwise if there is no Collator 8182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * associated with the current locale, the root collator will 8192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * be returned. 8202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see java.util.Locale 8212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see java.util.ResourceBundle 8222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getInstance(ULocale) 8232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getInstance() 8242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 8252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final Collator getInstance(Locale locale) { 8262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getInstance(ULocale.forLocale(locale)); 8272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 8301537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Registers a collator as the default collator for the provided locale. The 8312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * collator should not be modified after it is registered. 8322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 8332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>Because ICU may choose to cache Collator objects internally, this must 8342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * be called at application startup, prior to any calls to 8352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Collator.getInstance to avoid undefined behavior. 8362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 8372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param collator the collator to register 8382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param locale the locale for which this is the default collator 8392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return an object that can be used to unregister the registered collator. 840ee0f20f8e03a1df95ced34550ed1b0ee06238ecaNeil Fuller * 841ee0f20f8e03a1df95ced34550ed1b0ee06238ecaNeil Fuller * @hide unsupported on Android 8422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 8432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final Object registerInstance(Collator collator, ULocale locale) { 8442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getShim().registerInstance(collator, locale); 8452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 8481537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Registers a collator factory. 849f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * 8502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>Because ICU may choose to cache Collator objects internally, this must 8512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * be called at application startup, prior to any calls to 8522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Collator.getInstance to avoid undefined behavior. 8532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 8542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param factory the factory to register 8552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return an object that can be used to unregister the registered factory. 856ee0f20f8e03a1df95ced34550ed1b0ee06238ecaNeil Fuller * 857ee0f20f8e03a1df95ced34550ed1b0ee06238ecaNeil Fuller * @hide unsupported on Android 8582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 8592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final Object registerFactory(CollatorFactory factory) { 8602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getShim().registerFactory(factory); 8612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 8641537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Unregisters a collator previously registered using registerInstance. 8652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param registryKey the object previously returned by registerInstance. 8662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return true if the collator was successfully unregistered. 867ee0f20f8e03a1df95ced34550ed1b0ee06238ecaNeil Fuller * @hide unsupported on Android 8682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 8692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final boolean unregister(Object registryKey) { 8702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (shim == null) { 8712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return false; 8722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return shim.unregister(registryKey); 8742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 8772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns the set of locales, as Locale objects, for which collators 8782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * are installed. Note that Locale objects do not support RFC 3066. 8792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the list of locales in which collators are installed. 8802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This list includes any that have been registered, in addition to 8812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * those that are installed with ICU4J. 8822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 8832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static Locale[] getAvailableLocales() { 8842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // TODO make this wrap getAvailableULocales later 8852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (shim == null) { 8862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return ICUResourceBundle.getAvailableLocales( 887f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert ICUData.ICU_COLLATION_BASE_NAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER); 8882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return shim.getAvailableLocales(); 8902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 8931537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the set of locales, as ULocale objects, for which collators 8942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * are installed. ULocale objects support RFC 3066. 8952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the list of locales in which collators are installed. 8962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This list includes any that have been registered, in addition to 8972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * those that are installed with ICU4J. 8982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 8992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final ULocale[] getAvailableULocales() { 9002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (shim == null) { 9012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return ICUResourceBundle.getAvailableULocales( 902f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert ICUData.ICU_COLLATION_BASE_NAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER); 9032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return shim.getAvailableULocales(); 9052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 9082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The list of keywords for this service. This must be kept in sync with 9092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the resource data. 9102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 9112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static final String[] KEYWORDS = { "collation" }; 9122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 9142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The resource name for this service. Note that this is not the same as 9152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the keyword for this service. 9162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 9172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static final String RESOURCE = "collations"; 9182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 9202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The resource bundle base name for this service. 9212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * *since ICU 3.0 9222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 923f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert 924f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert private static final String BASE = ICUData.ICU_COLLATION_BASE_NAME; 9252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 9271537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns an array of all possible keywords that are relevant to 9282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * collation. At this point, the only recognized keyword for this 9292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * service is "collation". 9302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return an array of valid collation keywords. 9312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getKeywordValues 9322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 9332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final String[] getKeywords() { 9342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return KEYWORDS; 9352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 9381537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Given a keyword, returns an array of all values for 9392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * that keyword that are currently in use. 9402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param keyword one of the keywords returned by getKeywords. 9412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getKeywords 9422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 9432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final String[] getKeywordValues(String keyword) { 9442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (!keyword.equals(KEYWORDS[0])) { 9452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new IllegalArgumentException("Invalid keyword: " + keyword); 9462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return ICUResourceBundle.getKeywordValues(BASE, RESOURCE); 9482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 9511537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Given a key and a locale, returns an array of string values in a preferred 9522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * order that would make a difference. These are all and only those values where 9532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the open (creation) of the service with the locale formed from the input locale 9542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * plus input keyword and that value has different behavior than creation with the 9552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * input locale alone. 9562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param key one of the keys supported by this service. For now, only 9572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * "collation" is supported. 9582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param locale the locale 9592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param commonlyUsed if set to true it will return only commonly used values 9602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * with the given locale in preferred order. Otherwise, 9612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * it will return all the available values for the locale. 9622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return an array of string values for the given key and the locale. 9632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 964f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert public static final String[] getKeywordValuesForLocale(String key, ULocale locale, 9652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller boolean commonlyUsed) { 966f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert // Note: The parameter commonlyUsed is not used. 9672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // The switch is in the method signature for consistency 9682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // with other locale services. 9692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 970f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert // Read available collation values from collation bundles. 971f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert ICUResourceBundle bundle = (ICUResourceBundle) 972f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert UResourceBundle.getBundleInstance( 973f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert ICUData.ICU_COLLATION_BASE_NAME, locale); 974f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert KeywordsSink sink = new KeywordsSink(); 975f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert bundle.getAllItemsWithFallback("collations", sink); 976f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert return sink.values.toArray(new String[sink.values.size()]); 977f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert } 9782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 979f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert private static final class KeywordsSink extends UResource.Sink { 980f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert LinkedList<String> values = new LinkedList<String>(); 981f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert boolean hasDefault = false; 982f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert 983f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Override 984f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert public void put(UResource.Key key, UResource.Value value, boolean noFallback) { 985f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert UResource.Table collations = value.getTable(); 986f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert for (int i = 0; collations.getKeyAndValue(i, key, value); ++i) { 987f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert int type = value.getType(); 988f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert if (type == UResourceBundle.STRING) { 989f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert if (!hasDefault && key.contentEquals("default")) { 990f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert String defcoll = value.getString(); 991f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert if (!defcoll.isEmpty()) { 992f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert values.remove(defcoll); 993f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert values.addFirst(defcoll); 994f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert hasDefault = true; 995f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert } 996f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert } 997f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert } else if (type == UResourceBundle.TABLE && !key.startsWith("private-")) { 998f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert String collkey = key.toString(); 999f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert if (!values.contains(collkey)) { 1000f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert values.add(collkey); 10012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 10022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 10032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 10042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 10052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 10062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 10072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 10081537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the functionally equivalent locale for the given 10092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * requested locale, with respect to given keyword, for the 10102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * collation service. If two locales return the same result, then 10112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * collators instantiated for these locales will behave 10122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * equivalently. The converse is not always true; two collators 10132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * may in fact be equivalent, but return different results, due to 10142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * internal details. The return result has no other meaning than 10152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * that stated above, and implies nothing as to the relationship 10162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * between the two locales. This is intended for use by 10172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * applications who wish to cache collators, or otherwise reuse 10182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * collators when possible. The functional equivalent may change 10192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * over time. For more information, please see the <a 10202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * href="http://userguide.icu-project.org/locale#TOC-Locales-and-Services"> 10212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Locales and Services</a> section of the ICU User Guide. 10222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param keyword a particular keyword as enumerated by 10232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * getKeywords. 10242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param locID The requested locale 10252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param isAvailable If non-null, isAvailable[0] will receive and 10262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * output boolean that indicates whether the requested locale was 10272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 'available' to the collation service. If non-null, isAvailable 1028bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * must have length >= 1. 10292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the locale 10302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 10312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final ULocale getFunctionalEquivalent(String keyword, 10322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ULocale locID, 10332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller boolean isAvailable[]) { 10342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return ICUResourceBundle.getFunctionalEquivalent(BASE, ICUResourceBundle.ICU_DATA_CLASS_LOADER, RESOURCE, 10352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller keyword, locID, isAvailable, true); 10362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 10372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 10382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 10391537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the functionally equivalent locale for the given 10402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * requested locale, with respect to given keyword, for the 10412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * collation service. 10422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param keyword a particular keyword as enumerated by 10432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * getKeywords. 10442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param locID The requested locale 10452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the locale 10462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getFunctionalEquivalent(String,ULocale,boolean[]) 10472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 10482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final ULocale getFunctionalEquivalent(String keyword, 10492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ULocale locID) { 10502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getFunctionalEquivalent(keyword, locID, null); 10512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 10522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 10532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 10541537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the name of the collator for the objectLocale, localized for the 10552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * displayLocale. 10562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param objectLocale the locale of the collator 10572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param displayLocale the locale for the collator's display name 10582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the display name 10592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 10602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller static public String getDisplayName(Locale objectLocale, Locale displayLocale) { 10612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getShim().getDisplayName(ULocale.forLocale(objectLocale), 10622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ULocale.forLocale(displayLocale)); 10632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 10642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 10652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 10661537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the name of the collator for the objectLocale, localized for the 10672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * displayLocale. 10682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param objectLocale the locale of the collator 10692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param displayLocale the locale for the collator's display name 10702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the display name 10712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 10722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller static public String getDisplayName(ULocale objectLocale, ULocale displayLocale) { 10732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getShim().getDisplayName(objectLocale, displayLocale); 10742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 10752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 10762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 10771537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the name of the collator for the objectLocale, localized for the 10782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * default <code>DISPLAY</code> locale. 10792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param objectLocale the locale of the collator 10802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the display name 10812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale.Category#DISPLAY 10822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 10832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller static public String getDisplayName(Locale objectLocale) { 10842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getShim().getDisplayName(ULocale.forLocale(objectLocale), ULocale.getDefault(Category.DISPLAY)); 10852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 10862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 10872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 10881537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the name of the collator for the objectLocale, localized for the 10892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * default <code>DISPLAY</code> locale. 10902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param objectLocale the locale of the collator 10912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the display name 10922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale.Category#DISPLAY 10932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 10942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller static public String getDisplayName(ULocale objectLocale) { 10952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getShim().getDisplayName(objectLocale, ULocale.getDefault(Category.DISPLAY)); 10962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 10972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 10982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 10992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns this Collator's strength attribute. The strength attribute 11002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * determines the minimum level of difference considered significant. 11011537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu] Note:</strong> This can return QUATERNARY strength, which is not supported by the 11022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * JDK version. 11032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p> 11042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * See the Collator class description for more details. 11052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The base class method always returns {@link #TERTIARY}. 11062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Subclasses should override it if appropriate. 11072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 11082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return this Collator's current strength attribute. 11092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setStrength 11102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #PRIMARY 11112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #SECONDARY 11122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #TERTIARY 11132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #QUATERNARY 11142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #IDENTICAL 11152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 11162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public int getStrength() 11172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 11182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return TERTIARY; 11192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 11202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 11212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 11222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns the decomposition mode of this Collator. The decomposition mode 11232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * determines how Unicode composed characters are handled. 11242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p> 11252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * See the Collator class description for more details. 11262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The base class method always returns {@link #NO_DECOMPOSITION}. 11272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Subclasses should override it if appropriate. 11282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 11292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the decomposition mode 11302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setDecomposition 11312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #NO_DECOMPOSITION 11322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #CANONICAL_DECOMPOSITION 11332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 11342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public int getDecomposition() 11352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 11362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return NO_DECOMPOSITION; 11372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 11382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 11392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // public other methods ------------------------------------------------- 11402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 11412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 11422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Compares the equality of two text Strings using 11432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * this Collator's rules, strength and decomposition mode. Convenience method. 11442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param source the source string to be compared. 11452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param target the target string to be compared. 11462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return true if the strings are equal according to the collation 11472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * rules, otherwise false. 11482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #compare 11492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws NullPointerException thrown if either arguments is null. 11502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 11512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public boolean equals(String source, String target) 11522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 11532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return (compare(source, target) == 0); 11542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 11552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 11562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 11571537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns a UnicodeSet that contains all the characters and sequences tailored 11582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * in this collator. 11592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return a pointer to a UnicodeSet object containing all the 11602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * code points and sequences that may sort differently than 11612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * in the root collator. 11622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 11632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public UnicodeSet getTailoredSet() 11642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 11652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return new UnicodeSet(0, 0x10FFFF); 11662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 11672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 11682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 11692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Compares the source text String to the target text String according to 11702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * this Collator's rules, strength and decomposition mode. 11712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns an integer less than, 11722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * equal to or greater than zero depending on whether the source String is 11732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * less than, equal to or greater than the target String. See the Collator 11742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * class description for an example of use. 1175bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * 11762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param source the source String. 11772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param target the target String. 11782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return Returns an integer value. Value is less than zero if source is 11792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * less than target, value is zero if source and target are equal, 11802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * value is greater than zero if source is greater than target. 11812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see CollationKey 11822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getCollationKey 11832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws NullPointerException thrown if either argument is null. 11842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 11852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract int compare(String source, String target); 11862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 11872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 11882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Compares the source Object to the target Object. 1189bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * 11902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param source the source Object. 11912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param target the target Object. 11922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return Returns an integer value. Value is less than zero if source is 11932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * less than target, value is zero if source and target are equal, 11942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * value is greater than zero if source is greater than target. 11952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws ClassCastException thrown if either arguments cannot be cast to CharSequence. 11962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1197f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Override 11982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public int compare(Object source, Object target) { 11992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return doCompare((CharSequence)source, (CharSequence)target); 12002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 12012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 12022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 12032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Compares two CharSequences. 12042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The base class just calls compare(left.toString(), right.toString()). 12052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Subclasses should instead implement this method and have the String API call this method. 12062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 120793cf604e9dd0525f15bc0a7450b2a35f3884c298Neil Fuller * @hide original deprecated declaration 1208836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 12092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 12102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 12112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller protected int doCompare(CharSequence left, CharSequence right) { 12122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return compare(left.toString(), right.toString()); 12132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 12142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 12152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 12162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p> 12172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Transforms the String into a CollationKey suitable for efficient 12182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * repeated comparison. The resulting key depends on the collator's 12192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * rules, strength and decomposition mode. 12202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1221f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * <p>Note that collation keys are often less efficient than simply doing comparison. 12222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * For more details, see the ICU User Guide. 12232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1224bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * <p>See the CollationKey class documentation for more information. 12252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param source the string to be transformed into a CollationKey. 12262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the CollationKey for the given String based on this Collator's 12272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * collation rules. If the source String is null, a null 12282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * CollationKey is returned. 12292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see CollationKey 12302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #compare(String, String) 12312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 12322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract CollationKey getCollationKey(String source); 12332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 12342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 12351537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the simpler form of a CollationKey for the String source following 12362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the rules of this Collator and stores the result into the user provided argument 12372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * key. If key has a internal byte array of length that's too small for the result, 12382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the internal byte array will be grown to the exact required size. 12392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1240f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * <p>Note that collation keys are often less efficient than simply doing comparison. 12412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * For more details, see the ICU User Guide. 12422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 12432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param source the text String to be transformed into a RawCollationKey 12442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return If key is null, a new instance of RawCollationKey will be 12452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * created and returned, otherwise the user provided key will be 12462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * returned. 12472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #compare(String, String) 12482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getCollationKey 12492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see RawCollationKey 1250ad586b28fcfaa08bd930b5728975f6a3c182d553Paul Duffin * @hide unsupported on Android 12512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 12522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract RawCollationKey getRawCollationKey(String source, 12532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller RawCollationKey key); 12542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 12552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 12561537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Sets the variable top to the top of the specified reordering group. 12572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The variable top determines the highest-sorting character 12582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * which is affected by the alternate handling behavior. 12592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * If that attribute is set to UCOL_NON_IGNORABLE, then the variable top has no effect. 12602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 12612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The base class implementation throws an UnsupportedOperationException. 12622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param group one of Collator.ReorderCodes.SPACE, Collator.ReorderCodes.PUNCTUATION, 12632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Collator.ReorderCodes.SYMBOL, Collator.ReorderCodes.CURRENCY; 12642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * or Collator.ReorderCodes.DEFAULT to restore the default max variable group 12652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return this 12662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getMaxVariable 12672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 12682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public Collator setMaxVariable(int group) { 12692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new UnsupportedOperationException("Needs to be implemented by the subclass."); 12702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 12712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 12722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 12731537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the maximum reordering group whose characters are affected by 12742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the alternate handling behavior. 12752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 12762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The base class implementation returns Collator.ReorderCodes.PUNCTUATION. 12772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the maximum variable reordering group. 12782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setMaxVariable 12792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 12802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public int getMaxVariable() { 12812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return Collator.ReorderCodes.PUNCTUATION; 12822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 12832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 12842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 12851537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Sets the variable top to the primary weight of the specified string. 12862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 12872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>Beginning with ICU 53, the variable top is pinned to 12882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the top of one of the supported reordering groups, 12892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * and it must not be beyond the last of those groups. 12902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * See {@link #setMaxVariable(int)}. 1291f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * 12922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param varTop one or more (if contraction) characters to which the 12932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * variable top should be set 12942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return variable top primary weight 12952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @exception IllegalArgumentException 12962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * is thrown if varTop argument is not a valid variable top element. A variable top element is 12972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * invalid when 12982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <ul> 12992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>it is a contraction that does not exist in the Collation order 13002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>the variable top is beyond 13012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the last reordering group supported by setMaxVariable() 13022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>when the varTop argument is null or zero in length. 13032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </ul> 13042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getVariableTop 13052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see RuleBasedCollator#setAlternateHandlingShifted 13062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated ICU 53 Call {@link #setMaxVariable(int)} instead. 130793cf604e9dd0525f15bc0a7450b2a35f3884c298Neil Fuller * @hide original deprecated declaration 13082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 13092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 13102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract int setVariableTop(String varTop); 13112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 13122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 13131537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Gets the variable top value of a Collator. 1314f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * 13152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the variable top primary weight 13162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getMaxVariable 13172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 13182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract int getVariableTop(); 13192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 13202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 13211537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Sets the variable top to the specified primary weight. 13222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 13232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>Beginning with ICU 53, the variable top is pinned to 13242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the top of one of the supported reordering groups, 13252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * and it must not be beyond the last of those groups. 13262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * See {@link #setMaxVariable(int)}. 1327f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * 13282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param varTop primary weight, as returned by setVariableTop or getVariableTop 13292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getVariableTop 13302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setVariableTop(String) 13312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated ICU 53 Call setMaxVariable() instead. 133293cf604e9dd0525f15bc0a7450b2a35f3884c298Neil Fuller * @hide original deprecated declaration 13332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 13342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 13352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract void setVariableTop(int varTop); 13362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 13372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 13381537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the version of this collator object. 13392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the version object associated with this collator 13402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 13412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract VersionInfo getVersion(); 13422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 13432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 13441537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the UCA version of this collator object. 13452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the version object associated with this collator 13462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 13472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract VersionInfo getUCAVersion(); 1348f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert 1349f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert /** 13502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Retrieves the reordering codes for this collator. 13512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * These reordering codes are a combination of UScript codes and ReorderCodes. 1352f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * @return a copy of the reordering codes for this collator; 13532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * if none are set then returns an empty array 13542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setReorderCodes 13552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getEquivalentReorderCodes 13562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see Collator.ReorderCodes 13572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see UScript 1358f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert */ 1359f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert public int[] getReorderCodes() 1360f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert { 1361f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert throw new UnsupportedOperationException("Needs to be implemented by the subclass."); 1362f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert } 13632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 13642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 13652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Retrieves all the reorder codes that are grouped with the given reorder code. Some reorder 13662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * codes are grouped and must reorder together. 13672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Beginning with ICU 55, scripts only reorder together if they are primary-equal, 13682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for example Hiragana and Katakana. 13692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1370f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * @param reorderCode The reorder code to determine equivalence for. 13712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the set of all reorder codes in the same group as the given reorder code. 13722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #setReorderCodes 13732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see #getReorderCodes 13742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see Collator.ReorderCodes 13752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see UScript 13762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 13772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static int[] getEquivalentReorderCodes(int reorderCode) { 13782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller CollationData baseData = CollationRoot.getData(); 13792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return baseData.getEquivalentScripts(reorderCode); 1380f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert } 13812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 13822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 13832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Freezable interface implementation ------------------------------------------------- 1384f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert 13852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 13862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Determines whether the object has been frozen or not. 13872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 13882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>An unfrozen Collator is mutable and not thread-safe. 13892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * A frozen Collator is immutable and thread-safe. 13902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1391f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Override 13922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public boolean isFrozen() { 13932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return false; 13942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 13952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 13962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 13972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Freezes the collator. 13982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the collator itself. 13992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1400f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Override 14012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public Collator freeze() { 14022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new UnsupportedOperationException("Needs to be implemented by the subclass."); 14032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 14042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 14052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 14062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Provides for the clone operation. Any clone is initially unfrozen. 14072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1408f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Override 14092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public Collator cloneAsThawed() { 14102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new UnsupportedOperationException("Needs to be implemented by the subclass."); 14112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1412f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert 14132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 14142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Empty default constructor to make javadocs happy 14152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 14162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller protected Collator() 14172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 14182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 14192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 14202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static final boolean DEBUG = ICUDebug.enabled("collator"); 14212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 14222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // -------- BEGIN ULocale boilerplate -------- 14232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 14242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 14251537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the locale that was used to create this object, or null. 14262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This may may differ from the locale requested at the time of 14272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * this object's creation. For example, if an object is created 14282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for locale <tt>en_US_CALIFORNIA</tt>, the actual data may be 14292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * drawn from <tt>en</tt> (the <i>actual</i> locale), and 14302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <tt>en_US</tt> may be the most specific locale that exists (the 14312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <i>valid</i> locale). 14322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 14332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>Note: This method will be implemented in ICU 3.0; ICU 2.8 14342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * contains a partial preview implementation. The * <i>actual</i> 14352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * locale is returned correctly, but the <i>valid</i> locale is 14362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * not, in most cases. 14372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 14382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The base class method always returns {@link ULocale#ROOT}. 14392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Subclasses should override it if appropriate. 14402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 14412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param type type of information requested, either {@link 14422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * android.icu.util.ULocale#VALID_LOCALE} or {@link 14432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * android.icu.util.ULocale#ACTUAL_LOCALE}. 14442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the information specified by <i>type</i>, or null if 14452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * this object was not constructed from locale data. 14462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale 14472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale#VALID_LOCALE 14482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale#ACTUAL_LOCALE 1449836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 14502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 14512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public ULocale getLocale(ULocale.Type type) { 14522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return ULocale.ROOT; 14532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 14542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 14552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 14562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Set information about the locales that were used to create this 14572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * object. If the object was not constructed from locale data, 14582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * both arguments should be set to null. Otherwise, neither 14592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * should be null. The actual locale must be at the same level or 14602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * less specific than the valid locale. This method is intended 14612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for use by factories or other entities that create objects of 14622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * this class. 14632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 14642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>The base class method does nothing. Subclasses should override it if appropriate. 14652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 14662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param valid the most specific locale containing any resource 14672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * data, or null 14682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param actual the locale containing data used to construct this 14692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * object, or null 14702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale 14712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale#VALID_LOCALE 14722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale#ACTUAL_LOCALE 14732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 14742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller void setLocale(ULocale valid, ULocale actual) {} 14752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 14762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // -------- END ULocale boilerplate -------- 14772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller} 1478