- java.lang.Object
-
- org.omnifaces.utils.stream.Streams
-
public class Streams extends Object
-
-
Constructor Summary
Constructors Constructor Description Streams()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,R extends T>
Function<T,Stream<R>>mapToType(Class<R> clazz)
static <T extends Comparable<T>>
Stream<T>range(T start, T endExclusive, Function<? super T,? extends T> incrementer)
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>
stream(Iterable<T> iterable)
static <T> Stream<T>
stream(Object object)
Returns a stream of given object.static <K,V>
Stream<Map.Entry<K,V>>stream(Map<K,V> map)
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)
-
-
-
Method Detail
-
zip
public static <T,U,R> Stream<R> zip(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
public static <T,R extends T> Function<T,Stream<R>> mapToType(Class<R> clazz)
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
public static <T> Stream<T> stream(Object object)
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
public static <T> Stream<T> stream(T[] array)
-
-