Debian Codegraph @

net/sf/saxon/expr/sort/CodepointMatchKey.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.regex.UnicodeString;
11 import net.sf.saxon.value.AtomicValue;
12 import net.sf.saxon.value.Base64BinaryValue;
13
14 /**
15 * A match key for comparing strings (represented as an array of characters) using codepoint collation.
16 */
17 public class CodepointMatchKey implements Comparable<CodepointMatchKey>, AtomicMatchKey {
18
19 private UnicodeString value;
20
21 public CodepointMatchKey(CharSequence in) {
22 value = UnicodeString.makeUnicodeString(in);
23 }
24
25 public UnicodeString getValue() {
26 return value;
27 }
28
29 public int compareTo(CodepointMatchKey o) {
30 return value.compareTo(o.value);
31 }
32
33 @Override
34 public int hashCode() {
35 return value.hashCode();
36 }
37
38 @Override
39 public boolean equals(Object o) {
40 return this == o || (o instanceof CodepointMatchKey && compareTo((CodepointMatchKey)o) == 0);
41 }
42
43 /**
44 * Get an atomic value that encapsulates this match key. Needed to support the collation-key() function.
45 *
46 * @return an atomic value that encapsulates this match key
47 */
48 public AtomicValue asAtomic() {
49 return new Base64BinaryValue(value.getCodepointCollationKey());
50 }
51 }
52
53