org.teiid.query.processor.relational
Class ListNestedSortComparator<T extends java.lang.Comparable<? super T>>

java.lang.Object
  extended by org.teiid.query.processor.relational.ListNestedSortComparator<T>
All Implemented Interfaces:
java.util.Comparator<java.util.List<T>>

public class ListNestedSortComparator<T extends java.lang.Comparable<? super T>>
extends java.lang.Object
implements java.util.Comparator<java.util.List<T>>

This class can be used for comparing lists of elements, when the fields to be sorted on and the comparison mechanism are dynamically specified.

Typically, the lists are records in a collection that is to be sorted.

Example

    Records...
      { "a1", "b1", "c1" } 
      { "a1", "b1", "c2" }
      { "a1", "b2", "c1" }
      { "a1", "b2", "c2" }
      { "a2", "b1", "c1" } 
      { "a2", "b1", "c2" } 
      { "a2", "b2", "c1" } 
      { "a2", "b2", "c2" }

    Records sorted in ascending order on columns 0, 2...
      { "a1", "b1", "c1" } 
      { "a1", "b2", "c1" }
      { "a1", "b2", "c2" }
      { "a1", "b1", "c2" }
      { "a2", "b1", "c1" } 
      { "a2", "b2", "c1" } 
      { "a2", "b1", "c2" } 
      { "a2", "b2", "c2" } 
 


Constructor Summary
ListNestedSortComparator(int[] sortParameters)
          Constructs an instance of this class given the indicies of the parameters to sort on, and whether the sort should be in ascending or descending order.
ListNestedSortComparator(int[] sortParameters, boolean ascending)
          Constructs an instance of this class given the indicies of the parameters to sort on, and whether the sort should be in ascending or descending order.
ListNestedSortComparator(int[] sortParameters, java.util.List<java.lang.Boolean> orderTypes)
          Constructs an instance of this class given the indicies of the parameters to sort on, and orderList used to determine the order in which each column is sorted.
 
Method Summary
 int compare(java.util.List<T> list1, java.util.List<T> list2)
          Compares its two arguments for order.
 boolean isDistinct()
           
 void setDistinctIndex(int distinctIndex)
           
 void setNullOrdering(java.util.List<SortSpecification.NullOrdering> nullOrdering)
           
 
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

ListNestedSortComparator

public ListNestedSortComparator(int[] sortParameters)
Constructs an instance of this class given the indicies of the parameters to sort on, and whether the sort should be in ascending or descending order.


ListNestedSortComparator

public ListNestedSortComparator(int[] sortParameters,
                                boolean ascending)
Constructs an instance of this class given the indicies of the parameters to sort on, and whether the sort should be in ascending or descending order.


ListNestedSortComparator

public ListNestedSortComparator(int[] sortParameters,
                                java.util.List<java.lang.Boolean> orderTypes)
Constructs an instance of this class given the indicies of the parameters to sort on, and orderList used to determine the order in which each column is sorted.

Method Detail

isDistinct

public boolean isDistinct()

setDistinctIndex

public void setDistinctIndex(int distinctIndex)

setNullOrdering

public void setNullOrdering(java.util.List<SortSpecification.NullOrdering> nullOrdering)

compare

public int compare(java.util.List<T> list1,
                   java.util.List<T> list2)
Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The compare method returns

Specified by:
compare in interface java.util.Comparator<java.util.List<T extends java.lang.Comparable<? super T>>>
Parameters:
o1 - The first object being compared
o2 - The second object being compared


Copyright © 2010. All Rights Reserved.