|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.aliasi.util.ReversibleMTFListComparator<E>
public class ReversibleMTFListComparator<E>
A ReversibleMTFListComparator contains an ordered list
of comparators, any member of which can be reversed or moved to the
front of the list. The result of comparison is defined to be the
first non-zero result from the contained comparators evaluated in
order, or zero if they all return zero. A reversible move-to-front
list comparator is constructed with an array of comparators, and
will be initialized with them in the order supplied and in their
original polarity (not reversed). At any point, a comparator may
be reversed using reverse(Comparator), or may be moved to
the front of the list with moveToFront(Comparator).
This class is useful for maintaining ordering on columns in tables, where the ordering of sort on a column may be reversed, and where sorts should be stable except for reordering the column in focus.
To provide concurrent access to reversible move-to-front list
comparators, they must be concurrent-read/single-write (CRSW)
locked, where the methods moveToFront(Comparator), and
reverse(Comparator) are writers, and the methods compare(Object,Object) and sort(Object[]) are readers.
Exclusive locking on all access suffices for safety, but the result
is not as live as CRSW synchronization.
Implementation Note: The original comparators are
maintained in a hash map, so their equality and hashcode methods
must be stable after construction of a list comparator. Having
comparators simply inherit implementations of Object.hashCode() and
Object.equals(Object) from Object suffices.
| Constructor Summary | |
|---|---|
ReversibleMTFListComparator(Comparator<? super E>[] comparators)
Construct a reversible move-to-front comparator containing reversible versions of the specified comparators. |
|
| Method Summary | ||
|---|---|---|
int |
compare(E obj1,
E obj2)
Compares the specified objects using this list comparator, returning a positive number if the first is greater than the second, a negative number if the first is less than the second, and zero if they are equal. |
|
void |
moveToFront(Comparator comparator)
Moves the specified comparator to the front of the list of comparators. |
|
void |
reverse(Comparator comparator)
Reverse the ordering on the specified comparator. |
|
|
sort(F[] xs)
Sort the specified array of objects using this 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 |
|---|
public ReversibleMTFListComparator(Comparator<? super E>[] comparators)
comparators - Comparators to use, in order.| Method Detail |
|---|
public void moveToFront(Comparator comparator)
comparator - Comparator to move to the front of the list.
IllegalArgumentException - If the comparator specified is
not one of the comparators supplied at construction time.public void reverse(Comparator comparator)
comparator - Comparator whose order is reversed.
IllegalArgumentException - If the comparator specified is
not one of the comparators supplied at construction time.
public int compare(E obj1,
E obj2)
compare in interface Comparator<E>obj1 - First object to compare.obj2 - Second object to compare.
public <F extends E> void sort(F[] xs)
xs - Array of objects to sort.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||