Class NumericComparer

java.lang.Object
net.sf.saxon.sort.NumericComparer
All Implemented Interfaces:
Serializable, Comparator

public class NumericComparer extends Object implements Comparator, Serializable
A Comparer used for comparing sort keys when data-type="number". The items to be compared are converted to numbers, and the numbers are then compared directly.

This class is used in XSLT only, so there is no need to handle XQuery's "empty least" vs "empty greatest" options.

Author:
Michael H. Kay
See Also:
  • Method Details

    • getInstance

      public static NumericComparer getInstance()
    • compare

      public int compare(Object a, Object b)
      Compare two Items by converting them to numbers and comparing the numeric values. If either value cannot be converted to a number, it is treated as NaN, and compares less that the other (two NaN values compare equal).
      Specified by:
      compare in interface Comparator
      Parameters:
      a - the first Item to be compared.
      b - the second Item to be compared.
      Returns:
      invalid input: '<'0 if ainvalid input: '<'b, 0 if a=b, >0 if a>b
      Throws:
      ClassCastException - if the objects are not Items