public class StreamsUtil extends Object
Constructor and Description |
---|
StreamsUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> Stream<T> |
closing(Stream<T> stream)
Returns the original stream that is closed on terminating operation.
|
static <T> Predicate<T> |
distinctByKey(Function<? super T,?> keyExtractor)
distinctByKey is not supposed to be used with parallel streams
To make this method synchronized use
ConcurrentHashMap<Object, Boolean> instead of HashSet |
static <T> Stream<T> |
paginatedStream(Stream<T> originalStream,
Integer first,
Integer max)
|
static <T> Stream<T> |
throwIfEmpty(Stream<T> stream,
RuntimeException ex)
Returns the original stream if the stream is not empty.
|
public static <T> Stream<T> closing(Stream<T> stream)
stream
- the stream which is expected to be closed on terminationpublic static <T> Stream<T> throwIfEmpty(Stream<T> stream, RuntimeException ex)
stream
- Stream to be examined.ex
- Exception to be thrown if the stream is empty.public static <T> Stream<T> paginatedStream(Stream<T> originalStream, Integer first, Integer max)
skip
and
limit
functions based on values of first
and max
parameters.T
- Type of items in the streamoriginalStream
- Stream to be limited.first
- Index of first item to be returned by the stream. Ignored if negative, zero null
.max
- Maximum number of items to be returned by the stream. Ignored if negative or null
.Copyright © 2021 JBoss by Red Hat. All rights reserved.