live.dto
Class Thread.ThreadComparator

java.lang.Object
  extended bylive.dto.Thread.ThreadComparator
All Implemented Interfaces:
Comparator
Direct Known Subclasses:
Thread.ComparatorByDescription, Thread.ComparatorByResult, Thread.ComparatorByTimeEnded, Thread.ComparatorByTimeStarted
Enclosing class:
Thread

public abstract static class Thread.ThreadComparator
extends Object
implements Comparator

This is a base class for the different comparator styles. See ShowStatusAction for a use of this and why it is necessary for clean code there.


Field Summary
private  int reverse
           
 
Constructor Summary
Thread.ThreadComparator()
          Makes a comparator that will not reverse its decision
Thread.ThreadComparator(boolean reverseOrder)
          Makes a comparator that will optionally reverse its decision
 
Method Summary
 int compare(Object o1, Object o2)
          This makes sure that o1 and o2 are both threads, calls the abstract compare(Thread, Thread), and possibly reverses that decision.
abstract  int compare(Thread t1, Thread t2)
          This does the actual comparison.
 Thread.ThreadComparator setReverse(boolean reverseOrder)
          Returns this so it can be chained easily, e.g.
 
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
 

Field Detail

reverse

private int reverse
Constructor Detail

Thread.ThreadComparator

public Thread.ThreadComparator(boolean reverseOrder)
Makes a comparator that will optionally reverse its decision

Parameters:
reverseOrder - Order in reverse of what it otherwise would?

Thread.ThreadComparator

public Thread.ThreadComparator()
Makes a comparator that will not reverse its decision

Method Detail

setReverse

public Thread.ThreadComparator setReverse(boolean reverseOrder)
Returns this so it can be chained easily, e.g. foo(myComparator.setReverse(true)). Again, simplifies code. Note that the reverseOrder param ignores the current state of the object. So calling setReverse(true) on a comparator that is reversed will not make it work in its normal order again.

Parameters:
reverseOrder - Whether to reverse the output
Returns:
The comparator so it can be chained as above

compare

public final int compare(Object o1,
                         Object o2)
This makes sure that o1 and o2 are both threads, calls the abstract compare(Thread, Thread), and possibly reverses that decision.

Specified by:
compare in interface Comparator
Parameters:
o1 - The first object to compare
o2 - The second object to compare
Returns:
0 if o1==o2, a negative number if o1o2
See Also:
Comparator.compare(java.lang.Object, java.lang.Object)

compare

public abstract int compare(Thread t1,
                            Thread t2)
This does the actual comparison. Note that this should ignore any reversing option, because compare(Object, Object) calls this and reverses the return itself.

Parameters:
t1 - The first thread to compare
t2 - The second thread to compare
Returns:
0 if t1==t2, a negative number if t1t2
See Also:
Comparator.compare(java.lang.Object, java.lang.Object)


Copyright © 2005