com.ibm.icu.text
Class UTF16.StringComparator

java.lang.Object
  extended by com.ibm.icu.text.UTF16.StringComparator
All Implemented Interfaces:
Comparator
Enclosing class:
UTF16

public static final class UTF16.StringComparator
extends Object
implements Comparator

UTF16 string comparator class. Allows UTF16 string comparison to be done with the various modes

The code unit or code point comparison differ only when comparing supplementary code points (\u10000..\u10ffff) to BMP code points near the end of the BMP (i.e., \ue000..\uffff). In code unit comparison, high BMP code points sort after supplementary code points because they are stored as pairs of surrogates which are at \ud800..\udfff.

See Also:
FOLD_CASE_DEFAULT, FOLD_CASE_EXCLUDE_SPECIAL_I
Status:
Stable ICU 2.1.

Field Summary
static int FOLD_CASE_DEFAULT
           Option value for case folding comparison: Comparison is case insensitive, strings are folded using default mappings defined in Unicode data file CaseFolding.txt, before comparison.
static int FOLD_CASE_EXCLUDE_SPECIAL_I
           Option value for case folding comparison: Comparison is case insensitive, strings are folded using modified mappings defined in Unicode data file CaseFolding.txt, before comparison.
 
Constructor Summary
UTF16.StringComparator()
          Default constructor that does code unit comparison and case sensitive comparison.
UTF16.StringComparator(boolean codepointcompare, boolean ignorecase, int foldcaseoption)
          Constructor that does comparison based on the argument options.
 
Method Summary
 int compare(Object a, Object b)
          Compare two strings depending on the options selected during construction.
 boolean getCodePointCompare()
          Checks if the comparison mode is code point compare.
 boolean getIgnoreCase()
          Checks if Comparator is in the case insensitive mode.
 int getIgnoreCaseOption()
          Gets the fold case options set in Comparator to be used with case insensitive comparison.
 void setCodePointCompare(boolean flag)
          Sets the comparison mode to code point compare if flag is true.
 void setIgnoreCase(boolean ignorecase, int foldcaseoption)
          Sets the Comparator to case-insensitive comparison mode if argument is true, otherwise case sensitive comparison mode if set to false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

FOLD_CASE_DEFAULT

public static final int FOLD_CASE_DEFAULT

Option value for case folding comparison:

Comparison is case insensitive, strings are folded using default mappings defined in Unicode data file CaseFolding.txt, before comparison.

See Also:
Constant Field Values
Status:
Stable ICU 2.4.

FOLD_CASE_EXCLUDE_SPECIAL_I

public static final int FOLD_CASE_EXCLUDE_SPECIAL_I

Option value for case folding comparison:

Comparison is case insensitive, strings are folded using modified mappings defined in Unicode data file CaseFolding.txt, before comparison.

The modified set of mappings is provided in a Unicode data file CaseFolding.txt to handle dotted I and dotless i appropriately for Turkic languages (tr, az).

Before Unicode 3.2, CaseFolding.txt contains mappings marked with 'I' that are to be included for default mappings and excluded for the Turkic-specific mappings.

Unicode 3.2 CaseFolding.txt instead contains mappings marked with 'T' that are to be excluded for default mappings and included for the Turkic-specific mappings.

See Also:
Constant Field Values
Status:
Stable ICU 2.4.
Constructor Detail

UTF16.StringComparator

public UTF16.StringComparator()
Default constructor that does code unit comparison and case sensitive comparison.

Status:
Stable ICU 2.1.

UTF16.StringComparator

public UTF16.StringComparator(boolean codepointcompare,
                              boolean ignorecase,
                              int foldcaseoption)
Constructor that does comparison based on the argument options.

Parameters:
codepointcompare - flag to indicate true for code point comparison or false for code unit comparison.
ignorecase - false for case sensitive comparison, true for case-insensitive comparison
foldcaseoption - FOLD_CASE_DEFAULT or FOLD_CASE_EXCLUDE_SPECIAL_I. This option is used only when ignorecase is set to true. If ignorecase is false, this option is ignored.
Throws:
IllegalArgumentException - if foldcaseoption is out of range
See Also:
FOLD_CASE_DEFAULT, FOLD_CASE_EXCLUDE_SPECIAL_I
Status:
Stable ICU 2.4.
Method Detail

setCodePointCompare

public void setCodePointCompare(boolean flag)
Sets the comparison mode to code point compare if flag is true. Otherwise comparison mode is set to code unit compare

Parameters:
flag - true for code point compare, false for code unit compare
Status:
Stable ICU 2.4.

setIgnoreCase

public void setIgnoreCase(boolean ignorecase,
                          int foldcaseoption)
Sets the Comparator to case-insensitive comparison mode if argument is true, otherwise case sensitive comparison mode if set to false.

Parameters:
ignorecase - true for case-insitive comparison, false for case sensitive comparison
foldcaseoption - FOLD_CASE_DEFAULT or FOLD_CASE_EXCLUDE_SPECIAL_I. This option is used only when ignorecase is set to true. If ignorecase is false, this option is ignored.
See Also:
FOLD_CASE_DEFAULT, FOLD_CASE_EXCLUDE_SPECIAL_I
Status:
Stable ICU 2.4.

getCodePointCompare

public boolean getCodePointCompare()
Checks if the comparison mode is code point compare.

Returns:
true for code point compare, false for code unit compare
Status:
Stable ICU 2.4.

getIgnoreCase

public boolean getIgnoreCase()
Checks if Comparator is in the case insensitive mode.

Returns:
true if Comparator performs case insensitive comparison, false otherwise
Status:
Stable ICU 2.4.

getIgnoreCaseOption

public int getIgnoreCaseOption()
Gets the fold case options set in Comparator to be used with case insensitive comparison.

Returns:
either FOLD_CASE_DEFAULT or FOLD_CASE_EXCLUDE_SPECIAL_I
See Also:
FOLD_CASE_DEFAULT, FOLD_CASE_EXCLUDE_SPECIAL_I
Status:
Stable ICU 2.4.

compare

public int compare(Object a,
                   Object b)
Compare two strings depending on the options selected during construction.

Specified by:
compare in interface Comparator
Parameters:
a - first source string.
b - second source string.
Returns:
0 returned if a == b. If a < b, a negative value is returned. Otherwise if a > b, a positive value is returned.
Throws:
ClassCastException - thrown when either a or b is not a String object
Status:
Stable ICU 2.4.


Copyright (c) 2009 IBM Corporation and others.