01: package clime.messadmin.utils;
02:
03: import java.util.Comparator;
04:
05: /**
06: * Comparator which reverse the sort order
07: * @author Cédrik LIME
08: */
09: public class ReverseComparator implements Comparator {
10: protected Comparator comparator;
11:
12: /**
13: *
14: */
15: public ReverseComparator(Comparator comparator) {
16: super ();
17: this .comparator = comparator;
18: }
19:
20: /** {@inheritDoc}
21: */
22: public int compare(Object o1, Object o2) {
23: if (comparator != null) {
24: return comparator.compare(o2, o1);
25: } else if (o2 instanceof Comparable) {
26: return ((Comparable) o2).compareTo(o1);
27: } else if (o1 instanceof Comparable) {
28: return -((Comparable) o1).compareTo(o2);
29: } else {
30: throw new ClassCastException();
31: }
32: }
33: }
|