Class 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.

    • Field Detail

      • maxIgnorable

        public int[] maxIgnorable
    • 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 represented by this collation object
        Returns:
        the underlying ICU collator
      • 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()
      • comparesEqual

        public boolean comparesEqual​(UnicodeString s1,
                                     UnicodeString 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​(UnicodeString o1,
                                  UnicodeString 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​(UnicodeString 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​(UnicodeString s1,
                                UnicodeString 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​(UnicodeString s1,
                                UnicodeString 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​(UnicodeString s1,
                                  UnicodeString 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 UnicodeString substringAfter​(UnicodeString s1,
                                            UnicodeString 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 UnicodeString substringBefore​(UnicodeString s1,
                                             UnicodeString 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