RuleBasedCollator Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
RuleBasedCollator is a concrete subclass of Collator.
[Android.Runtime.Register("android/icu/text/RuleBasedCollator", ApiSince=24, DoNotGenerateAcw=true)]
public sealed class RuleBasedCollator : Android.Icu.Text.Collator
[<Android.Runtime.Register("android/icu/text/RuleBasedCollator", ApiSince=24, DoNotGenerateAcw=true)>]
type RuleBasedCollator = class
inherit Collator
- Inheritance
- Attributes
Remarks
RuleBasedCollator is a concrete subclass of Collator. It allows customization of the Collator via user-specified rule sets. RuleBasedCollator is designed to be fully compliant to the Unicode Collation Algorithm (UCA) and conforms to ISO 14651.
A Collator is thread-safe only when frozen. See #isFrozen()
and android.icu.util.Freezable
.
Users are strongly encouraged to read the User Guide for more information about the collation service before using this class.
Create a RuleBasedCollator from a locale by calling the getInstance(Locale) factory method in the base class Collator. Collator.getInstance(Locale) creates a RuleBasedCollator object based on the collation rules defined by the argument locale. If a customized collation ordering or attributes is required, use the RuleBasedCollator(String) constructor with the appropriate rules. The customized RuleBasedCollator will base its ordering on the CLDR root collation, while re-adjusting the attributes and orders of the characters in the specified rule accordingly.
RuleBasedCollator provides correct collation orders for most locales supported in ICU. If specific data for a locale is not available, the orders eventually falls back to the CLDR root sort order.
For information about the collation rule syntax and details about customization, please refer to the Collation customization section of the User Guide.
<strong>Note</strong> that there are some differences between the Collation rule syntax used in Java and ICU4J:
<ul> <li>According to the JDK documentation: <br> Modifier '!' : Turns on Thai/Lao vowel-consonant swapping. If this rule is in force when a Thai vowel of the range \U0E40-\U0E44 precedes a Thai consonant of the range \U0E01-\U0E2E OR a Lao vowel of the range \U0EC0-\U0EC4 precedes a Lao consonant of the range \U0E81-\U0EAE then the vowel is placed after the consonant for collation purposes. <br> If a rule is without the modifier '!', the Thai/Lao vowel-consonant swapping is not turned on. <br> ICU4J's RuleBasedCollator does not support turning off the Thai/Lao vowel-consonant swapping, since the UCA clearly states that it has to be supported to ensure a correct sorting order. If a '!' is encountered, it is ignored.</li> <li>As mentioned in the documentation of the base class Collator, compatibility decomposition mode is not supported.</li> </ul>
<strong>Examples</strong>
Creating Customized RuleBasedCollators: <blockquote>
String simple = "& a < b < c < d";
RuleBasedCollator simpleCollator = new RuleBasedCollator(simple);
String norwegian = "& a , A < b , B < c , C < d , D < e , E "
+ "< f , F < g , G < h , H < i , I < j , "
+ "J < k , K < l , L < m , M < n , N < "
+ "o , O < p , P < q , Q <r , R <s , S < "
+ "t , T < u , U < v , V < w , W < x , X "
+ "< y , Y < z , Z < \u00E5 = a\u030A "
+ ", \u00C5 = A\u030A ; aa , AA < \u00E6 "
+ ", \u00C6 < \u00F8 , \u00D8";
RuleBasedCollator norwegianCollator = new RuleBasedCollator(norwegian);
</blockquote>
Concatenating rules to combine Collator
s: <blockquote>
// Create an en_US Collator object
RuleBasedCollator en_USCollator = (RuleBasedCollator)
Collator.getInstance(new Locale("en", "US", ""));
// Create a da_DK Collator object
RuleBasedCollator da_DKCollator = (RuleBasedCollator)
Collator.getInstance(new Locale("da", "DK", ""));
// Combine the two
// First, get the collation rules from en_USCollator
String en_USRules = en_USCollator.getRules();
// Second, get the collation rules from da_DKCollator
String da_DKRules = da_DKCollator.getRules();
RuleBasedCollator newCollator =
new RuleBasedCollator(en_USRules + da_DKRules);
// newCollator has the combined rules
</blockquote>
Making changes to an existing RuleBasedCollator to create a new Collator
object, by appending changes to the existing rule: <blockquote>
// Create a new Collator object with additional rules
String addRules = "& C < ch, cH, Ch, CH";
RuleBasedCollator myCollator =
new RuleBasedCollator(en_USCollator.getRules() + addRules);
// myCollator contains the new rules
</blockquote>
How to change the order of non-spacing accents: <blockquote>
// old rule with main accents
String oldRules = "= \u0301 ; \u0300 ; \u0302 ; \u0308 "
+ "; \u0327 ; \u0303 ; \u0304 ; \u0305 "
+ "; \u0306 ; \u0307 ; \u0309 ; \u030A "
+ "; \u030B ; \u030C ; \u030D ; \u030E "
+ "; \u030F ; \u0310 ; \u0311 ; \u0312 "
+ "< a , A ; ae, AE ; \u00e6 , \u00c6 "
+ "< b , B < c, C < e, E & C < d , D";
// change the order of accent characters
String addOn = "& \u0300 ; \u0308 ; \u0302";
RuleBasedCollator myCollator = new RuleBasedCollator(oldRules + addOn);
</blockquote>
Putting in a new primary ordering before the default setting, e.g. sort English characters before or after Japanese characters in the Japanese Collator
: <blockquote>
// get en_US Collator rules
RuleBasedCollator en_USCollator
= (RuleBasedCollator)Collator.getInstance(Locale.US);
// add a few Japanese characters to sort before English characters
// suppose the last character before the first base letter 'a' in
// the English collation rule is \u2212
String jaString = "& \u2212 <\u3041, \u3042 <\u3043, "
+ "\u3044";
RuleBasedCollator myJapaneseCollator
= new RuleBasedCollator(en_USCollator.getRules() + jaString);
</blockquote>
This class is not subclassable
Java documentation for android.icu.text.RuleBasedCollator
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
RuleBasedCollator(String) |
Constructor that takes the argument rules for customization. |
Fields
CanonicalDecomposition |
Obsolete.
Decomposition mode value. (Inherited from Collator) |
FullDecomposition |
Obsolete.
<strong>[icu] Note:</strong> This is for backwards compatibility with Java APIs only. (Inherited from Collator) |
Identical |
Obsolete.
Smallest Collator strength value. (Inherited from Collator) |
NoDecomposition |
Obsolete.
Decomposition mode value. (Inherited from Collator) |
Primary |
Obsolete.
Strongest collator strength value. (Inherited from Collator) |
Quaternary |
Obsolete.
<strong>[icu]</strong> Fourth level collator strength value. (Inherited from Collator) |
Secondary |
Obsolete.
Second level collator strength value. (Inherited from Collator) |
Tertiary |
Obsolete.
Third level collator strength value. (Inherited from Collator) |
Properties
AlternateHandlingShifted |
Checks if the alternate handling behavior is the UCA defined SHIFTED or NON_IGNORABLE. -or- Sets the alternate handling for QUATERNARY strength to be either shifted or non-ignorable. |
CaseLevel |
Checks if case level is set to true. -or- When case level is set to true, an additional weight is formed between the SECONDARY and TERTIARY weight, known as the case level. |
Class |
Returns the runtime class of this |
Decomposition |
Returns the decomposition mode of this Collator. -or- Sets the decomposition mode of this Collator. (Inherited from Collator) |
FrenchCollation |
Checks if French Collation is set to true. -or- Sets the mode for the direction of SECONDARY weights to be used in French collation. |
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
IsFrozen |
Determines whether the object has been frozen or not. (Inherited from Collator) |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
LowerCaseFirst |
Return true if a lowercase character is sorted before the corresponding uppercase character. -or- Sets the orders of lower cased characters to sort before upper cased characters, in strength TERTIARY. |
MaxVariable |
<strong>[icu]</strong> Returns the maximum reordering group whose characters are affected by the alternate handling behavior. (Inherited from Collator) |
NumericCollation |
Method to retrieve the numeric collation value. -or- <strong>[icu]</strong> When numeric collation is turned on, this Collator makes substrings of digits sort according to their numeric values. |
PeerReference | (Inherited from Object) |
Rules |
Gets the collation tailoring rules for this RuleBasedCollator. |
Strength |
Returns this Collator's strength attribute. -or- Sets this Collator's strength attribute. (Inherited from Collator) |
TailoredSet |
<strong>[icu]</strong> Returns a UnicodeSet that contains all the characters and sequences tailored in this collator. (Inherited from Collator) |
ThresholdClass | (Inherited from Collator) |
ThresholdType | (Inherited from Collator) |
UCAVersion |
Get the UCA version of this collator object. |
UpperCaseFirst |
Return true if an uppercase character is sorted before the corresponding lowercase character. -or- Sets whether uppercase characters sort before lowercase characters or vice versa, in strength TERTIARY. |
VariableTop |
<strong>[icu]</strong> Gets the variable top value of a Collator. |
Version |
Get the version of this collator object. |
Methods
Clone() |
Clones the collator. (Inherited from Collator) |
CloneAsThawed() |
Provides for the clone operation. (Inherited from Collator) |
Compare(Object, Object) |
Compares the source Object to the target Object. (Inherited from Collator) |
Compare(String, String) |
Compares the source text String to the target text String according to the collation rules, strength and decomposition mode for this RuleBasedCollator. |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
Equals(String, String) |
Compares the equality of two text Strings using this Collator's rules, strength and decomposition mode. (Inherited from Collator) |
Freeze() |
Freezes the collator. (Inherited from Collator) |
GetCollationElementIterator(ICharacterIterator) |
Return a CollationElementIterator for the given CharacterIterator. |
GetCollationElementIterator(String) |
Return a CollationElementIterator for the given String. |
GetCollationElementIterator(UCharacterIterator) |
Return a CollationElementIterator for the given UCharacterIterator. |
GetCollationKey(String) |
Get a Collation key for the argument String source from this RuleBasedCollator. |
GetContractionsAndExpansions(UnicodeSet, UnicodeSet, Boolean) |
Gets unicode sets containing contractions and/or expansions of a collator |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
GetReorderCodes() |
Retrieves the reordering codes for this collator. (Inherited from Collator) |
GetRules(Boolean) |
Returns current rules. |
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
SetAlternateHandlingDefault() |
Sets the alternate handling mode to the initial mode set during construction of the RuleBasedCollator. |
SetCaseFirstDefault() |
Sets the case first mode to the initial mode set during construction of the RuleBasedCollator. |
SetCaseLevelDefault() |
Sets the case level mode to the initial mode set during construction of the RuleBasedCollator. |
SetDecompositionDefault() |
Sets the decomposition mode to the initial mode set during construction of the RuleBasedCollator. |
SetFrenchCollationDefault() |
Sets the French collation mode to the initial mode set during construction of the RuleBasedCollator. |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
SetMaxVariable(Int32) |
<strong>[icu]</strong> Sets the variable top to the top of the specified reordering group. (Inherited from Collator) |
SetNumericCollationDefault() |
Method to set numeric collation to its default value. |
SetReorderCodes(Int32[]) |
Sets the reordering codes for this collator. (Inherited from Collator) |
SetStrengthDefault() |
Sets the collation strength to the initial mode set during the construction of the RuleBasedCollator. |
ToArray<T>() | (Inherited from Object) |
ToString() |
Returns a string representation of the object. (Inherited from Object) |
UnregisterFromRuntime() | (Inherited from Object) |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Explicit Interface Implementations
IComparator.Compare(Object, Object) | (Inherited from Collator) |
IFreezable.CloneAsThawed() | (Inherited from Collator) |
IFreezable.Freeze() | (Inherited from Collator) |
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |
Gets the JNI name of the type of the instance |
JavaAs<TResult>(IJavaPeerable) |
Try to coerce |
TryJavaCast<TResult>(IJavaPeerable, TResult) |
Try to coerce |