Package net.sf.saxon.expr.sort
Class SimpleCollation
- java.lang.Object
-
- net.sf.saxon.expr.sort.SimpleCollation
-
- All Implemented Interfaces:
StringCollator
- Direct Known Subclasses:
RuleBasedSubstringMatcher
public class SimpleCollation extends java.lang.Object implements StringCollator
A simple collation that just wraps a supplied Comparator
-
-
Constructor Summary
Constructors Constructor Description SimpleCollation(java.lang.String uri, java.util.Comparator<? super java.lang.String> comparator)
Create a SimpleCollation
-
Method Summary
All 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)
Compares its two arguments for order.AtomicMatchKey
getCollationKey(UnicodeString s)
Get a collation key for a String.java.lang.String
getCollationURI()
Get the collation URI.java.util.Comparator<? super java.lang.String>
getComparator()
Get the underlying comparatorSubstringMatcher
getSubstringMatcher()
If possible, get a collator capable of substring matching (in functions such as fn:contains()).void
setComparator(java.util.Comparator<? super java.lang.String> comparator)
Set the underlying comparator-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.lib.StringCollator
isEqualToEmpty
-
-
-
-
Method Detail
-
getCollationURI
public java.lang.String getCollationURI()
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)
Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.- Specified by:
compareStrings
in interfaceStringCollator
- Parameters:
o1
- the first object to be compared.o2
- the second object to be compared.- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
- Throws:
java.lang.ClassCastException
- if the arguments' types prevent them from being compared by this Comparator.
-
comparesEqual
public boolean comparesEqual(UnicodeString s1, UnicodeString s2)
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,
-
getComparator
public java.util.Comparator<? super java.lang.String> getComparator()
Get the underlying comparator- Returns:
- the underlying comparator
-
setComparator
public void setComparator(java.util.Comparator<? super java.lang.String> comparator)
Set the underlying comparator- Parameters:
comparator
- the underlying comparator
-
getCollationKey
public AtomicMatchKey getCollationKey(UnicodeString s)
Get a collation key for a String. The essential property of collation keys is that if two values are equal under the collation, then the collation keys are compare correctly under the equals() method.- Specified by:
getCollationKey
in interfaceStringCollator
- Parameters:
s
- the string whose collation key is required- Returns:
- the collation key
-
getSubstringMatcher
public SubstringMatcher getSubstringMatcher()
If possible, get a collator capable of substring matching (in functions such as fn:contains()).- Returns:
- a collator suitable for substring matching, or null if none is available
-
-