public final class StreamSupport extends Object
This class is mostly for library writers presenting stream views
of data structures; most static stream methods intended for end users are in
the various Streams
classes.
Modifier and Type | Method and Description |
---|---|
static <T> Stream.Builder<T> |
builder()
Deprecated.
Use
RefStreams.builder() instead |
static <T> Stream<T> |
concat(Stream<? extends T> a,
Stream<? extends T> b)
Deprecated.
Use
RefStreams.concat(Stream, Stream) instead |
static DoubleStream |
doubleStream(Spliterator.OfDouble spliterator,
boolean parallel)
Creates a new sequential or parallel
DoubleStream from a
Spliterator.OfDouble . |
static DoubleStream |
doubleStream(Supplier<? extends Spliterator.OfDouble> supplier,
int characteristics,
boolean parallel)
Creates a new sequential or parallel
DoubleStream from a
Supplier of Spliterator.OfDouble . |
static <T> Stream<T> |
empty()
Deprecated.
Use
RefStreams.empty() instead |
static <T> Stream<T> |
generate(Supplier<? extends T> s)
Deprecated.
Use
RefStreams.generate(Supplier) instead |
static IntStream |
intStream(Spliterator.OfInt spliterator,
boolean parallel)
Creates a new sequential or parallel
IntStream from a
Spliterator.OfInt . |
static IntStream |
intStream(Supplier<? extends Spliterator.OfInt> supplier,
int characteristics,
boolean parallel)
Creates a new sequential or parallel
IntStream from a
Supplier of Spliterator.OfInt . |
static <T,S extends T> |
iterate(S seed,
UnaryOperator<S> f)
Deprecated.
Use
RefStreams.iterate(Object, UnaryOperator) instead |
static LongStream |
longStream(Spliterator.OfLong spliterator,
boolean parallel)
Creates a new sequential or parallel
LongStream from a
Spliterator.OfLong . |
static LongStream |
longStream(Supplier<? extends Spliterator.OfLong> supplier,
int characteristics,
boolean parallel)
Creates a new sequential or parallel
LongStream from a
Supplier of Spliterator.OfLong . |
static <T> Stream<T> |
of(T... values)
Deprecated.
Use
RefStreams.of(Object...) instead |
static <T> Stream<T> |
of(T t)
Deprecated.
Use
RefStreams.of(Object) instead |
static <T> Stream<T> |
ofNullable(T t)
Deprecated.
Use
RefStreams.ofNullable(Object) instead |
static <T> Stream<T> |
parallelStream(Collection<? extends T> c)
Creates a new possibly parallel
Stream using either the given
collection's Collection.iterator() as the source of
elements for an internally created Spliterator which will report
the collection's Collection.size() as its initial size
or a specialized Spliterator implementation (effectively the same
one that Java 8 uses) if the passed Collection is one of the
types listed below. |
static <T> Stream<T> |
stream(Collection<? extends T> c)
Creates a new sequential
Stream using either the given
collection's Collection.iterator() as the source of
elements for an internally created Spliterator which will report
the collection's Collection.size() as its initial size
or a specialized Spliterator implementation (effectively the same
one that Java 8 uses) if the passed Collection is one of the
types listed below. |
static <T> Stream<T> |
stream(Collection<? extends T> c,
int characteristics)
Creates a new sequential
Stream using the given collection's
Collection.iterator() as the source of elements for an
internally created Spliterator which will report the collection's
Collection.size() as its initial size. |
static <T> Stream<T> |
stream(Collection<? extends T> c,
int characteristics,
boolean parallel)
Creates a new sequential or parallel
Stream using the given
collection's Collection.iterator() as the source of
elements for an internally created Spliterator which will report
the collection's Collection.size() as its initial size. |
static <T> Stream<T> |
stream(Spliterator<T> spliterator,
boolean parallel)
Creates a new sequential or parallel
Stream from a
Spliterator . |
static <T> Stream<T> |
stream(Supplier<? extends Spliterator<T>> supplier,
int characteristics,
boolean parallel)
Creates a new sequential or parallel
Stream from a
Supplier of Spliterator . |
@Deprecated public static <T> Stream.Builder<T> builder()
RefStreams.builder()
insteadStream
.T
- type of elements@Deprecated public static <T> Stream<T> empty()
RefStreams.empty()
insteadStream
.T
- the type of stream elements@Deprecated public static <T> Stream<T> of(T t)
RefStreams.of(Object)
insteadStream
containing a single element.T
- the type of stream elementst
- the single element@Deprecated public static <T> Stream<T> ofNullable(T t)
RefStreams.ofNullable(Object)
insteadStream
containing a single element, if
non-null, otherwise returns an empty Stream
.T
- the type of stream elementst
- the single element@Deprecated public static <T> Stream<T> of(T... values)
RefStreams.of(Object...)
insteadT
- the type of stream elementsvalues
- the elements of the new stream@Deprecated public static <T,S extends T> Stream<T> iterate(S seed, UnaryOperator<S> f)
RefStreams.iterate(Object, UnaryOperator)
insteadStream
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 Stream
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
.
S
- the type of the operand and seed, a subtype of TT
- the type of stream elementsseed
- the initial elementf
- a function to be applied to the previous element to produce
a new elementStream
@Deprecated public static <T> Stream<T> generate(Supplier<? extends T> s)
RefStreams.generate(Supplier)
insteadSupplier
. This is suitable for
generating constant streams, streams of random elements, etc.T
- the type of stream elementss
- the Supplier
of generated elementsStream
@Deprecated public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)
RefStreams.concat(Stream, Stream)
insteadImplementation 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.
T
- The type of stream elementsa
- the first streamb
- the second streampublic static <T> Stream<T> stream(Collection<? extends T> c)
Stream
using either the given
collection's Collection.iterator()
as the source of
elements for an internally created Spliterator
which will report
the collection's Collection.size()
as its initial size
or a specialized Spliterator
implementation (effectively the same
one that Java 8 uses) if the passed Collection
is one of the
types listed below.
The Spliterator
s for CopyOnWriteArrayList
and
CopyOnWriteArraySet
provide a snapshot of the state of the
collection when the Stream
was created, otherwise the created
spliterator is
late-binding, inherits
the fail-fast properties of the collection's iterator, and
implements trySplit
to permit limited parallelism.
The created spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
T
- Type of elementsc
- The collectionStream
NullPointerException
- if the given collection is null
public static <T> Stream<T> parallelStream(Collection<? extends T> c)
Stream
using either the given
collection's Collection.iterator()
as the source of
elements for an internally created Spliterator
which will report
the collection's Collection.size()
as its initial size
or a specialized Spliterator
implementation (effectively the same
one that Java 8 uses) if the passed Collection
is one of the
types listed below.
The Spliterator
s for CopyOnWriteArrayList
and
CopyOnWriteArraySet
provide a snapshot of the state of the
collection when the Stream
was created, otherwise the created
spliterator is
late-binding, inherits
the fail-fast properties of the collection's iterator, and
implements trySplit
to permit limited parallelism.
The created spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
T
- Type of elementsc
- The collectionStream
NullPointerException
- if the given collection is null
public static <T> Stream<T> stream(Collection<? extends T> c, int characteristics)
Stream
using the given collection's
Collection.iterator()
as the source of elements for an
internally created Spliterator
which will report the collection's
Collection.size()
as its initial size.
The created spliterator is
late-binding, inherits
the fail-fast properties of the collection's iterator, and
implements trySplit
to permit limited parallelism.
The created spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
If the collection is immutable it is recommended to report a
characteristic of IMMUTABLE
. The characteristics SIZED
and SUBSIZED
are additionally (automatically) reported unless
CONCURRENT
is supplied.
T
- Type of elementsc
- The collectioncharacteristics
- Characteristics of the source collection's iterator or
elements. The characteristics SIZED
and
SUBSIZED
are additionally reported unless
CONCURRENT
is supplied.Stream
NullPointerException
- if the given collection is null
public static <T> Stream<T> stream(Collection<? extends T> c, int characteristics, boolean parallel)
Stream
using the given
collection's Collection.iterator()
as the source of
elements for an internally created Spliterator
which will report
the collection's Collection.size()
as its initial size.
The created spliterator is
late-binding, inherits
the fail-fast properties of the collection's iterator, and
implements trySplit
to permit limited parallelism.
The created spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
If possible for the collection, it is strongly recommended to report a
characteristic of IMMUTABLE
or CONCURRENT
especially if
you want a parallel Stream
. The characteristics SIZED
and
SUBSIZED
are additionally (automatically) reported unless
CONCURRENT
is supplied.
T
- Type of elementsc
- The collectioncharacteristics
- Characteristics of the source collection's iterator or
elements. The characteristics SIZED
and
SUBSIZED
are additionally reported unless
CONCURRENT
is supplied.parallel
- if true
then the returned stream is a parallel stream;
if false
the returned stream is a sequential stream.Stream
NullPointerException
- if the given collection is null
public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel)
Stream
from a
Spliterator
.
The spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
It is strongly recommended the spliterator report a characteristic of
IMMUTABLE
or CONCURRENT
, or be
late-binding. Otherwise,
stream(java8.util.function.Supplier, int, boolean)
should be used
to reduce the scope of potential interference with the source. See
Non-Interference for
more details.
T
- the type of stream elementsspliterator
- a Spliterator
describing the stream elementsparallel
- if true
then the returned stream is a parallel
stream; if false
the returned stream is a sequential
stream.Stream
public static <T> Stream<T> stream(Supplier<? extends Spliterator<T>> supplier, int characteristics, boolean parallel)
Stream
from a
Supplier
of Spliterator
.
The Supplier.get()
method will be invoked on the supplier no
more than once, and only after the terminal operation of the stream pipeline
commences.
For spliterators that report a characteristic of IMMUTABLE
or CONCURRENT
, or that are
late-binding, it is likely
more efficient to use stream(java8.util.Spliterator, boolean)
instead.
The use of a Supplier
in this form provides a level of
indirection that reduces the scope of potential interference with the
source. Since the supplier is only invoked after the terminal operation
commences, any modifications to the source up to the start of the
terminal operation are reflected in the stream result. See
Non-Interference for
more details.
T
- the type of stream elementssupplier
- a Supplier
of a Spliterator
characteristics
- Spliterator characteristics of the supplied
Spliterator
. The characteristics must be equal to
supplier.get().characteristics()
, otherwise undefined
behavior may occur when terminal operation commences.parallel
- if true
then the returned stream is a parallel
stream; if false
the returned stream is a sequential
stream.Stream
stream(java8.util.Spliterator, boolean)
public static IntStream intStream(Spliterator.OfInt spliterator, boolean parallel)
IntStream
from a
Spliterator.OfInt
.
The spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
It is strongly recommended the spliterator report a characteristic of
IMMUTABLE
or CONCURRENT
, or be
late-binding. Otherwise,
intStream(java8.util.function.Supplier, int, boolean)
should be
used to reduce the scope of potential interference with the source. See
Non-Interference for
more details.
spliterator
- a Spliterator.OfInt
describing the stream elementsparallel
- if true
then the returned stream is a parallel
stream; if false
the returned stream is a sequential
stream.IntStream
public static IntStream intStream(Supplier<? extends Spliterator.OfInt> supplier, int characteristics, boolean parallel)
IntStream
from a
Supplier
of Spliterator.OfInt
.
The Supplier.get()
method will be invoked on the supplier no
more than once, and only after the terminal operation of the stream pipeline
commences.
For spliterators that report a characteristic of IMMUTABLE
or CONCURRENT
, or that are
late-binding, it is likely
more efficient to use intStream(java8.util.Spliterator.OfInt, boolean)
instead.
The use of a Supplier
in this form provides a level of
indirection that reduces the scope of potential interference with the
source. Since the supplier is only invoked after the terminal operation
commences, any modifications to the source up to the start of the
terminal operation are reflected in the stream result. See
Non-Interference for
more details.
supplier
- a Supplier
of a Spliterator.OfInt
characteristics
- Spliterator characteristics of the supplied
Spliterator.OfInt
. The characteristics must be equal to
supplier.get().characteristics()
, otherwise undefined
behavior may occur when terminal operation commences.parallel
- if true
then the returned stream is a parallel
stream; if false
the returned stream is a sequential
stream.IntStream
intStream(java8.util.Spliterator.OfInt, boolean)
public static LongStream longStream(Spliterator.OfLong spliterator, boolean parallel)
LongStream
from a
Spliterator.OfLong
.
The spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
It is strongly recommended the spliterator report a characteristic of
IMMUTABLE
or CONCURRENT
, or be
late-binding. Otherwise,
longStream(java8.util.function.Supplier, int, boolean)
should be
used to reduce the scope of potential interference with the source. See
Non-Interference for
more details.
spliterator
- a Spliterator.OfLong
describing the stream elementsparallel
- if true
then the returned stream is a parallel
stream; if false
the returned stream is a sequential
stream.LongStream
public static LongStream longStream(Supplier<? extends Spliterator.OfLong> supplier, int characteristics, boolean parallel)
LongStream
from a
Supplier
of Spliterator.OfLong
.
The Supplier.get()
method will be invoked on the supplier no
more than once, and only after the terminal operation of the stream pipeline
commences.
For spliterators that report a characteristic of IMMUTABLE
or CONCURRENT
, or that are
late-binding, it is likely
more efficient to use longStream(java8.util.Spliterator.OfLong, boolean)
instead.
The use of a Supplier
in this form provides a level of
indirection that reduces the scope of potential interference with the
source. Since the supplier is only invoked after the terminal operation
commences, any modifications to the source up to the start of the
terminal operation are reflected in the stream result. See
Non-Interference for
more details.
supplier
- a Supplier
of a Spliterator.OfLong
characteristics
- Spliterator characteristics of the supplied
Spliterator.OfLong
. The characteristics must be equal to
supplier.get().characteristics()
, otherwise undefined
behavior may occur when terminal operation commences.parallel
- if true
then the returned stream is a parallel
stream; if false
the returned stream is a sequential
stream.LongStream
longStream(java8.util.Spliterator.OfLong, boolean)
public static DoubleStream doubleStream(Spliterator.OfDouble spliterator, boolean parallel)
DoubleStream
from a
Spliterator.OfDouble
.
The spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
It is strongly recommended the spliterator report a characteristic of
IMMUTABLE
or CONCURRENT
, or be
late-binding. Otherwise,
doubleStream(java8.util.function.Supplier, int, boolean)
should
be used to reduce the scope of potential interference with the source. See
Non-Interference for
more details.
spliterator
- A Spliterator.OfDouble
describing the stream elementsparallel
- if true
then the returned stream is a parallel
stream; if false
the returned stream is a sequential
stream.DoubleStream
public static DoubleStream doubleStream(Supplier<? extends Spliterator.OfDouble> supplier, int characteristics, boolean parallel)
DoubleStream
from a
Supplier
of Spliterator.OfDouble
.
The Supplier.get()
method will be invoked on the supplier no
more than once, and only after the terminal operation of the stream pipeline
commences.
For spliterators that report a characteristic of IMMUTABLE
or CONCURRENT
, or that are
late-binding, it is likely
more efficient to use doubleStream(java8.util.Spliterator.OfDouble, boolean)
instead.
The use of a Supplier
in this form provides a level of
indirection that reduces the scope of potential interference with the
source. Since the supplier is only invoked after the terminal operation
commences, any modifications to the source up to the start of the
terminal operation are reflected in the stream result. See
Non-Interference for
more details.
supplier
- A Supplier
of a Spliterator.OfDouble
characteristics
- Spliterator characteristics of the supplied
Spliterator.OfDouble
. The characteristics must be equal to
supplier.get().characteristics()
, otherwise undefined
behavior may occur when terminal operation commences.parallel
- if true
then the returned stream is a parallel
stream; if false
the returned stream is a sequential
stream.DoubleStream
doubleStream(java8.util.Spliterator.OfDouble, boolean)
Copyright © 2015. All rights reserved.