01: package org.incava.util;
02:
03: import java.util.Comparator;
04:
05: /**
06: * A comparator for reversed order.
07: */
08: public class ReverseComparator implements Comparator {
09: /**
10: * Compares o2 to o1. <code>o2</code> must implement Comparable.
11: */
12: public int compare(Object o1, Object o2) {
13: if (o2 instanceof Comparable) {
14: Comparable c2 = (Comparable) o2;
15: return c2.compareTo(o1);
16: } else {
17: throw new IllegalArgumentException("argument "
18: + o2.getClass() + " does not implement Comparable");
19: }
20: }
21:
22: /**
23: * Returns <code>o1.equals(o2)</code>.
24: */
25: public boolean equals(Object o1, Object o2) {
26: return o1.equals(o2);
27: }
28: }
|