Top Description Fields Constructors Methods
org.h2.value

public Class CompareMode

extends Object
implements Comparator<Value>
Class Inheritance
All Implemented Interfaces
java.util.Comparator
Known Direct Subclasses
org.h2.value.CompareModeDefault, org.h2.value.CompareModeIcu4J
Imports
java.nio.charset.Charset, java.text.Collator, java.util.Comparator, .Locale, .Objects, org.h2.util.StringUtils

Instances of this class can compare strings. Case sensitive and case insensitive comparison is supported, and comparison using a collator.

Field Summary

Modifier and TypeField and Description
private static final boolean
public static final String
CHARSET

This constant means the charset specified should be used.

public static final String
DEFAULT

This constant means the default collator should be used, even if ICU4J is in the classpath.

public static final String
ICU4J

This constant means ICU4J should be used (this will fail if it is not in the classpath).

private static volatile CompareMode
private static Locale[]
private final String
public static final String
OFF

This constant means there is no collator set, and the default string comparison is to be used.

private final int

Constructor Summary

AccessConstructor and Description
protected
CompareMode(String name, int strength)

Method Summary

Modifier and TypeMethod and Description
public int
compare(Value
the first object to be compared.
o1
,
Value
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

pack-priv static boolean

Returns:

true if they match
compareLocaleNames
(Locale
the locale
locale
,
String
the name
name
)

Compare name of the locale with the given name.

public int

Returns:

-1 if the first string is 'smaller', 1 if the second string is smaller, and 0 if they are equal
compareString
(String
the first string
a
,
String
the second string
b
,
boolean
true if a case-insensitive comparison should be made
ignoreCase
)

Compare two strings.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Implements java.util.Comparator.equals.

Indicates whether some other object is "equal to" this comparator.

public boolean

Returns:

true if the characters are equals
equalsChars
(String
the first string
a
,
int
the character index in the first string
ai
,
String
the second string
b
,
int
the character index in the second string
bi
,
boolean
true if a case-insensitive comparison should be made
ignoreCase
)

Compare two characters in a string.

public static Locale[]

Returns:

available locales for collations.
getCollationLocales
(boolean
if true, returns null when locales are not yet initialized
onlyIfInitialized
)

Returns available locales for collations.

public static Collator

Returns:

the collator
getCollator
(String
the language name
name
)

Get the collator object for the given language name or language / country combination.

public static CompareMode

Returns:

the compare mode
getInstance
(String
the collation name or null
name
,
int
the collation strength
strength
)

Create a new compare mode with the given collator and strength.

public static String

Returns:

the name of the collation
getName
(Locale
the locale
l
)

Get the collation name.

public String
public int
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

CAN_USE_ICU4Jback to summary
private static final boolean CAN_USE_ICU4J
CHARSETback to summary
public static final String CHARSET

This constant means the charset specified should be used. This will fail if the specified charset does not exist.

DEFAULTback to summary
public static final String DEFAULT

This constant means the default collator should be used, even if ICU4J is in the classpath.

ICU4Jback to summary
public static final String ICU4J

This constant means ICU4J should be used (this will fail if it is not in the classpath).

lastUsedback to summary
private static volatile CompareMode lastUsed
LOCALESback to summary
private static Locale[] LOCALES
nameback to summary
private final String name
OFFback to summary
public static final String OFF

This constant means there is no collator set, and the default string comparison is to be used.

strengthback to summary
private final int strength

Constructor Detail

CompareModeback to summary
protected CompareMode(String name, int strength)

Method Detail

compareback to summary
public int compare(Value o1, Value o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:Value

the first object to be compared.

o2:Value

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@Override
compareLocaleNamesback to summary
pack-priv static boolean compareLocaleNames(Locale locale, String name)

Compare name of the locale with the given name. The case of the name is ignored.

Parameters
locale:Locale

the locale

name:String

the name

Returns:boolean

true if they match

compareStringback to summary
public int compareString(String a, String b, boolean ignoreCase)

Compare two strings.

Parameters
a:String

the first string

b:String

the second string

ignoreCase:boolean

true if a case-insensitive comparison should be made

Returns:int

-1 if the first string is 'smaller', 1 if the second string is smaller, and 0 if they are equal

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.util.Comparator.equals.

Doc from java.util.Comparator.equals.

Indicates whether some other object is "equal to" this comparator. This method must obey the general contract of Object#equals(Object). Additionally, this method can return true only if the specified object is also a comparator and it imposes the same ordering as this comparator. Thus, comp1.equals(comp2) implies that signum(comp1.compare(o1, o2))==signum(comp2.compare(o1, o2)) for every object reference o1 and o2.

Note that it is always safe not to override Object.equals(Object). However, overriding this method may, in some cases, improve performance by allowing programs to determine that two distinct comparators impose the same order.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true only if the specified object is also a comparator and it imposes the same ordering as this comparator.

Annotations
@Override
equalsCharsback to summary
public boolean equalsChars(String a, int ai, String b, int bi, boolean ignoreCase)

Compare two characters in a string.

Parameters
a:String

the first string

ai:int

the character index in the first string

b:String

the second string

bi:int

the character index in the second string

ignoreCase:boolean

true if a case-insensitive comparison should be made

Returns:boolean

true if the characters are equals

getCollationLocalesback to summary
public static Locale[] getCollationLocales(boolean onlyIfInitialized)

Returns available locales for collations.

Parameters
onlyIfInitialized:boolean

if true, returns null when locales are not yet initialized

Returns:Locale[]

available locales for collations.

getCollatorback to summary
public static Collator getCollator(String name)

Get the collator object for the given language name or language / country combination.

Parameters
name:String

the language name

Returns:Collator

the collator

getInstanceback to summary
public static CompareMode getInstance(String name, int strength)

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:String

the collation name or null

strength:int

the collation strength

Returns:CompareMode

the compare mode

getNameback to summary
public static String getName(Locale l)

Get the collation name.

Parameters
l:Locale

the locale

Returns:String

the name of the collation

getNameback to summary
public String getName()
getStrengthback to summary
public int getStrength()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override