Added a REVERSE_COMPARABLE comparator,
removed the obsolete STRING comparator. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1481 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -27,11 +27,30 @@ import java.util.Comparator;
|
|||||||
*/
|
*/
|
||||||
public class Comparators
|
public class Comparators
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* A comparator that can be used to reverse the results of another
|
||||||
|
* comparator.
|
||||||
|
*/
|
||||||
|
public static class ReversingComparator implements Comparator
|
||||||
|
{
|
||||||
|
public ReversingComparator (Comparator reversable)
|
||||||
|
{
|
||||||
|
_reversable = reversable;
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited from interface Comparator
|
||||||
|
public int compare (Object o1, Object o2)
|
||||||
|
{
|
||||||
|
return _reversable.compare(o2, o1); // switching the order
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Comparator _reversable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A comparator that compares {@link Comparable} instances.
|
* A comparator that compares {@link Comparable} instances.
|
||||||
*/
|
*/
|
||||||
public static final Comparator COMPARABLE = new Comparator()
|
public static final Comparator COMPARABLE = new Comparator() {
|
||||||
{
|
|
||||||
public int compare (Object o1, Object o2)
|
public int compare (Object o1, Object o2)
|
||||||
{
|
{
|
||||||
if (o1 == o2) {
|
if (o1 == o2) {
|
||||||
@@ -45,7 +64,9 @@ public class Comparators
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A comparator that compares {@link String} instances.
|
* A comparator that imposes a reverse ordering on {@link Comparable}
|
||||||
|
* instances.
|
||||||
*/
|
*/
|
||||||
public static final Comparator STRING = COMPARABLE;
|
public static final Comparator REVERSE_COMPARABLE =
|
||||||
|
new ReversingComparator(COMPARABLE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user