Class ListNestedSortComparator<T extends Comparable<? super T>>
- java.lang.Object
-
- org.teiid.query.processor.relational.ListNestedSortComparator<T>
-
- All Implemented Interfaces:
Comparator<List<T>>
public class ListNestedSortComparator<T extends Comparable<? super T>> extends Object implements Comparator<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
Constructors Constructor Description 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, List<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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(List<T> list1, List<T> list2)
Compares its two arguments for order.ListNestedSortComparator<T>
defaultNullOrder(ExecutionFactory.NullOrder order)
List<Boolean>
getOrderTypes()
int[]
getSortParameters()
boolean
isDistinct()
void
setDistinctIndex(int distinctIndex)
void
setNullOrdering(List<SortSpecification.NullOrdering> nullOrdering)
void
setOrderTypes(List<Boolean> orderTypes)
void
setSortParameters(int[] sortParameters)
-
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, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
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.
-
-
Method Detail
-
defaultNullOrder
public ListNestedSortComparator<T> defaultNullOrder(ExecutionFactory.NullOrder order)
-
isDistinct
public boolean isDistinct()
-
setDistinctIndex
public void setDistinctIndex(int distinctIndex)
-
setNullOrdering
public void setNullOrdering(List<SortSpecification.NullOrdering> nullOrdering)
-
compare
public int compare(List<T> list1, 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- -1 if object1 less than object 2
- 0 if object1 equal to object 2
- +1 if object1 greater than object 2
- Specified by:
compare
in interfaceComparator<T extends Comparable<? super T>>
- Parameters:
list1
- The first object being comparedlist2
- The second object being compared
-
getSortParameters
public int[] getSortParameters()
-
setSortParameters
public void setSortParameters(int[] sortParameters)
-
-