org.inria.ns.reflex.processor.xcl
Class SortFunction

java.lang.Object
  extended by org.inria.ns.reflex.xml.xpath.XPathFunction.NamedXPathFunction
      extended by org.inria.ns.reflex.processor.xcl.SortFunction
All Implemented Interfaces:
DeferrableFunction, XPathFunction

public class SortFunction
extends XPathFunction.NamedXPathFunction
implements XPathFunction, DeferrableFunction

The xcl:sort() function sorts a list regarding one or more sorting criteria.

Each sorting criteria that need to be in descending order may be wrapped by the xcl:reverse() function.

Author:
Philippe Poulard
See Also:
ReverseFunction

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.xml.xpath.XPathFunction
XPathFunction.NamedXPathFunction
 
Constructor Summary
SortFunction()
           
 
Method Summary
 Object evaluate(XPathContext context, List args)
          Perform a sort.
 boolean isDeferred(int argument)
          The first argument is not deferred, others are deferred.
static int smartCompare(XPathContext context, Object v1, Object v2)
          Smart comparison of 2 objects : check if they are comparable, then if they are nodes with PSVI typed datas, then compare their values.
 
Methods inherited from class org.inria.ns.reflex.xml.xpath.XPathFunction.NamedXPathFunction
getQName, setQName
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.inria.ns.reflex.xml.xpath.XPathFunction
getQName
 

Constructor Detail

SortFunction

public SortFunction()
Method Detail

evaluate

public Object evaluate(XPathContext context,
                       List args)
                throws XPathFunctionException
Perform a sort.

Specified by:
evaluate in interface XPathFunction
Parameters:
context - The context when evaluating this function : XPath variables, current node, etc.
args - The arguments of this function :
  • the first is the list of items to sort,
  • the others are the sorting criteria.
Returns:
The sorted result.
Throws:
XPathFunctionException - When this function fails to be evaluated.
See Also:
XPathFunction.evaluate(org.inria.ns.reflex.xml.xpath.XPathContext, java.util.List)

isDeferred

public boolean isDeferred(int argument)
The first argument is not deferred, others are deferred.

Specified by:
isDeferred in interface DeferrableFunction
Parameters:
argument - The index of the argument.
Returns:
false if argument=0, true otherwise.
See Also:
DeferrableFunction.isDeferred(int)

smartCompare

public static int smartCompare(XPathContext context,
                               Object v1,
                               Object v2)
Smart comparison of 2 objects : check if they are comparable, then if they are nodes with PSVI typed datas, then compare their values. Best effort is made for numeric values of different types, including BigDecimal and BigInteger.

Parameters:
context - The XPath context.
o1 - The first object to compare.
o2 - The second object to compare.
Returns:
A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.