01: package com.xoetrope.carousel.langed;
02:
03: import java.util.Comparator;
04:
05: /**
06: * <p>Title: LanguageEditor</p>
07: * <p>Description: Language Resource Translation Utility</p>
08: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
09: * the GNU Public License (GPL), please see license.txt for more details. If
10: * you make commercial use of this software you must purchase a commercial
11: * license from Xoetrope.</p>
12: * <p> $Revision: 1.3 $</p>
13: * @author Luan O'Carroll
14: */
15:
16: class LangComparator implements Comparator {
17: public static final int NUM_ASCENDING = 0;
18: public static final int NUM_DESCENDING = 1;
19: public static final int ALPHA_ASCENDING = 2;
20: public static final int ALPHA_DESCENDING = 3;
21:
22: private int mode = NUM_ASCENDING;
23: private int returnCode = 1;
24:
25: LangComparator(int m) {
26: mode = m;
27:
28: // For a descending ordering reverse the return code
29: if ((mode == NUM_DESCENDING) || (mode == ALPHA_DESCENDING))
30: returnCode = -1;
31: }
32:
33: /**
34: * Copares to LangItems
35: * @param a
36: * @param b
37: * @return
38: */
39: public int compare(Object a, Object b) {
40: if (((LangItem) a).id == ((LangItem) b).id)
41: return 0;
42: else if (mode < ALPHA_ASCENDING) {
43: if (((LangItem) a).id < ((LangItem) b).id)
44: return -returnCode;
45: else
46: return returnCode;
47: } else {
48: if (((LangItem) a).langStr
49: .compareToIgnoreCase(((LangItem) b).langStr) < 0)
50: return -returnCode;
51: else
52: return returnCode;
53: }
54: }
55: }
|