Top Description Inners Constructors Methods
org.apache.commons.lang3.stream

public Class Streams

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collection, .Collections, .Enumeration, .Iterator, .List, .Objects, .Set, .Spliterator, .Spliterators, .Spliterators.AbstractSpliterator, java.util.function.BiConsumer, .BinaryOperator, .Consumer, .Function, .Predicate, .Supplier, java.util.stream.Collector, .Collectors, .Stream, .StreamSupport, org.apache.commons.lang3.ArrayUtils, org.apache.commons.lang3.function.Failable, .FailableConsumer, .FailableFunction, .FailablePredicate

Provides utility functions, and classes for working with the 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 Failable.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.

Since
3.11
See Also
Stream, Failable

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Streams.ArrayCollector<
The array type.
E
>

A Collector type for arrays.

private static class
Streams.EnumerationSpliterator<
The element type.
T
>

Helps implement Streams#of(Enumeration).

public static class
Streams.FailableStream<
The streams element type.
T
>

A reduced, and simplified version of a Stream with failable method signatures.

Constructor Summary

AccessConstructor and Description
public
Streams()
Deprecated Will be private in 4.0.0.

Constructs a new instance.

Method Summary

Modifier and TypeMethod and Description
public static <
The streams element type.
T
>
Streams.FailableStream<T>

Returns:

The FailableStream, which has been created by converting the stream.
failableStream
(final Collection<T>
The stream, which is being converted.
stream
)

Converts the given Collection into a FailableStream.

public static <
The streams element type.
T
>
Streams.FailableStream<T>

Returns:

The FailableStream, which has been created by converting the stream.
failableStream
(final Stream<T>
The stream, which is being converted.
stream
)

Converts the given stream into a FailableStream.

public static <
the type of stream elements.
T
>
Streams.FailableStream<T>

Returns:

the new FailableStream on value or an empty stream.
failableStream
(final T
the single element of the new stream, may be null.
value
)

Shorthand for Streams.failableStream(value == null ?

public static <
the type of stream elements.
T
>
Streams.FailableStream<T>

Returns:

the new FailableStream on values or an empty stream.
failableStream
(final T...
the elements of the new stream, may be null.
values
)

Shorthand for Streams.failableStream(Streams.of(arrayValues)).

public static <
the type of elements in the collection we want to stream.
E
>
Stream<E>

Returns:

A non-null stream that only provides instances we want.
instancesOf
(final Class<? super E>
the type of elements in the collection we want to stream.
clazz
,
final Collection<? super E>
the collection to stream or null.
collection
)

Streams only instances of the give Class in a collection.

private static <E> Stream<E>
instancesOf(final Class<? super E> clazz, final Stream<?> stream)

public static <
the type of elements in the collection.
E
>
Stream<E>

Returns:

A non-null stream that filters out null elements.
nonNull
(final Collection<E>
the collection to stream or null.
collection
)

Streams the non-null elements of a collection.

public static <
the type of elements in the collection.
E
>
Stream<E>

Returns:

A non-null stream that filters out a null element.
nonNull
(final E
the element to stream or null.
array
)

Streams the non-null element.

public static <
the type of elements in the collection.
E
>
Stream<E>

Returns:

A non-null stream that filters out null elements.
nonNull
(final E...
the array to stream or null.
array
)

Streams the non-null elements of an array.

public static <
the type of elements in the collection.
E
>
Stream<E>

Returns:

A non-null stream that filters out null elements.
nonNull
(final Stream<E>
the stream to stream or null.
stream
)

Streams the non-null elements of a stream.

public static <
the type of elements in the collection.
E
>
Stream<E>

Returns:

Collection#stream() or Stream#empty() if the collection is null.
of
(final Collection<E>
the collection to stream or null.
collection
)

Delegates to Collection#stream() or returns Stream#empty() if the collection is null.

public static <
The enumeration element type.
E
>
Stream<E>

Returns:

a new stream.
of
(final Enumeration<E>
The enumeration to stream.
enumeration
)

Streams the elements of the given enumeration in order.

public static <
the type of elements in the Iterable.
E
>
Stream<E>

Returns:

a new Stream or Stream#empty() if the Iterable is null.
of
(final Iterable<E>
the Iterable to stream or null.
iterable
)

Creates a sequential stream on the given Iterable.

public static <
the type of elements in the Iterator.
E
>
Stream<E>

Returns:

a new Stream or Stream#empty() if the Iterator is null.
of
(final Iterator<E>
the Iterator to stream or null.
iterator
)

Creates a sequential stream on the given Iterator.

private static <
the type of elements in the collection.
E
>
Stream<E>

Returns:

the stream or Stream#empty() if the stream is null.
of
(final Stream<E>
the stream to stream or null.
stream
)

Returns the stream or Stream#empty() if the stream is null.

public static <
the type of stream elements.
T
>
Stream<T>

Returns:

the new stream on values or Stream#empty().
of
(final T...
the elements of the new stream, may be null.
values
)

Null-safe version of Stream#of(Object[]).

public static <
The streams element type.
E
>
Streams.FailableStream<E>

Returns:

The FailableStream, which has been created by converting the stream.
stream
(final Collection<E>
The stream, which is being converted.
collection
)
Deprecated Use failableStream(Collection).

Converts the given Collection into a FailableStream.

public static <
The streams element type.
T
>
Streams.FailableStream<T>

Returns:

The FailableStream, which has been created by converting the stream.
stream
(final Stream<T>
The stream, which is being converted.
stream
)
Deprecated Use failableStream(Stream).

Converts the given stream into a FailableStream.

private static <T> Stream<T>
streamOf(final T value)

public static <
the type of the input elements
T
>
Collector<T, List<T>, T[]>

Returns:

a Collector which collects all the input elements into an array, in encounter order
toArray
(final Class<T>
Type of an element in the array.
elementType
)

Returns a Collector that accumulates the input elements into a new array.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait