net.sf.jec.namedop
Class OrderByOperator

java.lang.Object
  extended bynet.sf.jec.Operator
      extended bynet.sf.jec.namedop.GroupOperator
          extended bynet.sf.jec.namedop.OrderByOperator

public class OrderByOperator
extends GroupOperator

OrderByOperator sorts a Collection of elements by applying the argument operator to each element and comparing between the resulting values. The sort mode can be ascendent (by default) or descendent. You can specify a sort mode for each argument operator by writting it just after the argument operator.

Syntax: orderby(argOperator, [sortMode], [argOperator, [sortMode]])

Examples:

1. This one orders ascending by the accessor operators customerNumber (primary field) and customerAge (secondary field).

orderby(customerNumber, customerAge)

2. This one orders by the same criteria but descending. This example ilustrates where to specify the sort mode when you want to apply the same for all the argument operators. You must place it as the last argument.

orderby(customerNumber, customerAge, 'desc')

3. This one orders the primary field descending and the secondary ascending.

orderby(customerNumber, 'desc', customerAge, 'asc')

4. A given sort mode applies to all of the operator arguments preceeding it until another sort mode is found. In this example, the two last argOperators are sorted ascending and the first is sorted descending.
Think that the tuple is processed from the right to the left and the sort modes are switches that fix the current sort mode.

orderby(customerNumber, 'desc', customerAge, customerWeight, 'asc')

In this case we could remove the last 'asc' argument because this is the default sort mode. The result would be the same:

orderby(customerNumber, 'desc', customerAge, customerWeight)

But you should always specify explicitly the desired order.

Author:
mballesteros

Field Summary
 
Fields inherited from class net.sf.jec.Operator
argOps, nestedOp, showFunctionString
 
Constructor Summary
OrderByOperator()
          Creates a new OrderByOperator
 
Method Summary
protected  java.lang.Object directMap(java.lang.Object rootCtx, java.lang.Object ctx)
          Returns the associated value to the given context and root context
 java.lang.String toExpressionString()
          Returns an expression String representation for this operator
 java.lang.String toFunctionString()
          Returns a function representation String for this operator
 
Methods inherited from class net.sf.jec.namedop.GroupOperator
applyToGroup
 
Methods inherited from class net.sf.jec.Operator
apply, setArgumentOperators, setNestedOperator, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrderByOperator

public OrderByOperator()
Creates a new OrderByOperator

Method Detail

toFunctionString

public java.lang.String toFunctionString()
Returns a function representation String for this operator

Specified by:
toFunctionString in class Operator
Returns:
representation String for this operator

toExpressionString

public java.lang.String toExpressionString()
Returns an expression String representation for this operator

Specified by:
toExpressionString in class Operator
Returns:
String representation for this operator

directMap

protected java.lang.Object directMap(java.lang.Object rootCtx,
                                     java.lang.Object ctx)
                              throws EvaluationException
Returns the associated value to the given context and root context

Specified by:
directMap in class Operator
Parameters:
rootCtx - The root context, needed for operators that require expression evaluation from root point. Example: Indexer operators
ctx - The current context where the operator will work over
Returns:
The result of applying THIS Operator to the given context.
Throws:
EvaluationException - when the operator can not be applied to the given context.


Copyright © 2003 SourceForge. All Rights Reserved.