|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.util.comparator.CompoundComparator<T>
public class CompoundComparator<T>
A comparator that chains a sequence of one or more more Comparators.
A compound comparator calls each Comparator in sequence until a single Comparator returns a non-zero result, or the comparators are exhausted and zero is returned.
This facilitates in-memory sorting similar to multi-column sorting in SQL. The order of any single Comparator in the list can also be reversed.
Constructor Summary | |
---|---|
CompoundComparator()
Construct a CompoundComparator with initially no Comparators. |
|
CompoundComparator(Comparator[] comparators)
Construct a CompoundComparator from the Comparators in the provided array. |
Method Summary | |
---|---|
void |
addComparator(Comparator<T> comparator)
Add a Comparator to the end of the chain. |
void |
addComparator(Comparator<T> comparator,
boolean ascending)
Add a Comparator to the end of the chain using the provided sort order. |
int |
compare(T o1,
T o2)
|
boolean |
equals(Object obj)
|
int |
getComparatorCount()
Returns the number of aggregated comparators. |
int |
hashCode()
|
void |
invertOrder()
Invert the sort order of each sort definition contained by this compound comparator. |
void |
invertOrder(int index)
Invert the sort order of the sort definition at the specified index. |
void |
setAscendingOrder(int index)
Change the sort order at the given index to ascending. |
void |
setComparator(int index,
Comparator<T> comparator)
Replace the Comparator at the given index. |
void |
setComparator(int index,
Comparator<T> comparator,
boolean ascending)
Replace the Comparator at the given index using the given sort order. |
void |
setDescendingOrder(int index)
Change the sort order at the given index to descending sort. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CompoundComparator()
public CompoundComparator(Comparator[] comparators)
All Comparators will default to ascending sort order, unless they are InvertibleComparators.
comparators
- the comparators to build into a compound comparatorInvertibleComparator
Method Detail |
---|
public void addComparator(Comparator<T> comparator)
The Comparator will default to ascending sort order, unless it is a InvertibleComparator.
comparator
- the Comparator to add to the end of the chainInvertibleComparator
public void addComparator(Comparator<T> comparator, boolean ascending)
comparator
- the Comparator to add to the end of the chainascending
- the sort order: ascending (true) or descending (false)public void setComparator(int index, Comparator<T> comparator)
The Comparator will default to ascending sort order, unless it is a InvertibleComparator.
index
- the index of the Comparator to replacecomparator
- the Comparator to place at the given indexInvertibleComparator
public void setComparator(int index, Comparator<T> comparator, boolean ascending)
index
- the index of the Comparator to replacecomparator
- the Comparator to place at the given indexascending
- the sort order: ascending (true) or descending (false)public void invertOrder()
public void invertOrder(int index)
index
- the index of the comparator to invertpublic void setAscendingOrder(int index)
index
- the index of the comparator to changepublic void setDescendingOrder(int index)
index
- the index of the comparator to changepublic int getComparatorCount()
public int compare(T o1, T o2)
compare
in interface Comparator<T>
public boolean equals(Object obj)
equals
in interface Comparator<T>
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |