Deprecated
java.util.stream package, or more generally, with Java 8 lambdas. More
specifically, it attempts to address the fact that lambdas are supposed
not to throw Exceptions, at least not checked Exceptions, AKA instances
of Exception. This enforces the use of constructs like
Consumer<java.lang.reflect.Method> consumer = m -> {
try {
m.invoke(o, args);
} catch (Throwable t) {
throw Functions.rethrow(t);
}
};
stream.forEach(consumer);
Using a FailableStream, this can be rewritten as follows:
Streams.failable(stream).forEach(m -> m.invoke(o, args));
Obviously, the second version is much more concise and the spirit of
Lambda expressions is met better than in the first version.
Stream, Functions
| Modifier and Type | Class and Description |
|---|---|
| public static class | Streams.
The array type. O>
Deprecated
Use A Collector type for arrays.
org..
|
| public static class | Streams.
The streams element type. O>
Deprecated
Use A reduced, and simplified version of a org..
Stream with
failable method signatures.
|
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static < The streams element type. O> Streams. | Returns: TheFailableStream, which has been created by
converting the stream.The stream, which is being converted. stream)
References Deprecated
Streams.FailableStream is deprecated or references (maybe indirectly) at least one deprecated element.
Converts the given |
| public static < The streams element type. O> Streams. | Returns: TheFailableStream, which has been created by
converting the stream.The stream, which is being converted. stream)
References Deprecated
Streams.FailableStream is deprecated or references (maybe indirectly) at least one deprecated element.
Converts the given |
| public static < the type of the input elements. O> Collector |
| Streams | back to summary |
|---|---|
| public Streams() Constructs a new instance. | |
| stream | back to summary |
|---|---|
| public static <O> Streams. References Deprecated
See corresponding docs for further information. Converts the given
as follows:
While the second version may not be quite as
efficient (because it depends on the creation of additional,
intermediate objects, of type FailableStream), it is much more
concise, and readable, and meets the spirit of Lambdas better
than the first version.
| |
| stream | back to summary |
|---|---|
| public static <O> Streams. References Deprecated
See corresponding docs for further information. Converts the given
as follows:
While the second version may not be quite as
efficient (because it depends on the creation of additional,
intermediate objects, of type FailableStream), it is much more
concise, and readable, and meets the spirit of Lambdas better
than the first version.
| |
| toArray | back to summary |
|---|---|
| public static <O> Collector Returns a | |
Deprecated
| Modifier and Type | Field and Description |
|---|---|
| private static final Set | |
| private final Class |
| Access | Constructor and Description |
|---|---|
| public | ArrayCollector(final Class<O>
The element type. elementType)Constructs a new instance for the given element type. |
| Modifier and Type | Method and Description |
|---|---|
| public BiConsumer | accumulator()
Implements java. A function that folds a value into a mutable result container. |
| public Set | characteristics()
Implements java. Returns a |
| public BinaryOperator | combiner()
Implements java. A function that accepts two partial results and merges them. |
| public Function | finisher()
Implements java. Perform the final transformation from the intermediate accumulation type
|
| public Supplier | supplier()
Implements java. A function that creates and returns a new mutable result container. |
| characteristics | back to summary |
|---|---|
| private static final Set<Collector. | |
| elementType | back to summary |
|---|---|
| private final Class<O> elementType | |
| ArrayCollector | back to summary |
|---|---|
| public ArrayCollector(final Class<O> elementType) Constructs a new instance for the given element type.
| |
| accumulator | back to summary |
|---|---|
| public BiConsumer Implements java. Doc from java. A function that folds a value into a mutable result container.
| |
| characteristics | back to summary |
|---|---|
| public Set Implements java. Doc from java. Returns a
| |
| combiner | back to summary |
|---|---|
| public BinaryOperator Implements java. Doc from java. A function that accepts two partial results and merges them. The combiner function may fold state from one argument into the other and return that, or may return a new result container.
| |
| finisher | back to summary |
|---|---|
| public Function Implements java. Doc from java. Perform the final transformation from the intermediate accumulation type
If the characteristic
| |
| supplier | back to summary |
|---|---|
| public Supplier Implements java. Doc from java. A function that creates and returns a new mutable result container.
| |
Deprecated
Stream with
failable method signatures.
| Modifier and Type | Field and Description |
|---|---|
| private Stream | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true If either all elements of the stream match the
provided predicate or the stream is empty, otherwise false.A non-interfering, stateless predicate to apply to
elements of this stream. predicate
References Deprecated
Functions.FailablePredicate is deprecated or references (maybe indirectly) at least one deprecated element.
Returns whether all elements of this stream match the provided predicate. |
| public boolean | Returns: true if any elements of the stream match the provided
predicate, otherwise false.A non-interfering, stateless predicate to apply to
elements of this stream. predicate
References Deprecated
Functions.FailablePredicate is deprecated or references (maybe indirectly) at least one deprecated element.
Returns whether any elements of this stream match the provided predicate. |
| protected void | |
| public < the intermediate accumulation type of the A, Collector.the type of the result. R> R | |
| public < Type of the accumulator. A, type of the result. R> R | Returns: The result of the reduction.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. supplier, final BiConsumer<R, ? super O> An associative, non-interfering, stateless function for
incorporating an additional element into a result. accumulator, final BiConsumer<R, R> An associative, non-interfering, stateless
function for combining two values, which must be compatible with the
accumulator function. combiner)Performs a mutable reduction operation on the elements of this FailableStream. |
| public Streams. | Returns: the new stream.a non-interfering, stateless predicate to apply to each
element to determine if it should be included. predicate
References Deprecated
Functions.FailablePredicate and Streams.FailableStream are deprecated or reference (maybe indirectly) at least one deprecated element.
Returns a FailableStream consisting of the elements of this stream that match the given FailablePredicate. |
| public void | forEach(final Functions.
a non-interfering action to perform on the elements. action
References Deprecated
Functions.FailableConsumer is deprecated or references (maybe indirectly) at least one deprecated element.
Performs an action for each element of this stream. |
| protected void | |
| public < The element type of the new stream. R> Streams. | Returns: the new stream.A non-interfering, stateless function to apply to each element. mapper
References Deprecated
Functions.FailableFunction and Streams.FailableStream are deprecated or reference (maybe indirectly) at least one deprecated element.
Returns a stream consisting of the results of applying the given function to the elements of this stream. |
| public O | Returns: the result of the reduction.the identity value for the accumulating function. identity, final BinaryOperator<O> an associative, non-interfering, stateless
function for combining two values. 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. |
| public Stream | Returns: A stream, which will return the same elements, which this FailableStream would return.Converts the FailableStream into an equivalent stream. |
| stream | back to summary |
|---|---|
| private Stream<O> stream | |
| terminated | back to summary |
|---|---|
| private boolean terminated | |
| FailableStream | back to summary |
|---|---|
| public FailableStream(final Stream<O> stream) Constructs a new instance with the given
| |
| allMatch | back to summary |
|---|---|
| public boolean allMatch(final Functions. References Deprecated
See corresponding docs for further information. Returns whether all elements of this stream match the provided predicate.
May not evaluate the predicate on all elements if not necessary for
determining the result. If the stream is empty then This is a short-circuiting terminal operation.
Note
This method evaluates the universal quantification of the
predicate over the elements of the stream (for all x P(x)). If the
stream is empty, the quantification is said to be vacuously
satisfied and is always
| |
| anyMatch | back to summary |
|---|---|
| public boolean anyMatch(final Functions. References Deprecated
See corresponding docs for further information. Returns whether any elements of this stream match the provided
predicate. May not evaluate the predicate on all elements if not
necessary for determining the result. If the stream is empty then
This is a short-circuiting terminal operation. Note This method evaluates the existential quantification of the predicate over the elements of the stream (for some x P(x)).
| |
| assertNotTerminated | back to summary |
|---|---|
| protected void assertNotTerminated() Throws IllegalStateException if this stream is already terminated.
| |
| collect | back to summary |
|---|---|
| public <A, R> R collect(final Collector<? super O, A, R> collector) Performs a mutable reduction operation on the elements of this stream using a
If the underlying stream is parallel, and the This is an intermediate 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 Note The following will accumulate strings into an ArrayList:
The following will classify
The following will classify
| |
| collect | back to summary |
|---|---|
| public <A, R> R collect(final Supplier<R> supplier, final BiConsumer<R, ? super O> accumulator, final BiConsumer<R, R> combiner) Performs a mutable reduction operation on the elements of this FailableStream.
A mutable reduction is one in which the reduced value is a mutable result
container, such as an
Like This is an intermediate operation.
Note There are many existing classes in the JDK whose signatures are
well-suited for use with method references as arguments to
The following will take a stream of strings and concatenates them into a single string:
| |
| filter | back to summary |
|---|---|
| public Streams. References Deprecated
See corresponding docs for further information. Returns a FailableStream consisting of the elements of this stream that match the given FailablePredicate. This is an intermediate operation.
| |
| forEach | back to summary |
|---|---|
| public void forEach(final Functions. References Deprecated
See corresponding docs for further information. Performs an action for each element of this stream. This is an intermediate operation. The behavior of this operation is explicitly nondeterministic. 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.
| |
| makeTerminated | back to summary |
|---|---|
| protected void makeTerminated() Marks this stream as terminated.
| |
| map | back to summary |
|---|---|
| public <R> Streams. References Deprecated
See corresponding docs for further information. Returns a stream consisting of the results of applying the given function to the elements of this stream. This is an intermediate operation.
| |
| reduce | back to summary |
|---|---|
| public O reduce(final O identity, final BinaryOperator<O> 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. This is equivalent to:
but is not constrained to execute sequentially.
The This is an intermediate operation. Note Sum, min, max, average, and string concatenation are all special cases of reduction. Summing a stream of numbers can be expressed as:
or:
While this may seem a more roundabout way to perform an aggregation compared to simply mutating a running total in a loop, reduction operations parallelize more gracefully, without needing additional synchronization and with greatly reduced risk of data races.
| |
| stream | back to summary |
|---|---|
| public Stream Converts the FailableStream into an equivalent stream.
| |