Package org.mycore.common
Class MCRStreamUtils
java.lang.Object
org.mycore.common.MCRStreamUtils
Helper methods to handle common Stream use cases.
- Author:
- Thomas Scheffler (yagee)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Stream<T>
asStream
(Enumeration<T> e) Transforms an Enumeration in a Stream.static <T> Stream<T>
Concats any number of Streams not just 2 as inStream.concat(Stream, Stream)
.static <T> Predicate<T>
distinctByKey
(Function<? super T, ?> keyExtractor) Stream distinct by filter function.static <T> Stream<T>
flatten
(T node, Function<T, Collection<T>> subNodeSupplier, Function<Collection<T>, Stream<T>> streamProvider) Short circuit for callingflatten(node, subNodeSupplier, subNodeSupplier, t -> true)
static <T> Stream<T>
flatten
(T node, Function<T, Collection<T>> subNodeSupplier, Function<Collection<T>, Stream<T>> streamProvider, Predicate<T> filter) Example:static <T> Predicate<T>
Negates a predicate.
-
Constructor Details
-
MCRStreamUtils
public MCRStreamUtils()
-
-
Method Details
-
flatten
public static <T> Stream<T> flatten(T node, Function<T, Collection<T>> subNodeSupplier, Function<Collection<T>, Stream<T>> streamProvider) Short circuit for callingflatten(node, subNodeSupplier, subNodeSupplier, t -> true)
- Parameters:
node
- node that holds kind-of subtree.subNodeSupplier
- a function that delivers subtree items of next levelstreamProvider
- a function that makes a Stream of a Collection<T>, usuallyCollection::stream
orCollection::parallelStream
- Since:
- 2016.04
- See Also:
-
flatten
public static <T> Stream<T> flatten(T node, Function<T, Collection<T>> subNodeSupplier, Function<Collection<T>, Stream<T>> streamProvider, Predicate<T> filter) Example:MCRCategory foo = MCRCategoryDAOFactory.getInstance().getCategory(MCRCategoryID.rootID("foo"), -1); Stream<MCRCategory> parentCategories = flatten(foo, MCRCategory::getChildren, true, MCRCategory::hasChildren);
- Parameters:
node
- first node the stream is made ofsubNodeSupplier
- a function that delivers subtree items of next levelstreamProvider
- a function that makes a Stream of a Collection<T>, usuallyCollection::stream
orCollection::parallelStream
filter
- a predicate that filters the element of the next level- Since:
- 2016.04
-
asStream
Transforms an Enumeration in a Stream.- Parameters:
e
- the enumeration to transform- Returns:
- a sequential, ordered Stream of unknown size
-
concat
Concats any number of Streams not just 2 as inStream.concat(Stream, Stream)
.- Since:
- 2016.04
-
distinctByKey
Stream distinct by filter function.persons.stream().filter(MCRStreamUtils.distinctByKey(p -> p.getName());
- Parameters:
keyExtractor
- a compare function- Returns:
- a predicate
- See Also:
-
not
Negates a predicate.- Parameters:
predicate
- the predicate to negate- Returns:
- the negated predicate
- See Also:
-