Class Streams

java.lang.Object
org.omnifaces.utils.stream.Streams

public class Streams extends Object
  • Constructor Details

    • Streams

      public Streams()
  • Method Details

    • 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 a flatMap 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 return Stream.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 stream
      R - 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 - When T is of wrong type.
    • stream

      public static <T> Stream<T> stream(Iterable<T> iterable)
    • stream

      public static <K, V> Stream<Map.Entry<K,V>> stream(Map<K,V> map)
    • stream

      public static <T> Stream<T> stream(T[] array)