Debian Codegraph @

net/sf/saxon/s9api/SequenceType.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.s9api;
9
10 /**
11 * A SequenceType is the combination of an ItemType and an OccurrenceIndicator
12 */
13 public class SequenceType {
14
15 private ItemType itemType;
16 private OccurrenceIndicator occurrenceIndicator;
17
18 /**
19 * Construct a SequenceType
20 *
21 * @param itemType the ItemType
22 * @param occurrenceIndicator the permitted number of occurrences of the item in the sequence
23 */
24
25 private SequenceType(ItemType itemType, OccurrenceIndicator occurrenceIndicator) {
26 this.itemType = itemType;
27 this.occurrenceIndicator = occurrenceIndicator;
28 }
29
30 /**
31 * Factory method to construct a SequenceType
32 *
33 * @param itemType the ItemType
34 * @param occurrenceIndicator the permitted number of occurrences of the item in the sequence
35 * @return the constricted SequenceType
36 */
37
38 /*@NotNull*/
39 public static SequenceType makeSequenceType(ItemType itemType, OccurrenceIndicator occurrenceIndicator) {
40 return new SequenceType(itemType, occurrenceIndicator);
41 }
42
43 /**
44 * Get the item type
45 *
46 * @return the item type
47 */
48
49 public ItemType getItemType() {
50 return itemType;
51 }
52
53 /**
54 * Get the occurrence indicator
55 *
56 * @return the occurrence indicator
57 */
58
59 public OccurrenceIndicator getOccurrenceIndicator() {
60 return occurrenceIndicator;
61 }
62
63 /**
64 * Test whether two SequenceType objects represent the same type
65 *
66 * @param other the other SequenceType object
67 * @return true if the other object is a SequenceType representing the same type
68 * @since 9.5
69 */
70
71 public final boolean equals(Object other) {
72 return other instanceof SequenceType &&
73 ((SequenceType) other).getOccurrenceIndicator().equals(getOccurrenceIndicator()) &&
74 ((SequenceType) other).getItemType().equals(getItemType());
75 }
76
77 /**
78 * Get a hash code with semantics corresponding to the equals() method
79 *
80 * @return the hash code
81 * @since 9.5
82 */
83
84 public final int hashCode() {
85 return getItemType().hashCode() ^ (getOccurrenceIndicator().hashCode() << 17);
86 }
87
88 /**
89 * Get the underlying internal SequenceType
90 * @return the equivalent instance of {@link net.sf.saxon.value.SequenceType}
91 */
92
93 public net.sf.saxon.value.SequenceType getUnderlyingSequenceType() {
94 return net.sf.saxon.value.SequenceType.makeSequenceType(
95 itemType.getUnderlyingItemType(), occurrenceIndicator.getCardinality());
96 }
97
98 /**
99 * Factory method to construct a s9api {@code SequenceType} from an underlying
100 * instance of {@link net.sf.saxon.value.SequenceType}
101 *
102 * @since 10.0
103 */
104
105 public static SequenceType fromUnderlyingSequenceType(
106 Processor processor, net.sf.saxon.value.SequenceType st) {
107 ItemTypeFactory factory = new ItemTypeFactory(processor);
108 ItemType it = factory.exposeItemType(st.getPrimaryType());
109 OccurrenceIndicator oc = OccurrenceIndicator.getOccurrenceIndicator(st.getCardinality());
110 return makeSequenceType(it, oc);
111 }
112
113
114 }