org.h2.value

## Class CompareMode

- java.lang.Object
- - org.h2.value.CompareMode

Direct Known Subclasses:
  CompareModeDefault, CompareModeIcu4J

    public class CompareMode
    extends java.lang.Object

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

### Field Summary

Fields
`static java.lang.String` `CHARSET` This constant means the charset specified should be used.
`static java.lang.String` `DEFAULT` This constant means the default collator should be used, even if ICU4J is in the classpath.
`static java.lang.String` `ICU4J` This constant means ICU4J should be used (this will fail if it is not in the classpath).
`static java.lang.String` `OFF` This constant means there is no collator set, and the default string comparison is to be used.
`static java.lang.String` `SIGNED` This constant means that the BINARY columns are sorted as if the bytes were signed.
`static java.lang.String` `UNSIGNED` This constant means that the BINARY columns are sorted as if the bytes were unsigned.

### Constructor Summary

Constructors
`protected` `CompareMode(java.lang.String name, int strength, boolean binaryUnsigned)`

### Method Summary

Methods
`int` `compareString(java.lang.String a, java.lang.String b, boolean ignoreCase)` Compare two strings.
`boolean` `equals(java.lang.Object obj)`
`boolean` `equalsChars(java.lang.String a, int ai, java.lang.String b, int bi, boolean ignoreCase)` Compare two characters in a string.
`static java.text.Collator` `getCollator(java.lang.String name)` Get the collator object for the given language name or language / country combination.
`static CompareMode` `getInstance(java.lang.String name, int strength)` Create a new compare mode with the given collator and strength.
`static CompareMode` `getInstance(java.lang.String name, int strength, boolean binaryUnsigned)` Create a new compare mode with the given collator and strength.
`java.lang.String` `getName()`
`static java.lang.String` `getName(java.util.Locale l)` Get the collation name.
`int` `getStrength()`
`int` `hashCode()`
`boolean` `isBinaryUnsigned()`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### OFF

    public static final java.lang.String OFF

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

See Also:
  Constant Field Values

#### DEFAULT

    public static final java.lang.String DEFAULT

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

See Also:
  Constant Field Values

#### ICU4J

    public static final java.lang.String ICU4J

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

See Also:
  Constant Field Values

#### CHARSET

    public static final java.lang.String CHARSET

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

See Also:
  Constant Field Values

#### SIGNED

    public static final java.lang.String SIGNED

This constant means that the BINARY columns are sorted as if the bytes were signed.

See Also:
  Constant Field Values

#### UNSIGNED

    public static final java.lang.String UNSIGNED

This constant means that the BINARY columns are sorted as if the bytes were unsigned.

See Also:
  Constant Field Values

### Constructor Detail

#### CompareMode

    protected CompareMode(java.lang.String name,
               int strength,
               boolean binaryUnsigned)

### Method Detail

#### getInstance

    public static CompareMode getInstance(java.lang.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` - the collation name or null
  `strength` - the collation strength
Returns:
  the compare mode

#### getInstance

    public static CompareMode getInstance(java.lang.String name,
                          int strength,
                          boolean binaryUnsigned)

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 null
  `strength` - the collation strength
  `binaryUnsigned` - whether to compare binaries as unsigned
Returns:
  the compare mode

#### equalsChars

    public boolean equalsChars(java.lang.String a,
                      int ai,
                      java.lang.String b,
                      int bi,
                      boolean ignoreCase)

Compare two characters in a string.

Parameters:
  `a` - the first string
  `ai` - the character index in the first string
  `b` - the second string
  `bi` - the character index in the second string
  `ignoreCase` - true if a case-insensitive comparison should be made
Returns:
  true if the characters are equals

#### compareString

    public int compareString(java.lang.String a,
                    java.lang.String b,
                    boolean ignoreCase)

Compare two strings.

Parameters:
  `a` - the first string
  `b` - the second string
  `ignoreCase` - 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

    public static java.lang.String getName(java.util.Locale l)

Get the collation name.

Parameters:
  `l` - the locale
Returns:
  the name of the collation

#### getCollator

    public static java.text.Collator getCollator(java.lang.String name)

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

Parameters:
  `name` - the language name
Returns:
  the collator

#### getName

    public java.lang.String getName()

#### getStrength

    public int getStrength()

#### isBinaryUnsigned

    public boolean isBinaryUnsigned()

#### equals

    public boolean equals(java.lang.Object obj)

Overrides:
  `equals` in class `java.lang.Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `java.lang.Object`