public class XdmCollectors
extends java.lang.Object
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()
Modifier and Type | Class and Description |
---|---|
static class |
XdmCollectors.MultipleItemException
Unchecked exception that occurs when a collector method such as
asAtomic() or asOptionalNode()
is called, and the sequence contains more than one item. |
Constructor and Description |
---|
XdmCollectors() |
Modifier and Type | Method and Description |
---|---|
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 of
XdmAtomicValue . |
static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.util.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 of
List<XdmAtomicValue> ) |
static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.util.List<XdmNode>,XdmNode> |
asListOfNodes()
This method provides a Collector that returns the content of a stream as a list of
XdmNode objects
(that is, as an instance of List<XdmNode> ) |
static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<XdmNode,XdmNode> |
asNode()
This method provides a Collector that returns the content of a stream as a single
XdmNode . |
static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.util.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 of
Optional<XdmAtomicValue> ) |
static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.util.Optional<XdmNode>,XdmNode> |
asOptionalNode()
This method provides a Collector that returns the content of a stream as an optional
XdmNode
(that is, as an instance of Optional<XdmNode> ) |
static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.util.Optional<java.lang.String>,XdmItem> |
asOptionalString()
This method provides a Collector that returns the content of a stream as an optional String
(that is, as an instance of
Optional<String> )
The stream must deliver either nothing, or a single XdmItem ; the collector returns
the string value of that item. |
static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.lang.String,XdmItem> |
asString()
This method provides a Collector that returns the content of a stream as an optional String
(that is, as an instance of
Optional<String> )
The stream must deliver a single XdmItem ; the collector returns the string value
of that item. |
static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<XdmValue,XdmItem> |
asXdmValue()
This method provides a Collector that returns the content of a stream as an
XdmValue |
public static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<XdmValue,XdmItem> asXdmValue()
XdmValue
java.lang.ClassCastException
- if the stream contains an item that is not a nodepublic static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<XdmNode,XdmNode> asNode()
XdmNode
.java.util.NoSuchElementException
- if the stream is emptyXdmCollectors.MultipleItemException
- if the stream contains more than one nodejava.lang.ClassCastException
- if the stream contains an item that is not a nodepublic static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.util.Optional<XdmNode>,XdmNode> asOptionalNode()
XdmNode
(that is, as an instance of Optional<XdmNode>
)Optional#empty()
if the stream is emptyXdmCollectors.MultipleItemException
- if the stream contains more than one nodejava.lang.ClassCastException
- if the stream contains an item that is not a nodepublic static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.util.List<XdmNode>,XdmNode> asListOfNodes()
XdmNode
objects
(that is, as an instance of List<XdmNode>
)java.lang.ClassCastException
- if the stream contains an item that is not a nodepublic static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.util.List<XdmAtomicValue>,XdmAtomicValue> asListOfAtomic()
List<XdmAtomicValue>
)java.lang.ClassCastException
- if the stream contains an item that is not an atomic valuepublic static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.util.Optional<XdmAtomicValue>,XdmAtomicValue> asOptionalAtomic()
Optional<XdmAtomicValue>
)Optional.empty()
if the stream is emptyjava.lang.ClassCastException
- if the stream contains an item that is not a nodepublic static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<XdmAtomicValue,XdmAtomicValue> asAtomic()
XdmAtomicValue
.
The stream must deliver a single atomic value.java.util.NoSuchElementException
- if the stream is emptyXdmCollectors.MultipleItemException
- if the stream contains more than one itemjava.lang.ClassCastException
- if the stream delivers an item that is not an atomic valuepublic static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.util.Optional<java.lang.String>,XdmItem> asOptionalString()
Optional<String>
)
The stream must deliver either nothing, or a single XdmItem
; the collector returns
the string value of that item.XdmCollectors.MultipleItemException
- if the stream contains more than one itemjava.lang.UnsupportedOperationException
- if the stream contains an item with no string value (such
as a function item or an element with element-only content)public static net.sf.saxon.s9api.streams.XdmCollectors.XdmCollector<java.lang.String,XdmItem> asString()
Optional<String>
)
The stream must deliver a single XdmItem
; the collector returns the string value
of that item.XdmCollectors.MultipleItemException
- if the stream contains more than one itemjava.util.NoSuchElementException
- if the stream is emptyjava.lang.UnsupportedOperationException
- if the stream contains an item with no string value (such
as a function item or an element with element-only content)Copyright (c) 2004-2020 Saxonica Limited. All rights reserved.