Package net.sf.saxon.s9api.streams
Class XdmCollectors
java.lang.Object
net.sf.saxon.s9api.streams.XdmCollectors
This class contains a number of static methods that deliver implementations of the
Collector
interface suitable for use with streams processing XDM nodes and other items.
For example, the method asNode
can be used in an expression such as
XdmNode n = x.select(child("author")).collect(asNode())
to indicate that the content of the stream
delivered by the select()
call is to be delivered as a single XdmNode object, and that an exception
should occur if the result is anything other than a single node.
Although these methods can be used directly as arguments to Stream.collect(java.util.function.Supplier<R>, java.util.function.BiConsumer<R, ? super T>, java.util.function.BiConsumer<R, R>)
, it is usually more convenient
to use them indirectly, the form of terminal operations on the class XdmStream
, which extends Stream
.
So a more usual usage would be XdmNode n = x.select(child("author")).asNode()
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Unchecked exception that occurs when a collector method such asasAtomic()
orasOptionalNode()
is called, and the sequence contains more than one item. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector
<XdmAtomicValue, XdmAtomicValue> asAtomic()
This method provides a Collector that returns the content of a stream as a single atomic value, that is, an instance ofXdmAtomicValue
.static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector
<List<XdmAtomicValue>, XdmAtomicValue> This method provides a Collector that returns the content of a stream as a list of atomic values (that is, as an instance ofList<XdmAtomicValue>
)This method provides a Collector that returns the content of a stream as a list ofXdmNode
objects (that is, as an instance ofList<XdmNode>
)asNode()
This method provides a Collector that returns the content of a stream as a singleXdmNode
.static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector
<Optional<XdmAtomicValue>, XdmAtomicValue> This method provides a Collector that returns the content of a stream as an optional atomic value (that is, as an instance ofOptional<XdmAtomicValue>
)This method provides a Collector that returns the content of a stream as an optionalXdmNode
(that is, as an instance ofOptional<XdmNode>
)This method provides a Collector that returns the content of a stream as an optional String (that is, as an instance ofOptional<String>
) The stream must deliver either nothing, or a singleXdmItem
; the collector returns the string value of that item.asString()
This method provides a Collector that returns the content of a stream as an optional String (that is, as an instance ofOptional<String>
) The stream must deliver a singleXdmItem
; the collector returns the string value of that item.This method provides a Collector that returns the content of a stream as anXdmValue
-
Constructor Details
-
XdmCollectors
public XdmCollectors()
-
-
Method Details
-
asXdmValue
This method provides a Collector that returns the content of a stream as anXdmValue
- Returns:
- a collector that returns the single node delivered by the stream, or null if the stream is empty
- Throws:
ClassCastException
- if the stream contains an item that is not a node
-
asNode
This method provides a Collector that returns the content of a stream as a singleXdmNode
.- Returns:
- a collector that returns the single node delivered by the stream
- Throws:
NoSuchElementException
- if the stream is emptyXdmCollectors.MultipleItemException
- if the stream contains more than one nodeClassCastException
- if the stream contains an item that is not a node
-
asOptionalNode
public static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<Optional<XdmNode>,XdmNode> asOptionalNode()This method provides a Collector that returns the content of a stream as an optionalXdmNode
(that is, as an instance ofOptional<XdmNode>
)- Returns:
- a collector that returns the single node delivered by the stream, or
Optional#empty()
if the stream is empty - Throws:
XdmCollectors.MultipleItemException
- if the stream contains more than one nodeClassCastException
- if the stream contains an item that is not a node
-
asListOfNodes
public static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<List<XdmNode>,XdmNode> asListOfNodes()This method provides a Collector that returns the content of a stream as a list ofXdmNode
objects (that is, as an instance ofList<XdmNode>
)- Returns:
- a collector that returns the single node delivered by the stream, or null if the stream is empty
- Throws:
ClassCastException
- if the stream contains an item that is not a node
-
asListOfAtomic
public static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<List<XdmAtomicValue>,XdmAtomicValue> asListOfAtomic()This method provides a Collector that returns the content of a stream as a list of atomic values (that is, as an instance ofList<XdmAtomicValue>
)- Returns:
- a collector that returns the list of atomic values delivered by the stream
- Throws:
ClassCastException
- if the stream contains an item that is not an atomic value
-
asOptionalAtomic
public static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<Optional<XdmAtomicValue>,XdmAtomicValue> asOptionalAtomic()This method provides a Collector that returns the content of a stream as an optional atomic value (that is, as an instance ofOptional<XdmAtomicValue>
)- Returns:
- a collector that returns the single atomic value delivered by the stream, or
Optional.empty()
if the stream is empty - Throws:
ClassCastException
- if the stream contains an item that is not a node
-
asAtomic
public static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<XdmAtomicValue,XdmAtomicValue> asAtomic()This method provides a Collector that returns the content of a stream as a single atomic value, that is, an instance ofXdmAtomicValue
. The stream must deliver a single atomic value.- Returns:
- a collector that returns the string value of the single item delivered by the stream
- Throws:
NoSuchElementException
- if the stream is emptyXdmCollectors.MultipleItemException
- if the stream contains more than one itemClassCastException
- if the stream delivers an item that is not an atomic value
-
asOptionalString
public static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<Optional<String>,XdmItem> asOptionalString()This method provides a Collector that returns the content of a stream as an optional String (that is, as an instance ofOptional<String>
) The stream must deliver either nothing, or a singleXdmItem
; the collector returns the string value of that item.- Returns:
- a collector that returns the string value of the single item delivered by the stream, if any
- Throws:
XdmCollectors.MultipleItemException
- if the stream contains more than one itemUnsupportedOperationException
- if the stream contains an item with no string value (such as a function item or an element with element-only content)
-
asString
This method provides a Collector that returns the content of a stream as an optional String (that is, as an instance ofOptional<String>
) The stream must deliver a singleXdmItem
; the collector returns the string value of that item.- Returns:
- a collector that returns the string value of the single item delivered by the stream, if any
- Throws:
XdmCollectors.MultipleItemException
- if the stream contains more than one itemNoSuchElementException
- if the stream is emptyUnsupportedOperationException
- if the stream contains an item with no string value (such as a function item or an element with element-only content)
-