01: package net.sf.saxon.sort;
02:
03: import net.sf.saxon.om.NodeInfo;
04:
05: import java.io.Serializable;
06:
07: /**
08: * A Comparer used for comparing nodes in document order. This
09: * comparer is used when there is no guarantee that the nodes being compared
10: * come from the same document
11: *
12: * @author Michael H. Kay
13: *
14: */
15:
16: public final class GlobalOrderComparer implements NodeOrderComparer,
17: Serializable {
18:
19: private static GlobalOrderComparer instance = new GlobalOrderComparer();
20:
21: /**
22: * Get an instance of a GlobalOrderComparer. The class maintains no state
23: * so this returns the same instance every time.
24: */
25:
26: public static GlobalOrderComparer getInstance() {
27: return instance;
28: }
29:
30: public int compare(NodeInfo a, NodeInfo b) {
31: if (a == b) {
32: return 0;
33: }
34: int d1 = a.getDocumentNumber();
35: int d2 = b.getDocumentNumber();
36: if (d1 == d2) {
37: return a.compareOrder(b);
38: }
39: return d1 - d2;
40: // NodeInfo r1 = a.getRoot();
41: // NodeInfo r2 = b.getRoot();
42: // if (r1.isSameNodeInfo(r2)) {
43: // return a.compareOrder(b);
44: // }
45: // int d1 = r1.getDocumentNumber();
46: // int d2 = r2.getDocumentNumber();
47: // return d1 - d2;
48: }
49: }
50:
51: //
52: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
53: // you may not use this file except in compliance with the License. You may obtain a copy of the
54: // License at http://www.mozilla.org/MPL/
55: //
56: // Software distributed under the License is distributed on an "AS IS" basis,
57: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
58: // See the License for the specific language governing rights and limitations under the License.
59: //
60: // The Original Code is: all this file.
61: //
62: // The Initial Developer of the Original Code is Michael H. Kay
63: //
64: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
65: //
66: // Contributor(s): none
67: //
|