public final class DoubleStreams extends Object
takeWhile(),
dropWhile()) in the DoubleStream interface.| Modifier and Type | Method and Description |
|---|---|
static DoubleStream.Builder |
builder()
Returns a builder for a
DoubleStream. |
static DoubleStream |
concat(DoubleStream a,
DoubleStream b)
Creates a lazily concatenated stream whose elements are all the
elements of the first stream followed by all the elements of the
second stream.
|
static DoubleStream |
dropWhile(DoubleStream stream,
DoublePredicate predicate)
Returns a stream consisting of the remaining elements of the passed
stream after discarding elements that match the given predicate up to,
but not discarding, the first element encountered that does not match the
predicate.
|
static DoubleStream |
empty()
Returns an empty sequential
DoubleStream. |
static DoubleStream |
generate(DoubleSupplier s)
Returns an infinite sequential unordered stream where each element is
generated by the provided
DoubleSupplier. |
static DoubleStream |
iterate(double seed,
DoublePredicate hasNext,
DoubleUnaryOperator next)
Returns a sequential ordered
DoubleStream produced by iterative
application of the given next function to an initial element,
conditioned on satisfying the given hasNext predicate. |
static DoubleStream |
iterate(double seed,
DoubleUnaryOperator f)
Returns an infinite sequential ordered
DoubleStream produced by iterative
application of a function f to an initial element seed,
producing a Stream consisting of seed, f(seed),
f(f(seed)), etc. |
static DoubleStream |
of(double... values)
Returns a sequential ordered stream whose elements are the specified values.
|
static DoubleStream |
of(double t)
Returns a sequential
DoubleStream containing a single element. |
static DoubleStream |
takeWhile(DoubleStream stream,
DoublePredicate predicate)
Returns a stream consisting of elements of the passed stream that match
the given predicate up to, but discarding, the first element encountered
that does not match the predicate.
|
public static DoubleStream takeWhile(DoubleStream stream, DoublePredicate predicate)
stream - the stream to wrap for the takeWhile() operationpredicate - a non-interfering,
predicate to apply to each element to determine if it
should be included, or it and all subsequently
encountered elements be discarded.public static DoubleStream dropWhile(DoubleStream stream, DoublePredicate predicate)
This is a stateful intermediate operation.
stream - the stream to wrap for the dropWhile() operationpredicate - a non-interfering,
predicate to apply to each element to determine if it
should be discarded, or it and all subsequently
encountered elements be included.public static DoubleStream.Builder builder()
DoubleStream.public static DoubleStream empty()
DoubleStream.public static DoubleStream of(double t)
DoubleStream containing a single element.t - the single elementpublic static DoubleStream of(double... values)
values - the elements of the new streampublic static DoubleStream iterate(double seed, DoubleUnaryOperator f)
DoubleStream produced by iterative
application of a function f to an initial element seed,
producing a Stream consisting of seed, f(seed),
f(f(seed)), etc.
The first element (position 0) in the DoubleStream
will be the provided seed. For n > 0, the element at
position n, will be the result of applying the function f
to the element at position n - 1.
The action of applying f for one element
happens-before
the action of applying f for subsequent elements. For any given
element the action may be performed in whatever thread the library
chooses.
seed - the initial elementf - a function to be applied to the previous element to produce
a new elementDoubleStreampublic static DoubleStream iterate(double seed, DoublePredicate hasNext, DoubleUnaryOperator next)
DoubleStream produced by iterative
application of the given next function to an initial element,
conditioned on satisfying the given hasNext predicate. The
stream terminates as soon as the hasNext predicate returns false.
DoubleStreams.iterate should produce the same sequence of
elements as produced by the corresponding for-loop:
for (double index=seed; hasNext.test(index); index = next.applyAsDouble(index)) {
...
}
The resulting sequence may be empty if the hasNext predicate
does not hold on the seed value. Otherwise the first element will be the
supplied seed value, the next element (if present) will be the
result of applying the next function to the seed value,
and so on iteratively until the hasNext predicate indicates that
the stream should terminate.
The action of applying the hasNext predicate to an element
happens-before
the action of applying the next function to that element. The
action of applying the next function for one element
happens-before the action of applying the hasNext
predicate for subsequent elements. For any given element an action may
be performed in whatever thread the library chooses.
seed - the initial elementhasNext - a predicate to apply to elements to determine when the
stream must terminatenext - a function to be applied to the previous element to produce
a new elementDoubleStreampublic static DoubleStream generate(DoubleSupplier s)
DoubleSupplier. This is suitable for
generating constant streams, streams of random elements, etc.s - the DoubleSupplier for generated elementsDoubleStreampublic static DoubleStream concat(DoubleStream a, DoubleStream b)
This method operates on the two input streams and binds each stream to its source. As a result subsequent modifications to an input stream source may not be reflected in the concatenated stream result.
Implementation Note:
Use caution when constructing streams from repeated concatenation.
Accessing an element of a deeply concatenated stream can result in deep
call chains, or even StackOverflowError.
Subsequent changes to the sequential/parallel execution mode of the returned stream are not guaranteed to be propagated to the input streams.
API Note:
To preserve optimization opportunities this method binds each stream to
its source and accepts only two streams as parameters. For example, the
exact size of the concatenated stream source can be computed if the exact
size of each input stream source is known.
To concatenate more streams without binding, or without nested calls to
this method, try creating a stream of streams and flat-mapping with the
identity function, for example:
DoubleStream concat = RefStreams.of(s1, s2, s3, s4).flatMapToDouble(s -> s);
a - the first streamb - the second streamCopyright © 2018. All rights reserved.