public class

CompoundComparator

extends Object
implements Serializable Comparator<T>
java.lang.Object
   ↳ org.springframework.util.comparator.CompoundComparator<T>

Class Overview

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.

Summary

Public Constructors
CompoundComparator()
Construct a CompoundComparator with initially no Comparators.
CompoundComparator(Comparator[] comparators)
Construct a CompoundComparator from the Comparators in the provided array.
Public Methods
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, boolean ascending)
Replace the Comparator at the given index using the given sort order.
void setComparator(int index, Comparator<T> comparator)
Replace the Comparator at the given index.
void setDescendingOrder(int index)
Change the sort order at the given index to descending sort.
String toString()
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.util.Comparator

Public Constructors

public CompoundComparator ()

Also: SpringCore

Construct a CompoundComparator with initially no Comparators. Clients must add at least one Comparator before calling the compare method or an IllegalStateException is thrown.

public CompoundComparator (Comparator[] comparators)

Also: SpringCore

Construct a CompoundComparator from the Comparators in the provided array.

All Comparators will default to ascending sort order, unless they are InvertibleComparators.

Parameters
comparators the comparators to build into a compound comparator

Public Methods

public void addComparator (Comparator<T> comparator)

Also: SpringCore

Add a Comparator to the end of the chain.

The Comparator will default to ascending sort order, unless it is a InvertibleComparator.

Parameters
comparator the Comparator to add to the end of the chain

public void addComparator (Comparator<T> comparator, boolean ascending)

Also: SpringCore

Add a Comparator to the end of the chain using the provided sort order.

Parameters
comparator the Comparator to add to the end of the chain
ascending the sort order: ascending (true) or descending (false)

public int compare (T o1, T o2)

Also: SpringCore

public boolean equals (Object obj)

public int getComparatorCount ()

Also: SpringCore

Returns the number of aggregated comparators.

public int hashCode ()

public void invertOrder ()

Also: SpringCore

Invert the sort order of each sort definition contained by this compound comparator.

public void invertOrder (int index)

Also: SpringCore

Invert the sort order of the sort definition at the specified index.

Parameters
index the index of the comparator to invert

public void setAscendingOrder (int index)

Also: SpringCore

Change the sort order at the given index to ascending.

Parameters
index the index of the comparator to change

public void setComparator (int index, Comparator<T> comparator, boolean ascending)

Also: SpringCore

Replace the Comparator at the given index using the given sort order.

Parameters
index the index of the Comparator to replace
comparator the Comparator to place at the given index
ascending the sort order: ascending (true) or descending (false)

public void setComparator (int index, Comparator<T> comparator)

Also: SpringCore

Replace the Comparator at the given index.

The Comparator will default to ascending sort order, unless it is a InvertibleComparator.

Parameters
index the index of the Comparator to replace
comparator the Comparator to place at the given index

public void setDescendingOrder (int index)

Also: SpringCore

Change the sort order at the given index to descending sort.

Parameters
index the index of the comparator to change

public String toString ()