01: /*
02: * Helma License Notice
03: *
04: * The contents of this file are subject to the Helma License
05: * Version 2.0 (the "License"). You may not use this file except in
06: * compliance with the License. A copy of the License is available at
07: * http://adele.helma.org/download/helma/license.txt
08: *
09: * Copyright 1998-2003 Helma Software. All Rights Reserved.
10: *
11: * $RCSfile$
12: * $Author: root $
13: * $Revision: 8604 $
14: * $Date: 2007-09-28 15:16:38 +0200 (Fre, 28 Sep 2007) $
15: */
16:
17: package helma.doc;
18:
19: import java.util.Comparator;
20:
21: /**
22: *
23: */
24: public class DocComparator implements Comparator {
25: public static final int BY_TYPE = 0;
26: public static final int BY_NAME = 1;
27: int mode;
28: DocElement docEl;
29:
30: /**
31: * Creates a new DocComparator object.
32: *
33: * @param mode ...
34: * @param docEl ...
35: */
36: public DocComparator(int mode, DocElement docEl) {
37: this .mode = mode;
38: this .docEl = docEl;
39: }
40:
41: /**
42: * Creates a new DocComparator object.
43: *
44: * @param docEl ...
45: */
46: public DocComparator(DocElement docEl) {
47: this .mode = 0;
48: this .docEl = docEl;
49: }
50:
51: /**
52: *
53: *
54: * @param obj1 ...
55: * @param obj2 ...
56: *
57: * @return ...
58: */
59: public int compare(Object obj1, Object obj2) {
60: DocElement e1 = (DocElement) obj1;
61: DocElement e2 = (DocElement) obj2;
62:
63: if ((mode == BY_TYPE) && (e1.getType() > e2.getType())) {
64: return 1;
65: } else if ((mode == BY_TYPE) && (e1.getType() < e2.getType())) {
66: return -1;
67: } else {
68: return e1.name.compareTo(e2.name);
69: }
70: }
71:
72: /**
73: *
74: *
75: * @param obj ...
76: *
77: * @return ...
78: */
79: public boolean equals(Object obj) {
80: DocElement el = (DocElement) obj;
81:
82: if (el.name.equals(docEl.name)
83: && (el.getType() == docEl.getType())) {
84: return true;
85: } else {
86: return false;
87: }
88: }
89: }
|