| 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.om; |
| 9 | |
| 10 | import net.sf.saxon.tree.iter.AtomicIterator; |
| 11 | import net.sf.saxon.value.AtomicValue; |
| 12 | |
| 13 | /** |
| 14 | * Interface representing a sequence of atomic values. This is often used to represent the |
| 15 | * typed value of a node. In most cases the typed value of a node is a single atomic value, |
| 16 | * so the class AtomicValue implements this interface. |
| 17 | * <p>An AtomicSequence is always represented as a GroundedValue: that is, the entire sequence |
| 18 | * is in memory, making operations such as {@link #itemAt(int)} and {@link #getLength()} possible.</p> |
| 19 | */ |
| 20 | |
| 21 | public interface AtomicSequence extends GroundedValue<AtomicValue> { |
| 22 | |
| 23 | /** |
| 24 | * Get the first item in the sequence |
| 25 | * @return the first item in the sequence, or null if the sequence is empty |
| 26 | */ |
| 27 | |
| 28 | AtomicValue head(); |
| 29 | |
| 30 | /** |
| 31 | * Make an iterator over the items in the sequence |
| 32 | * @return an iterator over the items in the sequence |
| 33 | */ |
| 34 | |
| 35 | AtomicIterator iterate(); |
| 36 | |
| 37 | /** |
| 38 | * Get the Nth item in the sequence, zero-based |
| 39 | * @param n the index of the required item, with 0 representing the first item in the sequence |
| 40 | * @return the Nth item in the sequence, or null if the index is out of range |
| 41 | */ |
| 42 | |
| 43 | AtomicValue itemAt(int n); |
| 44 | |
| 45 | /** |
| 46 | * Get the length of the sequence |
| 47 | * @return the number of items in the sequence |
| 48 | */ |
| 49 | |
| 50 | int getLength(); |
| 51 | |
| 52 | /** |
| 53 | * Get the canonical lexical representation as defined in XML Schema. This is not always the same |
| 54 | * as the result of casting to a string according to the XPath rules. |
| 55 | * |
| 56 | * @return the canonical lexical representation if defined in XML Schema; otherwise, the result |
| 57 | * of casting to string according to the XPath 2.0 rules |
| 58 | */ |
| 59 | |
| 60 | CharSequence getCanonicalLexicalRepresentation(); |
| 61 | |
| 62 | /** |
| 63 | * Get a Comparable value that implements the XML Schema ordering comparison semantics for this value. |
| 64 | * The default implementation is written to compare sequences of atomic values. |
| 65 | * This method is overridden for AtomicValue and its subclasses. |
| 66 | * <p>In the case of data types that are partially ordered, the returned Comparable extends the standard |
| 67 | * semantics of the compareTo() method by returning the value {@link SequenceTool#INDETERMINATE_ORDERING} when there |
| 68 | * is no defined order relationship between two given values.</p> |
| 69 | * |
| 70 | * @return a Comparable that follows XML Schema comparison rules |
| 71 | */ |
| 72 | |
| 73 | Comparable getSchemaComparable(); |
| 74 | |
| 75 | /** |
| 76 | * Get a string representation of the sequence. The is the space-separated concatenation of the result of |
| 77 | * casting each of the items in the sequence to xs:string |
| 78 | * @return a whitespace-separated concatenation of the string values of the items making up the sequence, |
| 79 | * as a CharSequence. |
| 80 | */ |
| 81 | |
| 82 | CharSequence getStringValueCS(); |
| 83 | |
| 84 | /** |
| 85 | * Get a string representation of the sequence. The is the space-separated concatenation of the result of |
| 86 | * casting each of the items in the sequence to xs:string |
| 87 | * |
| 88 | * @return a whitespace-separated concatenation of the string values of the items making up the sequence, |
| 89 | * as a String. |
| 90 | */ |
| 91 | |
| 92 | String getStringValue(); |
| 93 | |
| 94 | } |
| 95 |