Package com.saxonica.expr.sort

## Class UcaCollatorUsingIcu

- java.lang.Object
- - com.saxonica.expr.sort.UcaCollatorUsingIcu

- All Implemented Interfaces:
    `StringCollator`, `SubstringMatcher`

      public class UcaCollatorUsingIcu
      extends java.lang.Object
      implements SubstringMatcher

  This class represents a collation (for comparing strings) implemented using the ICU library. It is available in Saxon-PE and Saxon-EE only.

  Note that in the case that the ICU libraries have not been loaded, then this class is not instantiated. However, the public static functions, e.g. getLocales() could in theory be accessed via an XSLT stylesheet (such as the documentation generators for example) and these invoke ICU features The guard function com.saxonica.config.JavaPlatformPE.hasICUCollator() can be used to check.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `class` | `UcaCollatorUsingIcu.Identical` |
    `class` | `UcaCollatorUsingIcu.Primary` |
    `class` | `UcaCollatorUsingIcu.Secondary` |
    `static interface` | `UcaCollatorUsingIcu.Strength` |
    `class` | `UcaCollatorUsingIcu.Tertiary` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `UcaCollatorUsingIcu​(java.lang.String uri)` | Construct a collation from a given UCA-based collation URI

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `comparesEqual​(java.lang.CharSequence s1, java.lang.CharSequence s2)` | Compare two strings for equality.
    `int` | `compareStrings​(java.lang.CharSequence o1, java.lang.CharSequence o2)` | Compare two strings
    `boolean` | `contains​(java.lang.String s1, java.lang.String s2)` | Test whether one string contains another, according to the rules of the XPath contains() function
    `boolean` | `endsWith​(java.lang.String s1, java.lang.String s2)` | Test whether one string ends with another, according to the rules of the XPath ends-with() function
    `AtomicMatchKey` | `getCollationKey​(java.lang.CharSequence s)` | Get a collation key for a String.
    `java.text.CollationKey` | `getCollationKey​(java.lang.String source)` | Factory method to generate a collation key for a given string, using this collation
    `java.lang.String` | `getCollationURI()` | Get the collation URI.
    `com.ibm.icu.util.ULocale` | `getLocale()` |
    `static java.lang.String[]` | `getLocales()` | Return the locales supported in this version of ICU Note that with Java 6 this method has been known to throw an array index exception from RuleBasedCollator, With Java 7 this performs correctly and getAvailableLocales() does not appear to be invoked from any of the UCA or numbering support.
    `com.ibm.icu.text.RuleBasedCollator` | `getRuleBasedCollator()` | Get the underlying ICU collator represention by this collation object
    `int` | `getStrength()` |
    `static java.lang.String` | `getUCAVersion()` | Return the version of UCA supported
    `int` | `hashCode()` | Get a hash code for the purpose of comparing whether this is the same collation as another.
    `void` | `setProps​(java.util.Properties props)` | Set the properties for the UCA collation
    `void` | `setStrength​(int newStrength)` |
    `java.lang.String` | `show()` | Display details of this collation
    `boolean` | `startsWith​(java.lang.String s1, java.lang.String s2)` | Test whether one string starts with another, according to the rules of the XPath starts-with() function
    `java.lang.String` | `substringAfter​(java.lang.String s1, java.lang.String s2)` | Return the part of a string after a given substring, according to the rules of the XPath substring-after() function
    `java.lang.String` | `substringBefore​(java.lang.String s1, java.lang.String s2)` | Return the part of a string before a given substring, according to the rules of the XPath substring-before() function

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

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

