T
- The type of items delivered by the stream.public class XdmStream<T extends XdmItem>
extends java.lang.Object
implements java.util.stream.Stream<T>
Stream
.
The extensions are:
List<XdmNode>
or
an Optional<XdmNode>
more conveniently than using the general-purpose
Collector
interface.The implementation is customized to streams of XdmItem
s.
Constructor and Description |
---|
XdmStream(java.util.Optional<T> input)
Create an
XdmStream consisting of zero or one items, supplied in the form
of an Optional<XdmItem> |
XdmStream(java.util.stream.Stream<T> base)
Create an
XdmStream from a general Stream that returns XDM items. |
Modifier and Type | Method and Description |
---|---|
boolean |
allMatch(java.util.function.Predicate<? super T> predicate) |
boolean |
anyMatch(java.util.function.Predicate<? super T> predicate) |
XdmAtomicValue |
asAtomic()
Return the result of the stream as an
XdmAtomicValue . |
java.util.List<T> |
asList()
Return the result of the stream as a
List<XdmItem> . |
java.util.List<XdmAtomicValue> |
asListOfAtomic()
Return the result of the stream as a
List<XdmAtomicValue> . |
java.util.List<XdmNode> |
asListOfNodes()
Return the result of the stream as a
List<XdmNode> . |
XdmNode |
asNode()
Return the result of the stream as an
XdmNode . |
java.util.Optional<XdmAtomicValue> |
asOptionalAtomic()
Return the result of the stream as an
Optional<XdmAtomicValue> . |
java.util.Optional<XdmNode> |
asOptionalNode()
Return the result of the stream as an
Optional<XdmNode> . |
java.util.Optional<java.lang.String> |
asOptionalString()
Return the result of the stream as an
Optional<String> . |
java.lang.String |
asString()
Return the result of the stream as an
String . |
XdmValue |
asXdmValue()
Return the result of the stream as an XdmValue.
|
java.util.Optional<T> |
at(int position)
Return the item at a given position in the stream.
|
void |
close() |
<R,A> R |
collect(java.util.stream.Collector<? super T,A,R> collector) |
<R> R |
collect(java.util.function.Supplier<R> supplier,
java.util.function.BiConsumer<R,? super T> accumulator,
java.util.function.BiConsumer<R,R> combiner) |
long |
count() |
XdmStream<T> |
distinct() |
boolean |
exists()
Return true if the stream is non-empty.
|
XdmStream<T> |
filter(java.util.function.Predicate<? super T> predicate)
Filter a stream of items, to create a new stream containing only those items
that satisfy a supplied condition
|
java.util.Optional<T> |
findAny() |
java.util.Optional<T> |
findFirst() |
XdmStream<T> |
first()
Return the first item of this stream, if there is one, discarding the remainder.
|
<R> java.util.stream.Stream<R> |
flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> mapper) |
java.util.stream.DoubleStream |
flatMapToDouble(java.util.function.Function<? super T,? extends java.util.stream.DoubleStream> mapper) |
java.util.stream.IntStream |
flatMapToInt(java.util.function.Function<? super T,? extends java.util.stream.IntStream> mapper) |
java.util.stream.LongStream |
flatMapToLong(java.util.function.Function<? super T,? extends java.util.stream.LongStream> mapper) |
<U extends XdmItem> |
flatMapToXdm(Step<U> mapper)
|
void |
forEach(java.util.function.Consumer<? super T> action) |
void |
forEachOrdered(java.util.function.Consumer<? super T> action) |
boolean |
isParallel() |
java.util.Iterator<T> |
iterator() |
XdmStream<T> |
last()
Return the last item of this stream, if there is one, discarding the remainder.
|
XdmStream<T> |
limit(long maxSize) |
<R> java.util.stream.Stream<R> |
map(java.util.function.Function<? super T,? extends R> mapper) |
java.util.stream.DoubleStream |
mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper) |
java.util.stream.IntStream |
mapToInt(java.util.function.ToIntFunction<? super T> mapper) |
java.util.stream.LongStream |
mapToLong(java.util.function.ToLongFunction<? super T> mapper) |
java.util.Optional<T> |
max(java.util.Comparator<? super T> comparator) |
java.util.Optional<T> |
min(java.util.Comparator<? super T> comparator) |
boolean |
noneMatch(java.util.function.Predicate<? super T> predicate) |
java.util.stream.Stream<T> |
onClose(java.lang.Runnable closeHandler) |
java.util.stream.Stream<T> |
parallel() |
XdmStream<T> |
peek(java.util.function.Consumer<? super T> action) |
java.util.Optional<T> |
reduce(java.util.function.BinaryOperator<T> accumulator) |
T |
reduce(T identity,
java.util.function.BinaryOperator<T> accumulator) |
<U> U |
reduce(U identity,
java.util.function.BiFunction<U,? super T,U> accumulator,
java.util.function.BinaryOperator<U> combiner) |
java.util.stream.Stream<T> |
sequential() |
XdmStream<T> |
skip(long n) |
XdmStream<T> |
sorted() |
XdmStream<T> |
sorted(java.util.Comparator<? super T> comparator) |
java.util.Spliterator<T> |
spliterator() |
XdmStream<T> |
subStream(int start,
int end)
Return the items at a given range of positions in the stream.
|
java.lang.Object[] |
toArray() |
<A> A[] |
toArray(java.util.function.IntFunction<A[]> generator) |
java.util.stream.Stream<T> |
unordered() |
XdmStream<T> |
untilFirstExclusive(java.util.function.Predicate<? super XdmItem> predicate)
Experimental method to return the content of a stream up to the first item
that satisfies a given predicate, excluding that item
|
XdmStream<T> |
untilFirstInclusive(java.util.function.Predicate<? super XdmItem> predicate)
Experimental method to return the content of a stream up to the first item
that satisfies a given predicate, including that item
|
public XdmStream(java.util.stream.Stream<T> base)
XdmStream
from a general Stream
that returns XDM items.base
- the stream of itemspublic XdmStream<T> filter(java.util.function.Predicate<? super T> predicate)
public <R> java.util.stream.Stream<R> map(java.util.function.Function<? super T,? extends R> mapper)
public java.util.stream.IntStream mapToInt(java.util.function.ToIntFunction<? super T> mapper)
public java.util.stream.LongStream mapToLong(java.util.function.ToLongFunction<? super T> mapper)
public java.util.stream.DoubleStream mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper)
public <R> java.util.stream.Stream<R> flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> mapper)
public <U extends XdmItem> XdmStream<U> flatMapToXdm(Step<U> mapper)
XdmStream
by applying a mapping function (specifically, a Step
)
to each item in the stream. The Step
returns a sequence of items, which are inserted
into the result sequence in place of the original item.U
- the type of items returned by the mapping functionmapper
- the mapping functionpublic java.util.stream.IntStream flatMapToInt(java.util.function.Function<? super T,? extends java.util.stream.IntStream> mapper)
public java.util.stream.LongStream flatMapToLong(java.util.function.Function<? super T,? extends java.util.stream.LongStream> mapper)
public java.util.stream.DoubleStream flatMapToDouble(java.util.function.Function<? super T,? extends java.util.stream.DoubleStream> mapper)
public void forEach(java.util.function.Consumer<? super T> action)
public void forEachOrdered(java.util.function.Consumer<? super T> action)
public java.lang.Object[] toArray()
public <A> A[] toArray(java.util.function.IntFunction<A[]> generator)
public <U> U reduce(U identity, java.util.function.BiFunction<U,? super T,U> accumulator, java.util.function.BinaryOperator<U> combiner)
public <R> R collect(java.util.function.Supplier<R> supplier, java.util.function.BiConsumer<R,? super T> accumulator, java.util.function.BiConsumer<R,R> combiner)
public <R,A> R collect(java.util.stream.Collector<? super T,A,R> collector)
public long count()
public boolean anyMatch(java.util.function.Predicate<? super T> predicate)
public boolean allMatch(java.util.function.Predicate<? super T> predicate)
public boolean noneMatch(java.util.function.Predicate<? super T> predicate)
public java.util.Optional<T> findFirst()
public java.util.Optional<T> findAny()
public java.util.Iterator<T> iterator()
public java.util.Spliterator<T> spliterator()
public boolean isParallel()
public java.util.stream.Stream<T> sequential()
public java.util.stream.Stream<T> parallel()
public java.util.stream.Stream<T> unordered()
public java.util.stream.Stream<T> onClose(java.lang.Runnable closeHandler)
public void close()
public XdmValue asXdmValue()
public java.util.List<T> asList()
List<XdmItem>
. This is a terminal operation.List<XdmItem>
.public java.util.List<XdmNode> asListOfNodes()
List<XdmNode>
. This is a terminal operation.java.lang.ClassCastException
- if the stream contains an item that is not a nodepublic java.util.Optional<XdmNode> asOptionalNode()
Optional<XdmNode>
. This is a terminal operation.XdmCollectors.MultipleItemException
- if the stream contains more than one nodejava.lang.ClassCastException
- if the stream contains an item that is not a nodepublic XdmNode asNode()
XdmNode
. This is a terminal operation.java.lang.ClassCastException
- if the stream contains an item that is not a nodeXdmCollectors.MultipleItemException
- if the stream contains
more than one itemjava.util.NoSuchElementException
- if the stream is emptypublic java.util.List<XdmAtomicValue> asListOfAtomic()
List<XdmAtomicValue>
. This is a terminal operation.java.lang.ClassCastException
- if the stream contains an item that is not an atomic valuepublic java.util.Optional<XdmAtomicValue> asOptionalAtomic()
Optional<XdmAtomicValue>
. This is a terminal operation.XdmCollectors.MultipleItemException
- if the stream contains more than one itemjava.lang.ClassCastException
- if the stream contains an item that is not an atomic valuepublic XdmAtomicValue asAtomic()
XdmAtomicValue
. This is a terminal operation.java.lang.ClassCastException
- if the stream contains an item that is not atomicXdmCollectors.MultipleItemException
- if the stream contains more than one itemjava.util.NoSuchElementException
- if the stream is emptypublic java.util.Optional<java.lang.String> asOptionalString()
Optional<String>
. This is a terminal operation.XdmCollectors.MultipleItemException
- if the stream contains more than one itemjava.lang.UnsupportedOperationException
- if the stream contains an item that has no string value,
for example a function itempublic java.lang.String asString()
String
. This is a terminal operation.java.lang.UnsupportedOperationException
- if the stream contains an item that has no string value,
for example a function itemXdmCollectors.MultipleItemException
- if the stream contains more than one itemjava.util.NoSuchElementException
- if the stream is emptypublic XdmStream<T> first()
findFirst()
, but it returns
XdmStream<T>
rather than Optional<T>
so that further operations such
as atomize()
can be applied, and so that a typed result can be returned
using a method such as asOptionalNode()
or asOptionalString()
public boolean exists()
public XdmStream<T> last()
first()
; it returns
XdmStream<T>
rather than Optional<T>
so that further operations such
atomize()
can be applied, and so that a typed result can be returned
using a method such as asOptionalNode()
or asOptionalString()
public java.util.Optional<T> at(int position)
position
- the required position; items in the stream are numbered from zero.Optional.empty()
public XdmStream<T> subStream(int start, int end)
start
- the position of the first required item; items in the stream are numbered from zero.end
- the position immediately after the last required item.public XdmStream<T> untilFirstInclusive(java.util.function.Predicate<? super XdmItem> predicate)
predicate
- a condition that determines when the stream should stoppublic XdmStream<T> untilFirstExclusive(java.util.function.Predicate<? super XdmItem> predicate)
predicate
- a condition that determines when the stream should stopCopyright (c) 2004-2020 Saxonica Limited. All rights reserved.