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.
-
-
Field Summary
Fields Modifier and Type Field Description int[]
maxIgnorable
-
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(UnicodeString s1, UnicodeString s2)
Compare two strings for equality.int
compareStrings(UnicodeString o1, UnicodeString o2)
Compare two stringsboolean
contains(UnicodeString s1, UnicodeString s2)
Test whether one string contains another, according to the rules of the XPath contains() functionboolean
endsWith(UnicodeString s1, UnicodeString s2)
Test whether one string ends with another, according to the rules of the XPath ends-with() functionjava.text.CollationKey
getCollationKey(java.lang.String source)
Factory method to generate a collation key for a given string, using this collationAtomicMatchKey
getCollationKey(UnicodeString s)
Get a collation key for a String.java.lang.String
getCollationURI()
Get the collation URI.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 represented by this collation objectint
getStrength()
static java.lang.String
getUCAVersion()
Return the version of UCA supportedint
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 collationvoid
setStrength(int newStrength)
java.lang.String
show()
Display details of this collationboolean
startsWith(UnicodeString s1, UnicodeString s2)
Test whether one string starts with another, according to the rules of the XPath starts-with() functionUnicodeString
substringAfter(UnicodeString s1, UnicodeString s2)
Return the part of a string after a given substring, according to the rules of the XPath substring-after() functionUnicodeString
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-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.lib.StringCollator
isEqualToEmpty
-
-
-
-
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
-
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)
andCollationKey.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 classjava.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 interfaceStringCollator
- Parameters:
s1
- the first strings2
- 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 interfaceStringCollator
- 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 interfaceStringCollator
- Parameters:
o1
- the first stringo2
- 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 interfaceStringCollator
- 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 interfaceSubstringMatcher
- Parameters:
s1
- the containing strings2
- 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 interfaceSubstringMatcher
- Parameters:
s1
- the containing strings2
- 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 interfaceSubstringMatcher
- Parameters:
s1
- the containing strings2
- 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 interfaceSubstringMatcher
- Parameters:
s1
- the containing strings2
- 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 interfaceSubstringMatcher
- Parameters:
s1
- the containing strings2
- the contained string- Returns:
- the part of s1 that precedes the first occurrence of s2
-
-