org.apache.jdo.impl.jdoql
Class OrderingComparator

java.lang.Object
  extended by org.apache.jdo.impl.jdoql.OrderingComparator
All Implemented Interfaces:
java.util.Comparator

public class OrderingComparator
extends java.lang.Object
implements java.util.Comparator

An instance of this class is used to compare two instances of Comparable based on the ordering expressions defined by a query tree. This instance holds references to a query tree, a tree walker and a memory query instance for this purpose.

Author:
Michael Watzek

Constructor Summary
OrderingComparator(TreeWalker walker, MemoryQuery nodeVisitor)
          Constructs an ordering comparator for a tree walker and a node visitor.
OrderingComparator(TreeWalker walker, MemoryQuery nodeVisitor, QueryTree queryTree)
          Constructs an ordering comparator for a tree walker, a node visitor and a query tree.
 
Method Summary
 int compare(java.lang.Object o1, java.lang.Object o2)
          Required method for implementing the interface Comparator.
 void setQueryTree(QueryTree queryTree)
          Sets the query tree for this ordering comparator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

OrderingComparator

public OrderingComparator(TreeWalker walker,
                          MemoryQuery nodeVisitor)
Constructs an ordering comparator for a tree walker and a node visitor. This comparator is not bound to a query tree. It can be bound to a query tree by calling method setQueryTree.

Parameters:
walker - the tree walker
nodeVisitor - the node visitor evaluating the ordering expressions

OrderingComparator

public OrderingComparator(TreeWalker walker,
                          MemoryQuery nodeVisitor,
                          QueryTree queryTree)
Constructs an ordering comparator for a tree walker, a node visitor and a query tree. This comparator is bound to that query tree.

Parameters:
walker - the tree walker
nodeVisitor - the node visitor evaluating the ordering expressions
queryTree - the query tree containing the ordering expressions
Method Detail

setQueryTree

public void setQueryTree(QueryTree queryTree)
Sets the query tree for this ordering comparator. Each ordering comparator can be bound to a query tree. The ordering expression list inside that query tree determines the ordering semantics of this comparator.

Parameters:
queryTree - the query tree containing the ordering expression list

compare

public int compare(java.lang.Object o1,
                   java.lang.Object o2)
Required method for implementing the interface Comparator. This method returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second argument. If this instance is not bound to a query tree or, if the query tree bound to this instance does not have any ordering expression, then argument o1 is less than argument o2 by definition.

Specified by:
compare in interface java.util.Comparator
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 are not instances of Comparable


Copyright © 2005-2012 Apache Software Foundation. All Rights Reserved.