KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > sort > GlobalOrderComparer


1 package net.sf.saxon.sort;
2 import net.sf.saxon.om.NodeInfo;
3
4 import java.io.Serializable JavaDoc;
5
6 /**
7  * A Comparer used for comparing nodes in document order. This
8  * comparer is used when there is no guarantee that the nodes being compared
9  * come from the same document
10  *
11  * @author Michael H. Kay
12  *
13  */

14
15 public final class GlobalOrderComparer implements NodeOrderComparer, Serializable JavaDoc {
16
17     private static GlobalOrderComparer instance = new GlobalOrderComparer();
18
19     /**
20     * Get an instance of a GlobalOrderComparer. The class maintains no state
21     * so this returns the same instance every time.
22     */

23
24     public static GlobalOrderComparer getInstance() {
25         return instance;
26     }
27
28     public int compare(NodeInfo a, NodeInfo b) {
29         if (a==b) {
30             return 0;
31         }
32         int d1 = a.getDocumentNumber();
33         int d2 = b.getDocumentNumber();
34         if (d1 == d2) {
35             return a.compareOrder(b);
36         }
37         return d1 - d2;
38 // NodeInfo r1 = a.getRoot();
39
// NodeInfo r2 = b.getRoot();
40
// if (r1.isSameNodeInfo(r2)) {
41
// return a.compareOrder(b);
42
// }
43
// int d1 = r1.getDocumentNumber();
44
// int d2 = r2.getDocumentNumber();
45
// return d1 - d2;
46
}
47 }
48
49
50 //
51
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
52
// you may not use this file except in compliance with the License. You may obtain a copy of the
53
// License at http://www.mozilla.org/MPL/
54
//
55
// Software distributed under the License is distributed on an "AS IS" basis,
56
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
57
// See the License for the specific language governing rights and limitations under the License.
58
//
59
// The Original Code is: all this file.
60
//
61
// The Initial Developer of the Original Code is Michael H. Kay
62
//
63
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
64
//
65
// Contributor(s): none
66
//
Popular Tags