Debian Codegraph @

net/sf/saxon/expr/sort/AtomicComparer.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.expr.XPathContext;
11 import net.sf.saxon.lib.StringCollator;
12 import net.sf.saxon.trans.NoDynamicContextException;
13 import net.sf.saxon.value.AtomicValue;
14
15 /**
16 * Interface representing an object that can be used to compare two XPath atomic values for equality or
17 * for ordering.
18 */
19
20 public interface AtomicComparer {
21
22 /**
23 * Get the collation used by this AtomicComparer if any
24 *
25 * @return the collation used for comparing strings, or null if not applicable
26 */
27
28 StringCollator getCollator();
29
30 /**
31 * Supply the dynamic context in case this is needed for the comparison
32 *
33 * @param context the dynamic evaluation context
34 * @return either the original AtomicComparer, or a new AtomicComparer in which the context
35 * is known. The original AtomicComparer is not modified
36 */
37
38 AtomicComparer provideContext(XPathContext context);
39
40 /**
41 * Compare two AtomicValue objects according to the rules for their data type. UntypedAtomic
42 * values are compared as if they were strings; if different semantics are wanted, the conversion
43 * must be done by the caller.
44 *
45 * @param a the first object to be compared. It is intended that this should be an instance
46 * of AtomicValue, though this restriction is not enforced. If it is a StringValue, the
47 * collator is used to compare the values, otherwise the value must implement the java.util.Comparable
48 * interface.
49 * @param b the second object to be compared. This must be comparable with the first object: for
50 * example, if one is a string, they must both be strings.
51 * @return <0 if a<b, 0 if a=b, >0 if a>b
52 * @throws ClassCastException if the objects are not comparable
53 * @throws NoDynamicContextException if this comparer required access to dynamic context information,
54 * notably the implicit timezone, and this information is not available. In general this happens if a
55 * context-dependent comparison is attempted at compile-time, and it signals the compiler to generate
56 * code that tries again at run-time.
57 */
58
59 int compareAtomicValues(AtomicValue a, AtomicValue b) throws NoDynamicContextException;
60
61 /**
62 * Compare two AtomicValue objects for equality according to the rules for their data type. UntypedAtomic
63 * values are compared by converting to the type of the other operand.
64 *
65 * @param a the first object to be compared.
66 * @param b the second object to be compared.
67 * @return true if the values are equal, false if not
68 * @throws ClassCastException if the objects are not comparable
69 */
70
71 boolean comparesEqual(AtomicValue a, AtomicValue b) throws NoDynamicContextException;
72
73 /**
74 * Create a string representation of this AtomicComparer that can be saved in a compiled
75 * package and used to reconstitute the AtomicComparer when the package is reloaded
76 * @return a string representation of the AtomicComparer
77 */
78
79 String save();
80
81 }