01: package com.salmonllc.html;
02:
03: import java.sql.Time;
04: import java.sql.Timestamp;
05:
06: import com.salmonllc.util.VectorSort;
07:
08: /**
09: * @author srufle
10: *
11: * To change this generated comment edit the template variable "typecomment":
12: * Window>Preferences>Java>Templates.
13: * To enable and disable the creation of type comments go to
14: * Window>Preferences>Java>Code Generation.
15: */
16:
17: /**
18: * Claudio Pi (4-01-2003) Inner class to allow drop down options sorting.
19: */
20: public class OptionsSort extends VectorSort {
21: /*Claudio Pi (4-01-2003)
22: Possible sort directions*/
23: public static final int SORT_ASC = 0;
24: public static final int SORT_DES = 1;
25:
26: private int _sortDir = SORT_ASC;
27:
28: public void setSortDir(int dir) {
29: this ._sortDir = dir;
30: }
31:
32: public boolean compare(Object o1, Object o2) {
33: boolean result = false;
34:
35: //Compares the values not the keys.
36: Object toCompare1 = ((HtmlOption) o1).getDisplay();
37: Object toCompare2 = ((HtmlOption) o2).getDisplay();
38:
39: if (toCompare1 instanceof String
40: && toCompare2 instanceof String) {
41: result = (((String) toCompare1)
42: .compareTo((String) toCompare2) > 0);
43: }
44:
45: // srufle 04-03-2003: I do not think we need anything but the string comparision,but i am leaving it in for now
46: if (toCompare1 instanceof Integer
47: && toCompare2 instanceof Integer) {
48: result = (((Integer) toCompare1)
49: .compareTo((Integer) toCompare2) > 0);
50: }
51:
52: if (toCompare1 instanceof Timestamp
53: && toCompare2 instanceof Timestamp) {
54: result = (((Timestamp) toCompare1)
55: .compareTo((Timestamp) toCompare2) > 0);
56: }
57:
58: if (toCompare1 instanceof Time && toCompare2 instanceof Time) {
59: result = (((Time) toCompare1).compareTo((Time) toCompare2) > 0);
60: }
61:
62: if (toCompare1 instanceof java.sql.Date
63: && toCompare2 instanceof java.sql.Date) {
64: result = (((java.sql.Date) toCompare1)
65: .compareTo((java.sql.Date) toCompare2) > 0);
66: }
67:
68: if (toCompare1 instanceof Double
69: && toCompare2 instanceof Double) {
70: result = (((Double) toCompare1)
71: .compareTo((Double) toCompare2) > 0);
72: }
73:
74: if (toCompare1 instanceof Short && toCompare2 instanceof Short) {
75: result = (((Short) toCompare1)
76: .compareTo((Short) toCompare2) > 0);
77: }
78:
79: if (toCompare1 instanceof Long && toCompare2 instanceof Long) {
80: result = (((Long) toCompare1).compareTo((Long) toCompare2) > 0);
81: }
82:
83: if (toCompare1 instanceof Float && toCompare2 instanceof Float) {
84: result = (((Float) toCompare1)
85: .compareTo((Float) toCompare2) > 0);
86: }
87:
88: if (_sortDir == SORT_DES) {
89: return result;
90: } else {
91: return !result;
92: }
93: }
94: }
|