01: /*
02: * @(#)PnutsComparator.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.lib;
10:
11: import java.util.Comparator;
12: import pnuts.lang.Runtime;
13: import pnuts.lang.Context;
14:
15: /**
16: * A Comparator based on Pnuts comparison operators '<', '>', '==', '<=', and '>='.
17: */
18: public class PnutsComparator implements Comparator {
19:
20: private boolean reverse;
21: private Context context;
22:
23: public PnutsComparator(Context context) {
24: this (context, false);
25: }
26:
27: /**
28: * @param reverse If true, sort in reverse order.
29: */
30: public PnutsComparator(Context context, boolean reverse) {
31: this .context = context;
32: this .reverse = reverse;
33: }
34:
35: /**
36: * Compares its two arguments for order.
37: */
38: public int compare(Object o1, Object o2) {
39: if (reverse) {
40: return Runtime.compareTo(o2, o1);
41: } else {
42: return Runtime.compareTo(o1, o2);
43: }
44: }
45: }
|