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 stringsboolean
contains(java.lang.String s1, java.lang.String s2)
Test whether one string contains another, according to the rules of the XPath contains() functionboolean
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() functionAtomicMatchKey
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 collationjava.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 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(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.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() functionjava.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
-
-
-
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)
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()
-
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 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(java.lang.CharSequence o1, java.lang.CharSequence 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(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 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:
contains
in 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:
endsWith
in 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:
startsWith
in 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:
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 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 interfaceSubstringMatcher
- Parameters:
s1
- the containing strings2
- the contained string- Returns:
- the part of s1 that precedes the first occurrence of s2
-
-