Debian Codegraph @

net/sf/saxon/expr/sort/CollationMatchKey.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.value.AtomicValue;
11 import net.sf.saxon.value.Base64BinaryValue;
12
13 import java.text.CollationKey;
14
15 /**
16 * A match key for comparing strings under a collation. Wraps a Java CollationKey obtained
17 * from the collation.
18 */
19 public class CollationMatchKey implements AtomicMatchKey, Comparable {
20
21 private CollationKey key;
22
23 public CollationMatchKey(CollationKey key) {
24 this.key = key;
25 }
26
27 public int compareTo(Object o) {
28 if (o instanceof CollationMatchKey) {
29 return key.compareTo(((CollationMatchKey) o).key);
30 } else {
31 throw new ClassCastException();
32 }
33 }
34
35 @Override
36 public int hashCode() {
37 return key.hashCode();
38 }
39
40 @Override
41 public boolean equals(Object o) {
42 return o instanceof CollationMatchKey && key.equals(((CollationMatchKey) o).key);
43 }
44
45 /**
46 * Get an atomic value that encapsulates this match key. Needed to support the collation-key() function.
47 *
48 * @return an atomic value that encapsulates this match key
49 */
50 public AtomicValue asAtomic() {
51 return new Base64BinaryValue(key.toByteArray());
52 }
53 }