net.sf.saxon.sort

Class AlphanumericCollator

public class AlphanumericCollator extends Object implements StringCollator, Serializable

A Comparer that treats strings as an alternating sequence of alpha parts and numeric parts. The alpha parts are compared using a base collation supplied as a parameter; the numeric parts are compared numerically. "Numeric" here means a sequence of consecutive ASCII digits 0-9.

Note: this StringCollator produces an ordering that is not compatible with equals().

Constructor Summary
AlphanumericCollator(StringCollator base)
Create an alphanumeric collation
Method Summary
booleancomparesEqual(String s1, String s2)
Compare two strings for equality.
intcompareStrings(String s1, String s2)
Compare two objects.
ObjectgetCollationKey(String s)
Get a collation key for two Strings.

Constructor Detail

AlphanumericCollator

public AlphanumericCollator(StringCollator base)
Create an alphanumeric collation

Parameters: base the collation used to compare the alphabetic parts of the string

Method Detail

comparesEqual

public boolean comparesEqual(String s1, String 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

Parameters: s1 the first string s2 the second string

Returns: true if and only if the strings are considered equal,

compareStrings

public int compareStrings(String s1, String s2)
Compare two objects.

Returns: <0 if a0 if a>b

getCollationKey

public Object getCollationKey(String s)
Get a collation key for two Strings. 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.