Debian Codegraph @

net/sf/saxon/expr/sort/GlobalOrderComparer.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.expr.sort;
9
10 import net.sf.saxon.om.Item;
11 import net.sf.saxon.om.NodeInfo;
12
13 /**
14 * A Comparer used for comparing nodes in document order. This
15 * comparer is used when there is no guarantee that the nodes being compared
16 * come from the same document
17 */
18
19 public final class GlobalOrderComparer implements ItemOrderComparer {
20
21 private static GlobalOrderComparer instance = new GlobalOrderComparer();
22
23 /**
24 * Get an instance of a GlobalOrderComparer. The class maintains no state
25 * so this returns the same instance every time.
26 */
27
28 public static GlobalOrderComparer getInstance() {
29 return instance;
30 }
31
32 public int compare(Item a, /*@NotNull*/ Item b) {
33 if (a == b) {
34 return 0;
35 }
36 long d1 = ((NodeInfo) a).getTreeInfo().getDocumentNumber();
37 long d2 = ((NodeInfo) b).getTreeInfo().getDocumentNumber();
38 if (d1 == d2) {
39 return ((NodeInfo) a).compareOrder((NodeInfo) b);
40 }
41 return Long.signum(d1 - d2);
42 }
43 }
44