Package no.digipost

Class DiggStreams

java.lang.Object
no.digipost.DiggStreams

public final class DiggStreams extends Object
Utilities for working with Streams.
  • Method Summary

    Modifier and Type
    Method
    Description
    static final <S, K, V> Stream<V>
    streamByIndex(S source, IntStream indexes, ObjIntFunction<S,V> resolveValue)
    Stream the elements from a container which allows access to the by through an int index, but does not itself offer any means for traversal/iteration/streaming.
    static final <S, K, V> Stream<V>
    streamByIndex(S source, LongStream indexes, ObjLongFunction<S,V> resolveValue)
    Stream the elements from a container which allows access to the by through a long index, but does not itself offer any means for traversal/iteration/streaming.
    static final <S, V> Stream<V>
    streamByIntIndex(S source, int endExclusive, ObjIntFunction<S,V> resolveValue)
    Stream the elements from a container which allows access to the elements by an int index, but does not itself offer any means for traversal/iteration/streaming.
    static final <S, K, V> Stream<V>
    streamByKey(S source, Stream<K> keys, BiFunction<S,K,V> resolveValue)
    Stream the elements from a container which allows access to the by through a key, but does not itself offer any means for traversal/iteration/streaming.
    static final <S, V> Stream<V>
    streamByLongIndex(S source, long endExclusive, ObjLongFunction<S,V> resolveValue)
    Stream the elements from a container which allows access to the elements by a long index, but does not itself offer any means for traversal/iteration/streaming.
    static <P> Stream<P>
    streamPages(int firstPageNum, IntFunction<P> resolvePage, Predicate<? super P> includeWhile)
    Generate a stream of objects resolved from an incrementing int (page number), while a predicate is accepting the resolved objects.
    static <P> Stream<P>
    streamPages(IntFunction<P> resolvePage, Predicate<? super P> includeWhile)
    Generate a stream of objects resolved from an incrementing int (page number), while a predicate is accepting the resolved objects.
    static <E> Stream<E>
    streamWhileNonEmpty(IntFunction<? extends Collection<E>> resolveCollection)
    Stream elements retrieved from resolved collections while they are non-empty.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • streamByIntIndex

      public static final <S, V> Stream<V> streamByIntIndex(S source, int endExclusive, ObjIntFunction<S,V> resolveValue)
      Stream the elements from a container which allows access to the elements by an int index, but does not itself offer any means for traversal/iteration/streaming. This method will stream all elements from index 0 up to, but not including, the given endExclusive index.
      Type Parameters:
      V - The type of the resolved elements yielded by the Stream.
      S - The type of the source object which yields elements of type V by index.
      Parameters:
      source - The source object which yields the elements by an index
      endExclusive - The end index. This is also effectively the resulting size of the stream
      resolveValue - How to query the source object for each index. This can usually be a method reference like S::get or similar.
      Returns:
      the stream yielding the elements
    • streamByIndex

      public static final <S, K, V> Stream<V> streamByIndex(S source, IntStream indexes, ObjIntFunction<S,V> resolveValue)
      Stream the elements from a container which allows access to the by through an int index, but does not itself offer any means for traversal/iteration/streaming. This method will stream the elements with indexes from the given IntStream.
      Type Parameters:
      V - The type of the resolved elements yielded by the Stream.
      S - The type of the source object which yields elements of type V by index.
      Parameters:
      source - The source object which yields the elements by an index
      indexes - The indexes
      resolveValue - How to query the source object for each index. This can usually be a method reference like S::get or similar.
      Returns:
      the stream yielding the elements
    • streamByLongIndex

      public static final <S, V> Stream<V> streamByLongIndex(S source, long endExclusive, ObjLongFunction<S,V> resolveValue)
      Stream the elements from a container which allows access to the elements by a long index, but does not itself offer any means for traversal/iteration/streaming. This method will stream all elements from index 0 up to, but not including, the given endExclusive index.
      Type Parameters:
      V - The type of the resolved elements yielded by the Stream.
      S - The type of the source object which yields elements of type V by index.
      Parameters:
      source - The source object which yields the elements by an index
      endExclusive - The end index. This is also effectively the resulting size of the stream
      resolveValue - How to query the source object for each index. This can usually be a method reference like S::get or similar.
      Returns:
      the stream yielding the elements
    • streamByIndex

      public static final <S, K, V> Stream<V> streamByIndex(S source, LongStream indexes, ObjLongFunction<S,V> resolveValue)
      Stream the elements from a container which allows access to the by through a long index, but does not itself offer any means for traversal/iteration/streaming. This method will stream the elements with indexes from the given IntStream.
      Type Parameters:
      V - The type of the resolved elements yielded by the Stream.
      S - The type of the source object which yields elements of type V by index.
      Parameters:
      source - The source object which yields the elements by an index
      indexes - The indexes
      resolveValue - How to query the source object for each index. This can usually be a method reference like S::get or similar.
      Returns:
      the stream yielding the elements
    • streamByKey

      public static final <S, K, V> Stream<V> streamByKey(S source, Stream<K> keys, BiFunction<S,K,V> resolveValue)
      Stream the elements from a container which allows access to the by through a key, but does not itself offer any means for traversal/iteration/streaming. This method will stream the elements with keys from the given Stream<K>.
      Type Parameters:
      V - The type of the resolved elements yielded by the Stream.
      S - The type of the source object which yields elements of type V by key.
      K - The type of the key used to query elements of type V.
      Parameters:
      source - The source object which yields the elements by a key
      keys - The keys
      resolveValue - How to query the source object for each key. This can usually be a method reference like S::get or similar.
      Returns:
      the stream yielding the elements
    • streamWhileNonEmpty

      public static <E> Stream<E> streamWhileNonEmpty(IntFunction<? extends Collection<E>> resolveCollection)
      Stream elements retrieved from resolved collections while they are non-empty. The first empty collection will end the stream.
      Type Parameters:
      E - The type of the elements in the resolved collections, and elements in the resulting stream
      Parameters:
      resolveCollection - a function accepting an int indicating the page number and returns a Collection with elements to include in the resulting stream
      Returns:
      the stream yielding the elements of the resolved collections
    • streamPages

      public static <P> Stream<P> streamPages(IntFunction<P> resolvePage, Predicate<? super P> includeWhile)
      Generate a stream of objects resolved from an incrementing int (page number), while a predicate is accepting the resolved objects. The first object not accepted by the predicate will end the stream.
      Parameters:
      resolvePage - a function accepting an int indicating the page number and returns a page to include in the resulting stream
      includeWhile - the predicate accepting the objects to include in the stream
      Returns:
      the stream of the resolved objects
    • streamPages

      public static <P> Stream<P> streamPages(int firstPageNum, IntFunction<P> resolvePage, Predicate<? super P> includeWhile)
      Generate a stream of objects resolved from an incrementing int (page number), while a predicate is accepting the resolved objects. The first object not accepted by the predicate will end the stream.
      Parameters:
      firstPageNum - the initial page number
      resolvePage - a function accepting an int indicating the page number and returns a page to include in the resulting stream
      includeWhile - the predicate accepting the objects to include in the stream
      Returns:
      the stream of the resolved objects