Spec-Zone .ru
спецификации, руководства, описания, API
|
Constructor and Description |
---|
DelegatingStream(Stream<T> delegate)
Construct a
Stream that delegates operations to another Stream . |
Modifier and Type | Method and Description |
---|---|
boolean |
allMatch(Predicate<? super T> predicate)
Returns whether all elements of this stream match the provided predicate.
|
boolean |
anyMatch(Predicate<? super T> predicate)
Returns whether any elements of this stream match the provided
predicate.
|
<R> R |
collect(Collector<? super T,R> collector)
Performs a mutable
reduction operation on the elements of this stream using a
Collector object to describe the reduction. |
<R> R |
collect(Supplier<R> resultFactory,
BiConsumer<R,? super T> accumulator,
BiConsumer<R,R> combiner)
Performs a mutable
reduction operation on the elements of this stream.
|
long |
count()
Returns the count of elements in this stream.
|
Stream<T> |
distinct()
Returns a stream consisting of the distinct elements (according to
Object.equals(Object) ) of this stream. |
Stream<T> |
filter(Predicate<? super T> predicate)
Returns a stream consisting of the elements of this stream that match
the given predicate.
|
Optional<T> |
findAny()
Returns an
Optional describing some element of the stream, or an
empty Optional if the stream is empty. |
Optional<T> |
findFirst()
Returns an
Optional describing the first element of this stream
(in the encounter order), or an empty Optional if the stream is
empty. |
<R> Stream<R> |
flatMap(Function<? super T,? extends Stream<? extends R>> mapper)
Returns a stream consisting of the results of replacing each element of
this stream with the contents of the stream produced by applying the
provided mapping function to each element.
|
DoubleStream |
flatMapToDouble(Function<? super T,? extends DoubleStream> mapper)
Returns a
DoubleStream consisting of the results of replacing each
element of this stream with the contents of the stream produced
by applying the provided mapping function to each element. |
IntStream |
flatMapToInt(Function<? super T,? extends IntStream> mapper)
Returns an
IntStream consisting of the results of replacing each
element of this stream with the contents of the stream produced by
applying the provided mapping function to each element. |
LongStream |
flatMapToLong(Function<? super T,? extends LongStream> mapper)
Returns a
LongStream consisting of the results of replacing each
element of this stream with the contents of the stream produced
by applying the provided mapping function to each element. |
void |
forEach(Consumer<? super T> action)
Performs an action for each element of this stream.
|
void |
forEachOrdered(Consumer<? super T> action)
Performs an action for each element of this stream, guaranteeing that
each element is processed in encounter order for streams that have a
defined encounter order.
|
boolean |
isParallel()
Returns whether this stream, when executed, would execute in parallel
(assuming no further modification of the stream, such as appending
further intermediate operations or changing its parallelism).
|
Iterator<T> |
iterator()
Returns an iterator for the elements of this stream.
|
Stream<T> |
limit(long maxSize)
Returns a stream consisting of the elements of this stream, truncated
to be no longer than
maxSize in length. |
<R> Stream<R> |
map(Function<? super T,? extends R> mapper)
Returns a stream consisting of the results of applying the given
function to the elements of this stream.
|
DoubleStream |
mapToDouble(ToDoubleFunction<? super T> mapper)
Returns a
DoubleStream consisting of the results of applying the
given function to the elements of this stream. |
IntStream |
mapToInt(ToIntFunction<? super T> mapper)
Returns an
IntStream consisting of the results of applying the
given function to the elements of this stream. |
LongStream |
mapToLong(ToLongFunction<? super T> mapper)
Returns a
LongStream consisting of the results of applying the
given function to the elements of this stream. |
Optional<T> |
max(Comparator<? super T> comparator)
Returns the maximum element of this stream according to the provided
Comparator . |
Optional<T> |
min(Comparator<? super T> comparator)
Returns the minimum element of this stream according to the provided
Comparator . |
boolean |
noneMatch(Predicate<? super T> predicate)
Returns whether no elements of this stream match the provided predicate.
|
Stream<T> |
parallel()
Returns an equivalent stream that is parallel.
|
Stream<T> |
peek(Consumer<? super T> consumer)
Returns a stream consisting of the elements of this stream, additionally
performing the provided action on each element as elements are consumed
from the resulting stream.
|
Optional<T> |
reduce(BinaryOperator<T> accumulator)
Performs a reduction on the
elements of this stream, using an
associative accumulation
function, and returns an
Optional describing the reduced value,
if any. |
T |
reduce(T identity,
BinaryOperator<T> accumulator)
Performs a reduction on the
elements of this stream, using the provided identity value and an
associative
accumulation function, and returns the reduced value.
|
<U> U |
reduce(U identity,
BiFunction<U,? super T,U> accumulator,
BinaryOperator<U> combiner)
Performs a reduction on the
elements of this stream, using the provided identity, accumulation
function, and a combining functions.
|
Stream<T> |
sequential()
Returns an equivalent stream that is sequential.
|
Stream<T> |
sorted()
Returns a stream consisting of the elements of this stream, sorted
according to natural order.
|
Stream<T> |
sorted(Comparator<? super T> comparator)
Returns a stream consisting of the elements of this stream, sorted
according to the provided
Comparator . |
Spliterator<T> |
spliterator()
Returns a spliterator for the elements of this stream.
|
Stream<T> |
substream(long startingOffset)
Returns a stream consisting of the remaining elements of this stream
after indexing
startInclusive elements into the stream. |
Stream<T> |
substream(long startingOffset,
long endingOffset)
Returns a stream consisting of the remaining elements of this stream
after indexing
startInclusive elements into the stream and
truncated to contain no more than endExclusive - startInclusive
elements. |
Object[] |
toArray()
Returns an array containing the elements of this stream.
|
<A> A[] |
toArray(IntFunction<A[]> generator)
Returns an array containing the elements of this stream, using the
provided
generator function to allocate the returned array. |
Stream<T> |
unordered()
Returns an equivalent stream that is
unordered.
|
public DelegatingStream(Stream<T> delegate)
Stream
that delegates operations to another Stream
.delegate
- the underlying Stream
to which we delegate all
Stream
methodsNullPointerException
- if the delegate is nullpublic Spliterator<T> spliterator()
This is a terminal operation.
public boolean isParallel()
true
if this stream would execute in parallel if executed
without further modification otherwise false
public Iterator<T> iterator()
This is a terminal operation.
public Stream<T> filter(Predicate<? super T> predicate)
Stream
This is an intermediate operation.
filter
in interface Stream<T>
predicate
- a
non-interfering, stateless predicate to apply to
each element to determine if it should be includedpublic <R> Stream<R> map(Function<? super T,? extends R> mapper)
Stream
This is an intermediate operation.
map
in interface Stream<T>
R
- The element type of the new streammapper
- a
non-interfering, stateless function to apply to each
elementpublic IntStream mapToInt(ToIntFunction<? super T> mapper)
Stream
IntStream
consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapToInt
in interface Stream<T>
mapper
- a
non-interfering, stateless function to apply to each
elementpublic LongStream mapToLong(ToLongFunction<? super T> mapper)
Stream
LongStream
consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapToLong
in interface Stream<T>
mapper
- a
non-interfering, stateless function to apply to each
elementpublic DoubleStream mapToDouble(ToDoubleFunction<? super T> mapper)
Stream
DoubleStream
consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapToDouble
in interface Stream<T>
mapper
- a
non-interfering, stateless function to apply to each
elementpublic <R> Stream<R> flatMap(Function<? super T,? extends Stream<? extends R>> mapper)
Stream
null
, this is treated as if the result is an empty
stream.
This is an intermediate operation.
flatMap
in interface Stream<T>
R
- The element type of the new streammapper
- a
non-interfering, stateless function to apply to each
element which produces a stream of new valuespublic IntStream flatMapToInt(Function<? super T,? extends IntStream> mapper)
Stream
IntStream
consisting of the results of replacing each
element of this stream with the contents of the stream produced by
applying the provided mapping function to each element. If the result of
the mapping function is null
, this is treated as if the result is
an empty stream.
This is an intermediate operation.
flatMapToInt
in interface Stream<T>
mapper
- a
non-interfering, stateless function to apply to each
element which produces a stream of new valuespublic LongStream flatMapToLong(Function<? super T,? extends LongStream> mapper)
Stream
LongStream
consisting of the results of replacing each
element of this stream with the contents of the stream produced
by applying the provided mapping function to each element. If the result
of the mapping function is null
, this is treated as if the
result is an empty stream.
This is an intermediate operation.
flatMapToLong
in interface Stream<T>
mapper
- a
non-interfering, stateless function to apply to
each element which produces a stream of new valuespublic DoubleStream flatMapToDouble(Function<? super T,? extends DoubleStream> mapper)
Stream
DoubleStream
consisting of the results of replacing each
element of this stream with the contents of the stream produced
by applying the provided mapping function to each element. If the result
of the mapping function is null
, this is treated as if the result
is an empty stream.
This is an intermediate operation.
flatMapToDouble
in interface Stream<T>
mapper
- a
non-interfering, stateless function to apply to each
element which produces a stream of new valuespublic Stream<T> distinct()
Stream
Object.equals(Object)
) of this stream.
This is a stateful intermediate operation.
public Stream<T> sorted()
Stream
Comparable
, a java.lang.ClassCastException
may be thrown
when the stream pipeline is executed.
This is a stateful intermediate operation.
public Stream<T> sorted(Comparator<? super T> comparator)
Stream
Comparator
.
This is a stateful intermediate operation.
sorted
in interface Stream<T>
comparator
- a
non-interfering, stateless Comparator
to
be used to compare stream elementspublic void forEach(Consumer<? super T> action)
Stream
This is a terminal operation.
For parallel stream pipelines, this operation does not guarantee to respect the encounter order of the stream, as doing so would sacrifice the benefit of parallelism. For any given element, the action may be performed at whatever time and in whatever thread the library chooses. If the action accesses shared state, it is responsible for providing the required synchronization.
forEach
in interface Stream<T>
action
- a
non-interfering action to perform on the elementspublic void forEachOrdered(Consumer<? super T> action)
Stream
This is a terminal operation.
forEachOrdered
in interface Stream<T>
action
- a
non-interfering action to perform on the elementsStream.forEach(Consumer)
public Stream<T> peek(Consumer<? super T> consumer)
Stream
This is an intermediate operation.
For parallel stream pipelines, the action may be called at whatever time and in whatever thread the element is made available by the upstream operation. If the action modifies shared state, it is responsible for providing the required synchronization.
peek
in interface Stream<T>
consumer
- a
non-interfering action to perform on the elements as
they are consumed from the streampublic Stream<T> limit(long maxSize)
Stream
maxSize
in length.
public Stream<T> substream(long startingOffset)
Stream
startInclusive
elements into the stream. If the
startInclusive
index lies past the end of this stream then an
empty stream will be returned.
This is a stateful intermediate operation.
public Stream<T> substream(long startingOffset, long endingOffset)
Stream
startInclusive
elements into the stream and
truncated to contain no more than endExclusive - startInclusive
elements. If the startInclusive
index lies past the end
of this stream then an empty stream will be returned.
public <A> A[] toArray(IntFunction<A[]> generator)
Stream
generator
function to allocate the returned array.
This is a terminal operation.
public Object[] toArray()
Stream
This is a terminal operation.
public T reduce(T identity, BinaryOperator<T> accumulator)
Stream
T result = identity;
for (T element : this stream)
result = accumulator.apply(result, element)
return result;
but is not constrained to execute sequentially.
The identity
value must be an identity for the accumulator
function. This means that for all t
,
accumulator.apply(identity, t)
is equal to t
.
The accumulator
function must be an
associative function.
This is a terminal operation.
reduce
in interface Stream<T>
identity
- the identity value for the accumulating functionaccumulator
- an associative
non-interfering,
stateless function for combining two valuespublic Optional<T> reduce(BinaryOperator<T> accumulator)
Stream
Optional
describing the reduced value,
if any. This is equivalent to:
boolean foundAny = false;
T result = null;
for (T element : this stream) {
if (!foundAny) {
foundAny = true;
result = element;
}
else
result = accumulator.apply(result, element);
}
return foundAny ? Optional.of(result) : Optional.empty();
but is not constrained to execute sequentially.
The accumulator
function must be an
associative function.
This is a terminal operation.
reduce
in interface Stream<T>
accumulator
- an associative
non-interfering,
stateless function for combining two valuesStream.reduce(Object, BinaryOperator)
,
Stream.min(java.util.Comparator)
,
Stream.max(java.util.Comparator)
public <U> U reduce(U identity, BiFunction<U,? super T,U> accumulator, BinaryOperator<U> combiner)
Stream
U result = identity;
for (T element : this stream)
result = accumulator.apply(result, element)
return result;
but is not constrained to execute sequentially.
The identity
value must be an identity for the combiner
function. This means that for all u
, combiner(identity, u)
is equal to u
. Additionally, the combiner
function
must be compatible with the accumulator
function; for all
u
and t
, the following must hold:
combiner.apply(u, accumulator.apply(identity, t)) == accumulator.apply(u, t)
This is a terminal operation.
reduce
in interface Stream<T>
U
- The type of the resultidentity
- the identity value for the combiner functionaccumulator
- an associative
non-interfering,
stateless function for incorporating an additional
element into a resultcombiner
- an associative
non-interfering,
stateless function for combining two values, which
must be compatible with the accumulator functionStream.reduce(BinaryOperator)
,
Stream.reduce(Object, BinaryOperator)
public <R> R collect(Supplier<R> resultFactory, BiConsumer<R,? super T> accumulator, BiConsumer<R,R> combiner)
Stream
ArrayList
, and elements are incorporated by updating
the state of the result, rather than by replacing the result. This
produces a result equivalent to:
R result = resultFactory.get();
for (T element : this stream)
accumulator.accept(result, element);
return result;
Like Stream.reduce(Object, BinaryOperator)
, collect
operations
can be parallelized without requiring additional synchronization.
This is a terminal operation.
collect
in interface Stream<T>
R
- type of the resultresultFactory
- a function that creates a new result container.
For a parallel execution, this function may be
called multiple times and must return a fresh value
each time.accumulator
- an associative
non-interfering,
stateless function for incorporating an additional
element into a resultcombiner
- an associative
non-interfering,
stateless function for combining two values, which
must be compatible with the accumulator functionpublic <R> R collect(Collector<? super T,R> collector)
Stream
Collector
object to describe the reduction. A Collector
encapsulates the functions used as arguments to
Stream.collect(Supplier, BiConsumer, BiConsumer)
, allowing for reuse of
collection strategies, and composition of collect operations such as
multiple-level grouping or partitioning.
This is a terminal operation.
When executed in parallel, multiple intermediate results may be
instantiated, populated, and merged, so as to maintain isolation of
mutable data structures. Therefore, even when executed in parallel
with non-thread-safe data structures (such as ArrayList
), no
additional synchronization is needed for a parallel reduction.
collect
in interface Stream<T>
R
- the type of the resultcollector
- the Collector
describing the reductionStream.collect(Supplier, BiConsumer, BiConsumer)
,
Collectors
public Optional<T> max(Comparator<? super T> comparator)
Stream
Comparator
. This is a special case of a
reduction.
This is a terminal operation.
max
in interface Stream<T>
comparator
- a non-interfering,
stateless Comparator
to use to compare
elements of this streamOptional
describing the maximum element of this stream,
or an empty Optional
if the stream is emptypublic Optional<T> min(Comparator<? super T> comparator)
Stream
Comparator
. This is a special case of a
reduction.
This is a terminal operation.
min
in interface Stream<T>
comparator
- a non-interfering,
stateless Comparator
to use to compare
elements of this streamOptional
describing the minimum element of this stream,
or an empty Optional
if the stream is emptypublic long count()
Stream
return mapToLong(e -> 1L).sum();
This is a terminal operation.
public boolean anyMatch(Predicate<? super T> predicate)
Stream
This is a short-circuiting terminal operation.
anyMatch
in interface Stream<T>
predicate
- a non-interfering,
stateless predicate to apply to elements of this
streamtrue
if any elements of the stream match the provided
predicate otherwise false
public boolean allMatch(Predicate<? super T> predicate)
Stream
This is a short-circuiting terminal operation.
allMatch
in interface Stream<T>
predicate
- a non-interfering,
stateless predicate to apply to elements of this
streamtrue
if all elements of the stream match the provided
predicate otherwise false
public boolean noneMatch(Predicate<? super T> predicate)
Stream
This is a short-circuiting terminal operation.
noneMatch
in interface Stream<T>
predicate
- a non-interfering,
stateless predicate to apply to elements of this
streamtrue
if no elements of the stream match the provided
predicate otherwise false
public Optional<T> findFirst()
Stream
Optional
describing the first element of this stream
(in the encounter order), or an empty Optional
if the stream is
empty. If the stream has no encounter order, than any element may be
returned.
This is a short-circuiting terminal operation.
public Optional<T> findAny()
Stream
Optional
describing some element of the stream, or an
empty Optional
if the stream is empty.
This is a short-circuiting terminal operation.
The behavior of this operation is explicitly nondeterministic; it is
free to select any element in the stream. This is to allow for maximal
performance in parallel operations; the cost is that multiple invocations
on the same source may not return the same result. (If the first element
in the encounter order is desired, use Stream.findFirst()
instead.)
findAny
in interface Stream<T>
Optional
describing some element of this stream, or an
empty Optional
if the stream is emptyStream.findFirst()
public Stream<T> unordered()
This is an intermediate operation.
public Stream<T> sequential()
This is an intermediate operation.
public Stream<T> parallel()
This is an intermediate operation.
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2013, Oracle and/or its affiliates. All rights reserved.
DRAFT ea-b92