public class SequenceTool
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
INDETERMINATE_ORDERING
Constant returned by compareTo() method to indicate an indeterminate ordering between two values
|
Constructor and Description |
---|
SequenceTool() |
Modifier and Type | Method and Description |
---|---|
static <T extends Item<?>> |
asItem(Sequence<T> sequence)
Static method to make an Item from a Value
|
static java.lang.Object |
convertToJava(Item item)
Convert an XPath value to a Java object.
|
static Sequence<?>[] |
fromItems(Item<?>... items)
Make an array of general-purpose Sequence objects with supplied contents
|
static int |
getCardinality(Sequence<?> sequence)
Get the cardinality of a sequence
|
static ItemType |
getItemType(Sequence<?> sequence,
TypeHierarchy th)
Get the item type of the items in a sequence.
|
static int |
getLength(Sequence<?> sequence)
Get the length of a sequence (the number of items it contains)
|
static SequenceType |
getSequenceType(Sequence<?> value,
TypeHierarchy th)
Get a sequence type to which a given value conforms
|
static <T extends Item<?>> |
getStringValue(Sequence<T> sequence)
Get the string value of a sequence.
|
static UType |
getUType(Sequence<?> sequence)
Get the UType of the items in a sequence.
|
static boolean |
hasLength(SequenceIterator iter,
int length)
Ask whether the length of a sequence is exactly N
|
static boolean |
isUnrepeatable(Sequence<?> seq) |
static <T extends Item<?>> |
itemAt(Sequence<T> sequence,
int index)
Get the item at a given offset in a sequence.
|
static Sequence<?>[] |
makeSequenceArray(int length)
Make an array of general-purpose Sequence objects of a given length
|
static void |
process(Sequence<?> value,
XPathContext context,
Location locationId)
Process a supplied value by copying it to the current output destination
|
static boolean |
sameLength(SequenceIterator a,
SequenceIterator b)
Determine whether two sequences have the same number of items.
|
static <T extends Item<?>> |
toGroundedValue(SequenceIterator<T> iterator)
Produce a GroundedValue containing the same values as a supplied sequence.
|
static <T extends Item<?>> |
toLazySequence(SequenceIterator<T> iterator)
Construct a sequence capable of returning the same items as an iterator,
without incurring the cost of evaluating the iterator and storing all
the items.
|
static Sequence<?> |
toLazySequence2(SequenceIterator<?> iterator) |
static <T extends Item<?>> |
toMemoSequence(SequenceIterator<T> iterator)
Produce a Sequence containing the same values as a supplied sequence; the input is
read progressively as required, and saved in a buffer as it is read in case it is needed
again.
|
public static final int INDETERMINATE_ORDERING
public static <T extends Item<?>> GroundedValue<T> toGroundedValue(SequenceIterator<T> iterator) throws XPathException
iterator
- the supplied sequence. The iterator may or may not be consumed as a result of
passing it to this method.XPathException
- if a failure occurs reading the input iteratorpublic static <T extends Item<?>> Sequence<T> toMemoSequence(SequenceIterator<T> iterator) throws XPathException
iterator
- the supplied sequence. The iterator may or may not be consumed as a result of
passing it to this method.XPathException
- if a failure occurs reading the input iteratorpublic static <T extends Item<?>> Sequence<T> toLazySequence(SequenceIterator<T> iterator) throws XPathException
iterator
- the supplied sequence. The iterator may or may not be consumed as a result of
passing it to this method.XPathException
- if a failure occurs reading the input iteratorpublic static Sequence<?> toLazySequence2(SequenceIterator<?> iterator) throws XPathException
XPathException
public static boolean isUnrepeatable(Sequence<?> seq)
public static int getLength(Sequence<?> sequence) throws XPathException
sequence
- the sequenceXPathException
- if an error occurs (due to lazy evaluation)public static boolean hasLength(SequenceIterator iter, int length) throws XPathException
iter
- an iterator over the sequence in question (which is typically consumed)length
- the supposed lengthXPathException
public static boolean sameLength(SequenceIterator a, SequenceIterator b) throws XPathException
a
- iterator over the first sequenceb
- iterator over the second sequeceXPathException
public static <T extends Item<?>> T itemAt(Sequence<T> sequence, int index) throws XPathException
sequence
- the input sequenceindex
- the 0-based subscriptXPathException
- for example if the value is a closure that needs to be
evaluated, and evaluation failspublic static <T extends Item<?>> T asItem(Sequence<T> sequence) throws XPathException
sequence
- the value to be convertedXPathException
- if the supplied Sequence contains multiple itemspublic static java.lang.Object convertToJava(Item item) throws XPathException
item
- the item to be convertedXPathException
- if an error occurs: for example, if the XPath value is
an integer and is too big to fit in a Java longpublic static <T extends Item<?>> java.lang.String getStringValue(Sequence<T> sequence) throws XPathException
sequence
- the input sequenceXPathException
- if the sequence contains an item with no string value,
for example a function itempublic static ItemType getItemType(Sequence<?> sequence, TypeHierarchy th)
sequence
- the input sequenceth
- the Type Hierarchy cachepublic static UType getUType(Sequence<?> sequence)
sequence
- the input sequencepublic static int getCardinality(Sequence<?> sequence)
sequence
- the supplied sequenceStaticProperty.ALLOWS_ZERO
(for an empty sequence)
StaticProperty.EXACTLY_ONE
(for a singleton), or StaticProperty.ALLOWS_ONE_OR_MORE
(for
a sequence with more than one item)public static SequenceType getSequenceType(Sequence<?> value, TypeHierarchy th)
value
- the given valueth
- the type hierarchy cachepublic static void process(Sequence<?> value, XPathContext context, Location locationId) throws XPathException
value
- the sequence to be processedcontext
- The dynamic context, giving access to the current node,
the current variables, etc.locationId
- (can be set to -1 if absent) information about the location of the value,
which can be resolved by reference to the PipelineConfiguration of the current output
destinationXPathException
- if an error occurs (for example if the value is
a closure that needs to be evaluated)public static Sequence<?>[] makeSequenceArray(int length)
length
- the length of the returned arrayCopyright (c) 2004-2020 Saxonica Limited. All rights reserved.