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 Item |
asItem(Sequence sequence)
Static method to make an Item from a Value
|
static AttributeMap |
attributeMapFromList(java.util.List<AttributeInfo> list)
Construct an AttributeMap given a list of
AttributeInfo objects
representing the individual attributes. |
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 int |
getLength(SequenceIterator iterator)
Get the number of items in the sequence identified by a
SequenceIterator . |
static UnicodeString |
getStringValue(Sequence 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 Item |
itemAt(Sequence sequence,
int index)
Get the item at a given offset in a sequence.
|
static GroundedValue |
itemOrEmpty(Item item)
Helper method to convert an Item or null to a Sequence
|
static Sequence[] |
makeSequenceArray(int length)
Make an array of general-purpose Sequence objects of a given length
|
static void |
process(Sequence value,
Outputter output,
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 java.lang.String |
stringify(Sequence sequence)
Get the string value of a sequence.
|
static void |
supply(SequenceIterator iter,
ItemConsumer<? super Item> consumer)
Supply the (remaining) items in a sequence to a consumer of items
|
static boolean |
supportsGetLength(SequenceIterator iterator)
Ask whether a SequenceIterator supports the capability to call
getLength() to establish
the number of items in the sequence. |
static GroundedValue |
toGroundedValue(SequenceIterator iterator)
Produce a GroundedValue containing the same values as a supplied sequence.
|
static Sequence |
toLazySequence(SequenceIterator 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 |
toMemoSequence(SequenceIterator 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 GroundedValue toGroundedValue(SequenceIterator iterator)
iterator
- the supplied sequence. The iterator may or may not be consumed as a result of
passing it to this method.UncheckedXPathException
- if a failure occurs reading the input iteratorpublic static Sequence toMemoSequence(SequenceIterator 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 toLazySequence(SequenceIterator 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 boolean supportsGetLength(SequenceIterator iterator)
getLength()
to establish
the number of items in the sequence.iterator
- the iterator we are asking aboutLastPositionFinder
with this
capability. Note that some iterators implement this interface, but do not actually have the
capability to determine the length, because they delegate to another iterator.public static int getLength(SequenceIterator iterator)
SequenceIterator
.
This method can only be used if supportsGetLength(SequenceIterator)
has been called
and returns true. The length is returned regardless of the current position of the iterator.
The state of the iterator is not changediterator
- the iterator we are asking aboutjava.lang.UnsupportedOperationException
- if the iterator does not have this capabilitypublic static void supply(SequenceIterator iter, ItemConsumer<? super Item> consumer)
iter
- a sequence iterator, which will be consumed by calling this methodconsumer
- the consumer which will be called to process the remaining items
in the sequence, in turnUncheckedXPathException
- if the computation of the input sequence reports an XPathException,
or if the consymer throws an XPathExceptionpublic 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
Note: this is more efficient than counting the items and testing whether the result is N, because the sequence only needs to be read as far as the Nth item.
iter
- an iterator over the sequence in question (which is typically consumed)length
- the supposed lengthXPathException
- if an error is detectedpublic static boolean sameLength(SequenceIterator a, SequenceIterator b) throws XPathException
a
- iterator over the first sequenceb
- iterator over the second sequenceXPathException
- if an error is detectedpublic static Item itemAt(Sequence sequence, int index)
sequence
- the input sequenceindex
- the 0-based subscriptUncheckedXPathException
- for example if the value is a closure that needs to be
evaluated, and evaluation failspublic static Item asItem(Sequence 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 UnicodeString getStringValue(Sequence sequence) throws XPathException
sequence
- the input sequenceXPathException
- if the sequence contains an item with no string value,
for example a function itempublic static java.lang.String stringify(Sequence 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 void process(Sequence value, Outputter output, Location locationId) throws XPathException
value
- the sequence to be processedoutput
- the destination for the resultlocationId
- (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 arraypublic static Sequence[] fromItems(Item... items)
items
- the contents for the arraypublic static AttributeMap attributeMapFromList(java.util.List<AttributeInfo> list)
AttributeInfo
objects
representing the individual attributes.list
- the list of attributes. It is the caller's responsibility
to ensure that this list contains no duplicates. The method
may detect this, but is not guaranteed to do so. Calling
AttributeMap.verify()
after constructing the attribute map verifies
that there are no duplicates. The order of items in the input
list is not necessarily preserved.java.lang.IllegalArgumentException
- if duplicate attributes are detectedpublic static GroundedValue itemOrEmpty(Item item)
item
- the item to convertCopyright (c) 2004-2022 Saxonica Limited. All rights reserved.