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 classUcaCollatorUsingIcu.IdenticalclassUcaCollatorUsingIcu.PrimaryclassUcaCollatorUsingIcu.Secondarystatic interfaceUcaCollatorUsingIcu.StrengthclassUcaCollatorUsingIcu.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 booleancomparesEqual(java.lang.CharSequence s1, java.lang.CharSequence s2)Compare two strings for equality.intcompareStrings(java.lang.CharSequence o1, java.lang.CharSequence o2)Compare two stringsbooleancontains(java.lang.String s1, java.lang.String s2)Test whether one string contains another, according to the rules of the XPath contains() functionbooleanendsWith(java.lang.String s1, java.lang.String s2)Test whether one string ends with another, according to the rules of the XPath ends-with() functionAtomicMatchKeygetCollationKey(java.lang.CharSequence s)Get a collation key for a String.java.text.CollationKeygetCollationKey(java.lang.String source)Factory method to generate a collation key for a given string, using this collationjava.lang.StringgetCollationURI()Get the collation URI.com.ibm.icu.util.ULocalegetLocale()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.RuleBasedCollatorgetRuleBasedCollator()Get the underlying ICU collator represention by this collation objectintgetStrength()static java.lang.StringgetUCAVersion()Return the version of UCA supportedinthashCode()Get a hash code for the purpose of comparing whether this is the same collation as another.voidsetProps(java.util.Properties props)Set the properties for the UCA collationvoidsetStrength(int newStrength)java.lang.Stringshow()Display details of this collationbooleanstartsWith(java.lang.String s1, java.lang.String s2)Test whether one string starts with another, according to the rules of the XPath starts-with() functionjava.lang.StringsubstringAfter(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() functionjava.lang.StringsubstringBefore(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
-
-
-
Constructor Detail
-
UcaCollatorUsingIcu
public UcaCollatorUsingIcu(java.lang.String uri) throws XPathExceptionConstruct 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)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:
hashCodein classjava.lang.Object- Returns:
- a suitable hash code
-
setProps
public void setProps(java.util.Properties props) throws XPathExceptionSet 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:StringCollatorCompare 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:
comparesEqualin 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:StringCollatorGet the collation URI. It must be possible to use this collation URI to reconstitute the collation- Specified by:
getCollationURIin interfaceStringCollator- 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:StringCollatorCompare two strings- Specified by:
compareStringsin 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(java.lang.CharSequence s)
Description copied from interface:StringCollatorGet 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:
getCollationKeyin interfaceStringCollator- 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:
containsin interfaceSubstringMatcher- Parameters:
s1- the containing strings2- 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:
endsWithin interfaceSubstringMatcher- Parameters:
s1- the containing strings2- 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:
startsWithin interfaceSubstringMatcher- Parameters:
s1- the containing strings2- 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:
substringAfterin interfaceSubstringMatcher- Parameters:
s1- the containing strings2- 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:
substringBeforein interfaceSubstringMatcher- Parameters:
s1- the containing strings2- the contained string- Returns:
- the part of s1 that precedes the first occurrence of s2
-
-