Class CachedStream<T>

java.lang.Object
org.jdrupes.builder.core.CachedStream<T>
Type Parameters:
T - the generic type

public class CachedStream<T> extends Object

A cached stream allows the user of a Stream to access it multiple times. The stream is evaluated on the first call to stream() and then cached.

As a convenience, the class supports combining the contents of multiple streams.

  • Constructor Details

    • CachedStream

      public CachedStream()
      Instantiates a new cached stream.
  • Method Details

    • add

      @SafeVarargs public final void add(Stream<T>... sources)
      Use all given streams as sources.
      Parameters:
      sources - the sources
    • stream

      public Stream<T> stream()
      Provide the contents from the stream(s).
      Returns:
      the stream<? extends t>
    • of

      public static <T> CachedStream<T> of(Stream<T> source)
      Create a cached stream from a single source stream.
      Type Parameters:
      T - the generic type
      Parameters:
      source - the source
      Returns:
      the cached stream