Class StreamHelper
java.lang.Object
io.github.torand.javacommons.stream.StreamHelper
Helper functions for streams
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Stream<T> concatAndStream(Iterable<T> first, Iterable<T> second) Creates a concatenated stream from the elements in the specified iterables.static <T> Stream<T> concatStreams(Stream<T>... streams) Concatenates an arbitrary number of streams.static <T> Stream<T> streamSafely(Iterable<T> iterable) Creates a stream from the elements in the specified iterable.static <T> Stream<T> streamSafely(Iterator<T> iterator) Creates a stream from the elements in the specified iterator.static <T> Stream<T> streamSafely(T... items) Creates a stream from the elements in the specified array.Returns aCollectorproducing a list with elements in reversed order.
-
Method Details
-
streamSafely
Creates a stream from the elements in the specified iterable. If the iterable is null or contains no elements, an empty stream is returned.- Type Parameters:
T- the element type.- Parameters:
iterable- the iterable.- Returns:
- the stream.
-
streamSafely
Creates a stream from the elements in the specified iterator. If the iterator is null or contains no elements, an empty stream is returned.- Type Parameters:
T- the element type.- Parameters:
iterator- the iterator.- Returns:
- the stream.
-
streamSafely
Creates a stream from the elements in the specified array. If the array is null or contains no elements, an empty stream is returned.- Type Parameters:
T- the item type.- Parameters:
items- the items.- Returns:
- the stream.
-
concatAndStream
Creates a concatenated stream from the elements in the specified iterables.- Type Parameters:
T- the element type.- Parameters:
first- the first iterable.second- the second iterable.- Returns:
- the stream.
-
concatStreams
Concatenates an arbitrary number of streams.- Type Parameters:
T- the stream value type.- Parameters:
streams- the streams to concatenate.- Returns:
- the concatenates streams.
-
toReversedList
Returns aCollectorproducing a list with elements in reversed order.- Type Parameters:
T- the value type.- Returns:
- the
Collectorobject.
-