java.lang.Object
org.omnifaces.utils.stream.Streams
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<T>>
Stream<T>static <T> Stream<T>
range
(T start, T endExclusive, Function<? super T, ? extends T> incrementer, Comparator<? super T> comparator) static <T extends Comparable<T>>
Stream<T>rangeClosed
(T start, T endInclusive, Function<? super T, ? extends T> incrementer) static <T> Stream<T>
rangeClosed
(T start, T endInclusive, Function<? super T, ? extends T> incrementer, Comparator<? super T> comparator) static <T> Stream<T>
static <T> Stream<T>
Returns a stream of given object.static <T> Stream<T>
stream
(T[] array) static <T,
U, R> Stream<R> zip
(Stream<? extends T> stream1, Stream<? extends U> stream2, BiFunction<? super T, ? super U, R> zipFunction)
-
Constructor Details
-
Streams
public Streams()
-
-
Method Details
-
zip
public static <T,U, Stream<R> zipR> (Stream<? extends T> stream1, Stream<? extends U> stream2, BiFunction<? super T, ? super U, R> zipFunction) -
rangeClosed
public static <T extends Comparable<T>> Stream<T> rangeClosed(T start, T endInclusive, Function<? super T, ? extends T> incrementer) -
rangeClosed
public static <T> Stream<T> rangeClosed(T start, T endInclusive, Function<? super T, ? extends T> incrementer, Comparator<? super T> comparator) -
range
public static <T extends Comparable<T>> Stream<T> range(T start, T endExclusive, Function<? super T, ? extends T> incrementer) -
range
public static <T> Stream<T> range(T start, T endExclusive, Function<? super T, ? extends T> incrementer, Comparator<? super T> comparator) -
mapToType
Returns aflatMap
Function
that only retains a instances of a given type and casts them to this type.Unlike other flatMap functions, this function will only return 0 or 1 result. If an instance passed to it is of the specified type, then the function will return a
Stream
with only this item, cast to this type. If the instance is not of this type, the function will returnStream.empty()
. Example use Say we have a Stream<X> from which we want retain only all instances of Y, then could do the following to obtain a Stream<Y>:Stream<X> streamOfX = ...; Stream<Y> streamOfY = streamOfX.flatMap(mapToType(Y.class));
Which is the equivalent of this:streamOfX.filter(x -> x instanceof Y) .map(x -> (Y)x)
- Type Parameters:
T
- the type of the elements in the streamR
- the type of the instances to retain- Parameters:
clazz
- the type of the instances to retain- Returns:
- a flatMap function that only retains instances of a given type.
-
stream
Returns a stream of given object. Supported types are: Anything else is returned as a single-element stream. Null is returned as an empty stream.- Type Parameters:
T
- The expected stream type.- Parameters:
object
- Any object to get a stream for.- Returns:
- A stream of given object.
- Throws:
ClassCastException
- WhenT
is of wrong type.
-
stream
-
stream
-
stream
-