Class CompareMode
java.lang.Object
org.h2.value.CompareMode
- All Implemented Interfaces:
Comparator<Value>
- Direct Known Subclasses:
CompareModeDefault, CompareModeIcu4J
Instances of this class can compare strings. Case sensitive and case
insensitive comparison is supported, and comparison using a collator.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanstatic final StringThis constant means the charset specified should be used.static final StringThis constant means the default collator should be used, even if ICU4J is in the classpath.static final StringThis constant means ICU4J should be used (this will fail if it is not in the classpath).private static CompareModeprivate static Locale[]private final Stringstatic final StringThis constant means there is no collator set, and the default string comparison is to be used.private final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint(package private) static booleancompareLocaleNames(Locale locale, String name) Compare name of the locale with the given name.intcompareString(String a, String b, boolean ignoreCase) Compare two strings.booleanbooleanequalsChars(String a, int ai, String b, int bi, boolean ignoreCase) Compare two characters in a string.static Locale[]getCollationLocales(boolean onlyIfInitialized) Returns available locales for collations.static CollatorgetCollator(String name) Get the collator object for the given language name or language / country combination.static CompareModegetInstance(String name, int strength) Create a new compare mode with the given collator and strength.getName()static StringGet the collation name.intinthashCode()Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
OFF
This constant means there is no collator set, and the default string comparison is to be used.- See Also:
-
DEFAULT
This constant means the default collator should be used, even if ICU4J is in the classpath.- See Also:
-
ICU4J
This constant means ICU4J should be used (this will fail if it is not in the classpath).- See Also:
-
CHARSET
This constant means the charset specified should be used. This will fail if the specified charset does not exist.- See Also:
-
LOCALES
-
lastUsed
-
CAN_USE_ICU4J
private static final boolean CAN_USE_ICU4J -
name
-
strength
private final int strength
-
-
Constructor Details
-
CompareMode
-
-
Method Details
-
getInstance
Create a new compare mode with the given collator and strength. If required, a new CompareMode is created, or if possible the last one is returned. A cache is used to speed up comparison when using a collator; CollationKey objects are cached.- Parameters:
name- the collation name or nullstrength- the collation strength- Returns:
- the compare mode
-
getCollationLocales
Returns available locales for collations.- Parameters:
onlyIfInitialized- iftrue, returnsnullwhen locales are not yet initialized- Returns:
- available locales for collations.
-
equalsChars
Compare two characters in a string.- Parameters:
a- the first stringai- the character index in the first stringb- the second stringbi- the character index in the second stringignoreCase- true if a case-insensitive comparison should be made- Returns:
- true if the characters are equals
-
compareString
Compare two strings.- Parameters:
a- the first stringb- the second stringignoreCase- true if a case-insensitive comparison should be made- Returns:
- -1 if the first string is 'smaller', 1 if the second string is smaller, and 0 if they are equal
-
getName
-
compareLocaleNames
-
getCollator
-
getName
-
getStrength
public int getStrength() -
equals
-
hashCode
-
compare
- Specified by:
comparein interfaceComparator<Value>
-