- - ### Constructor Detail

    - #### UcaCollatorUsingIcu

          public UcaCollatorUsingIcu​(java.lang.String uri)
                              throws XPathException

      Construct a collation from a given UCA-based collation URI
      Parameters:
        `uri` - the collation URI, conforming to the syntax defined in the W3C Functions and Operators specification.
      Throws:
        `XPathException` - if the URI is invalid

  - ### Method Detail

    - #### getUCAVersion

          public static java.lang.String getUCAVersion()

      Return the version of UCA supported
      Returns:
        UCA version as nn.nn.nn.nn

    - #### getRuleBasedCollator

          public com.ibm.icu.text.RuleBasedCollator getRuleBasedCollator()

      Get the underlying ICU collator represention by this collation object
      Returns:
        the underlying ICU collator

    - #### getLocales

          public static java.lang.String[] getLocales()

      Return the locales supported in this version of ICU Note that with Java 6 this method has been known to throw an array index exception from RuleBasedCollator, With Java 7 this performs correctly and getAvailableLocales() does not appear to be invoked from any of the UCA or numbering support.
      Returns:
        The language tags and display names separated by semicolon

    - #### show

          public java.lang.String show()

      Display details of this collation
      Returns:
        a string suitable for diagnostic display

    - #### getCollationKey

          public java.text.CollationKey getCollationKey​(java.lang.String source)

      Factory method to generate a collation key for a given string, using this collation
      Parameters:
        `source` - the supplied string
      Returns:
        a collation key with the property that two strings that are deemed equal under this collation generate the same collation key (according to the `Object.equals(Object)` and `CollationKey.compareTo(CollationKey)` methods).

    - #### hashCode

          public int hashCode()

      Get a hash code for the purpose of comparing whether this is the same collation as another.
      Overrides:
        `hashCode` in class `java.lang.Object`
      Returns:
        a suitable hash code

    - #### setProps

          public void setProps​(java.util.Properties props)
                        throws XPathException

      Set the properties for the UCA collation
      Parameters:
        `props` - the set of properties parsed from the UCA parameters
      Throws:
        `XPathException` - if the properties are invalid

    - #### setStrength

          public void setStrength​(int newStrength)

    - #### getStrength

          public int getStrength()

    - #### getLocale

          public com.ibm.icu.util.ULocale getLocale()

    - #### comparesEqual

          public boolean comparesEqual​(java.lang.CharSequence s1,
                                       java.lang.CharSequence s2)

      Description copied from interface: `StringCollator`
      Compare two strings for equality. This may be more efficient than using compareStrings and testing whether the result is zero, but it must give the same result
      Specified by:
        `comparesEqual` in interface `StringCollator`
      Parameters:
        `s1` - the first string
        `s2` - the second string
      Returns:
        true if and only if the strings are considered equal,

    - #### getCollationURI

          public java.lang.String getCollationURI()

      Description copied from interface: `StringCollator`
      Get the collation URI. It must be possible to use this collation URI to reconstitute the collation
      Specified by:
        `getCollationURI` in interface `StringCollator`
      Returns:
        a collation URI that can be used to reconstruct the collation when an XSLT package is reloaded.

    - #### compareStrings

          public int compareStrings​(java.lang.CharSequence o1,
                                    java.lang.CharSequence o2)

      Description copied from interface: `StringCollator`
      Compare two strings
      Specified by:
        `compareStrings` in interface `StringCollator`
      Parameters:
        `o1` - the first string
        `o2` - the second string
      Returns:
        0 if the strings are considered equal, a negative integer if the first string is less than the second, a positive integer if the first string is greater than the second

    - #### getCollationKey

          public AtomicMatchKey getCollationKey​(java.lang.CharSequence s)

      Description copied from interface: `StringCollator`
      Get a collation key for a String. The essential property of collation keys is that if (and only if) two strings are equal under the collation, then comparing the collation keys using the equals() method must return true.
      Specified by:
        `getCollationKey` in interface `StringCollator`
      Parameters:
        `s` - the string whose collation key is required
      Returns:
        the collation key

    - #### contains

          public boolean contains​(java.lang.String s1,
                                  java.lang.String s2)

      Test whether one string contains another, according to the rules of the XPath contains() function
      Specified by:
        `contains` in interface `SubstringMatcher`
      Parameters:
        `s1` - the containing string
        `s2` - the contained string
      Returns:
        true iff s1 contains s2

    - #### endsWith

          public boolean endsWith​(java.lang.String s1,
                                  java.lang.String s2)

      Test whether one string ends with another, according to the rules of the XPath ends-with() function
      Specified by:
        `endsWith` in interface `SubstringMatcher`
      Parameters:
        `s1` - the containing string
        `s2` - the contained string
      Returns:
        true iff s1 ends with s2

    - #### startsWith

          public boolean startsWith​(java.lang.String s1,
                                    java.lang.String s2)

      Test whether one string starts with another, according to the rules of the XPath starts-with() function
      Specified by:
        `startsWith` in interface `SubstringMatcher`
      Parameters:
        `s1` - the containing string
        `s2` - the contained string
      Returns:
        true iff s1 starts with s2

    - #### substringAfter

          public java.lang.String substringAfter​(java.lang.String s1,
                                                 java.lang.String s2)

      Return the part of a string after a given substring, according to the rules of the XPath substring-after() function
      Specified by:
        `substringAfter` in interface `SubstringMatcher`
      Parameters:
        `s1` - the containing string
        `s2` - the contained string
      Returns:
        the part of s1 that follows the first occurrence of s2

    - #### substringBefore

          public java.lang.String substringBefore​(java.lang.String s1,
                                                  java.lang.String s2)

      Return the part of a string before a given substring, according to the rules of the XPath substring-before() function
      Specified by:
        `substringBefore` in interface `SubstringMatcher`
      Parameters:
        `s1` - the containing string
        `s2` - the contained string
      Returns:
        the part of s1 that precedes the first occurrence of s2