Package net.sf.saxon.expr.sort
Class UcaCollatorUsingJava
- java.lang.Object
-
- net.sf.saxon.expr.sort.UcaCollatorUsingJava
-
- All Implemented Interfaces:
StringCollator,SubstringMatcher
public class UcaCollatorUsingJava extends java.lang.Object implements SubstringMatcher
This class implements (an approximation to) the UCA Collation Algorithm relying solely on the built-in Java support (that is, without using the ICU library). This provides a fallback implementation for Saxon-HE, and it is used only when the collation URI does not include the option fallback=no.
-
-
Constructor Summary
Constructors Constructor Description UcaCollatorUsingJava(java.lang.String uri)Create a collation from a given collation URI
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancomparesEqual(java.lang.CharSequence s1, java.lang.CharSequence s2)Ask whether two strings are considered equal under this collationintcompareStrings(java.lang.CharSequence o1, java.lang.CharSequence o2)Compare two strings for equality or ordering under the rules of this collationbooleancontains(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 that can be used as a proxy for strings being comparedjava.lang.StringgetCollationURI()Get the collation URI corresponding to this collationjava.text.CollationKeygetJavaCollationKey(java.lang.String source)Factory method to create a CollationKey that can be used as a proxy for string comparisons under this collationjava.util.PropertiesgetProperties()Get the properties of the collationjava.text.RuleBasedCollatorgetRuleBasedCollator()Get the underlying Java Collator objectintgetStrength()Get the strength of the collation (primary, secondary, tertiary, etc)inthashCode()Get a hash code used to compare two collations.voidsetStrength(int newStrength)Set the strength of the collation (primary, secondary, tertiary, etc)booleanstartsWith(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
-
UcaCollatorUsingJava
public UcaCollatorUsingJava(java.lang.String uri) throws XPathExceptionCreate a collation from a given collation URI- Parameters:
uri- the collation URI, in the format defined in the W3C Functions and Operators specification- Throws:
XPathException- if the collation URI does not conform to the W3C rules, or if it requires features that Saxon-HE does not support
-
-
Method Detail
-
getRuleBasedCollator
public java.text.RuleBasedCollator getRuleBasedCollator()
Get the underlying Java Collator object- Returns:
- the underlying Java Collator
-
getJavaCollationKey
public java.text.CollationKey getJavaCollationKey(java.lang.String source)
Factory method to create a CollationKey that can be used as a proxy for string comparisons under this collation- Parameters:
source- the string whose CollationKey is required- Returns:
- a CollationKey with the property that two collation keys are equal (according
to its
Object.equals(Object)method if their corresponding strings are considered to be equal under this collation
-
hashCode
public int hashCode()
Get a hash code used to compare two collations. (Probably not used.)- Overrides:
hashCodein classjava.lang.Object- Returns:
- a suitable hash code
-
getProperties
public java.util.Properties getProperties()
Get the properties of the collation- Returns:
- the properties of the collation
-
setStrength
public void setStrength(int newStrength)
Set the strength of the collation (primary, secondary, tertiary, etc)- Parameters:
newStrength- the strength
-
getStrength
public int getStrength()
Get the strength of the collation (primary, secondary, tertiary, etc)- Returns:
- the strength
-
comparesEqual
public boolean comparesEqual(java.lang.CharSequence s1, java.lang.CharSequence s2)Ask whether two strings are considered equal under this collation- Specified by:
comparesEqualin interfaceStringCollator- Parameters:
s1- the first strings2- the second string- Returns:
- true if the strings are considered equal
-
getCollationURI
public java.lang.String getCollationURI()
Get the collation URI corresponding to this collation- Specified by:
getCollationURIin interfaceStringCollator- Returns:
- the collation URI
-
compareStrings
public int compareStrings(java.lang.CharSequence o1, java.lang.CharSequence o2)Compare two strings for equality or ordering under the rules of this collation- Specified by:
compareStringsin interfaceStringCollator- Parameters:
o1- the first stringo2- the second string- Returns:
- -1, 0, or +1 according to the relative ordering of the strings
-
getCollationKey
public AtomicMatchKey getCollationKey(java.lang.CharSequence s)
Get a collation key that can be used as a proxy for strings being compared- Specified by:
getCollationKeyin interfaceStringCollator- Parameters:
s- the string whose collation key is required- Returns:
- a 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
-
-