Package no.digipost
Class DiggStreams
java.lang.Object
no.digipost.DiggStreams
Utilities for working with
Streams.-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 anintindex, 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 alongindex, 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 anintindex, 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 alongindex, 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.
-
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 anintindex, 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 givenendExclusiveindex.- Type Parameters:
V- The type of the resolved elements yielded by theStream.S- The type of the source object which yields elements of typeVby index.- Parameters:
source- The source object which yields the elements by an indexendExclusive- The end index. This is also effectively the resulting size of the streamresolveValue- How to query thesourceobject for each index. This can usually be a method reference likeS::getor similar.- Returns:
- the stream yielding the elements
-
streamByIndex
public static final <S,K, Stream<V> streamByIndexV> (S source, IntStream indexes, ObjIntFunction<S, V> resolveValue) Stream the elements from a container which allows access to the by through anintindex, but does not itself offer any means for traversal/iteration/streaming. This method will stream the elements with indexes from the givenIntStream.- Type Parameters:
V- The type of the resolved elements yielded by theStream.S- The type of the source object which yields elements of typeVby index.- Parameters:
source- The source object which yields the elements by an indexindexes- The indexesresolveValue- How to query thesourceobject for each index. This can usually be a method reference likeS::getor 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 alongindex, 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 givenendExclusiveindex.- Type Parameters:
V- The type of the resolved elements yielded by theStream.S- The type of the source object which yields elements of typeVby index.- Parameters:
source- The source object which yields the elements by an indexendExclusive- The end index. This is also effectively the resulting size of the streamresolveValue- How to query thesourceobject for each index. This can usually be a method reference likeS::getor similar.- Returns:
- the stream yielding the elements
-
streamByIndex
public static final <S,K, Stream<V> streamByIndexV> (S source, LongStream indexes, ObjLongFunction<S, V> resolveValue) Stream the elements from a container which allows access to the by through alongindex, but does not itself offer any means for traversal/iteration/streaming. This method will stream the elements with indexes from the givenIntStream.- Type Parameters:
V- The type of the resolved elements yielded by theStream.S- The type of the source object which yields elements of typeVby index.- Parameters:
source- The source object which yields the elements by an indexindexes- The indexesresolveValue- How to query thesourceobject for each index. This can usually be a method reference likeS::getor similar.- Returns:
- the stream yielding the elements
-
streamByKey
public static final <S,K, Stream<V> streamByKeyV> (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 givenStream<K>.- Type Parameters:
V- The type of the resolved elements yielded by theStream.S- The type of the source object which yields elements of typeVby key.K- The type of the key used to query elements of typeV.- Parameters:
source- The source object which yields the elements by a keykeys- The keysresolveValue- How to query thesourceobject for each key. This can usually be a method reference likeS::getor 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 aCollectionwith 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 streamincludeWhile- 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 numberresolvePage- a function accepting an int indicating the page number and returns a page to include in the resulting streamincludeWhile- the predicate accepting the objects to include in the stream- Returns:
- the stream of the resolved objects
-