Package io.toro.martini
Class StreamMethods
- java.lang.Object
- 
- io.toro.martini.StreamMethods
 
- 
 public final class StreamMethods extends Object Provides methods for mappingStream-based operations, so theJava Streams APIcan be utilized in Gloop.
- 
- 
Constructor SummaryConstructors Constructor Description StreamMethods()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static <T> Stream<T>applyToTap(Stream<T> stream, UnaryOperator<Stream<T>> streamAction, Collection<T> collection, Function<Collection<T>,Stream<T>> collectionAction)(package private) static <T> TcollectToSink(Stream stream, Collection<?> collection, Function<Stream,T> function)static Longcount(Stream<?> stream)Count the number of elements in the stream.static <T> Stream<T>distinct(Stream<T> stream, Collection<T> collection)Filter out duplicate elements.static Streamfilter(Stream stream, Collection collection, Closure<Boolean> predicate)Filter items in the provided stream based on a given condition.static <T> voidforEach(Stream<T> stream, Closure<T> consumer)Consume each element of the stream to do a provided operation.static GloopModelgroupBy(Stream<GloopModel> stream, Collection<GloopModel> collection, String groupBy)Group together elements based on a Gloop model property.static Streamlimit(Stream stream, Collection collection, long limit)Limit the items to process.static Streamskip(Stream stream, Collection collection, long skip)Skip the first n number of elements.static Stream<GloopModel>sorted(Stream<GloopModel> stream, Collection<GloopModel> collection, String sortBy)Sort models by a certain property.static <T> Stream<T>sorted(Stream<T> stream, Collection<T> collection)Sort items by their natural order.static Streamsorted(Stream stream, Collection collection, Closure<Integer> comparator)Sort items based on a provided comparator.static <T> List<T>toList(Stream<T> stream)Collect all elements in the stream, then return them as aList.static <T> Stream<T>toStream(Collection<T> collection)Return a sequentialStreamwith this collection as its source.
 
- 
- 
- 
Method Detail- 
toStream@GloopObjectParameter("output:object::::::java.util.stream.Stream") public static <T> Stream<T> toStream(Collection<T> collection) Return a sequentialStreamwith this collection as its source.- Parameters:
- collection- collection data source collection data source
- Returns:
- a stream of elements from an array
- Since:
- 1.0
 
 - 
applyToTapstatic <T> Stream<T> applyToTap(Stream<T> stream, UnaryOperator<Stream<T>> streamAction, Collection<T> collection, Function<Collection<T>,Stream<T>> collectionAction) 
 - 
filter@GloopObjectParameter("output:object:::::java.util.stream.Stream") public static Stream filter(Stream stream, Collection collection, Closure<Boolean> predicate) Filter items in the provided stream based on a given condition.- Parameters:
- stream- stream data source stream data source
- collection- collection data source collection data source
- predicate- the condition for filtering
- Returns:
- filtered stream of elements
- Throws:
- IllegalArgumentException- if both- streamand- collectionare non-null and non-empty
- Since:
- 1.0
 
 - 
sorted@GloopObjectParameter("output:object:::::java.util.stream.Stream") public static <T> Stream<T> sorted(Stream<T> stream, Collection<T> collection) Sort items by their natural order.- Parameters:
- stream- stream data source the stream data source
- collection- collection data source the collection data source
- Returns:
- a stream of elements sorted by natural order
- Throws:
- IllegalArgumentException- if both- streamand- collectionare non-null and non-empty
- Since:
- 1.0
 
 - 
sortedpublic static Stream sorted(Stream stream, Collection collection, Closure<Integer> comparator) Sort items based on a provided comparator.- Parameters:
- stream- stream data source stream data source
- collection- collection data source collection data source
- comparator- the closure to use to determine order
- Returns:
- a stream of elements sorted by a comparator
- Throws:
- IllegalArgumentException- if both- streamand- collectionare non-null and non-empty
- Since:
- 1.0
 
 - 
sorted@GloopObjectParameter("output:object:::::java.util.stream.Stream") public static Stream<GloopModel> sorted(Stream<GloopModel> stream, Collection<GloopModel> collection, String sortBy) Sort models by a certain property.- Parameters:
- stream- stream data source stream data source
- collection- collection data source collection data source
- sortBy- property to use as basis for sorting
- Returns:
- a stream of models sorted by a property
- Throws:
- IllegalArgumentException- if both- streamand- collectionare non-null and non-empty
- Since:
- 1.0
 
 - 
limit@GloopObjectParameter("output:object:::::java.util.stream.Stream") public static Stream limit(Stream stream, Collection collection, long limit) Limit the items to process.- Parameters:
- stream- stream data source
- collection- collection data source
- limit- a limited stream of items
- Returns:
- a limited stream of items
- Throws:
- IllegalArgumentException- if both- streamand- collectionare non-null and non-empty
- Since:
- 1.0
 
 - 
skip@GloopObjectParameter("output:object:::::java.util.stream.Stream") public static Stream skip(Stream stream, Collection collection, long skip) Skip the first n number of elements.- Parameters:
- stream- stream data source
- collection- collection data source
- skip- the number of leading elements to skip
- Returns:
- stream whose first n elements were skipped
- Throws:
- IllegalArgumentException- if both- streamand- collectionare non-null and non-empty
- Since:
- 1.0
 
 - 
distinct@GloopObjectParameter("output:object:::::java.util.stream.Stream") public static <T> Stream<T> distinct(Stream<T> stream, Collection<T> collection) Filter out duplicate elements.- Parameters:
- stream- stream data source
- collection- collection data source
- Returns:
- a stream of distinct items
- Throws:
- IllegalArgumentException- if both- streamand- collectionare non-null and non-empty
- Since:
- 1.0
 
 - 
count@GloopObjectParameter("output:long") public static Long count(Stream<?> stream) Count the number of elements in the stream.- Parameters:
- stream- stream data source
- Returns:
- the number of elements
- Since:
- 1.0
 
 - 
collectToSinkstatic <T> T collectToSink(Stream stream, Collection<?> collection, Function<Stream,T> function) 
 - 
toList@GloopObjectParameter("output[]:object") public static <T> List<T> toList(Stream<T> stream) Collect all elements in the stream, then return them as aList.- Parameters:
- stream- stream data source
- Returns:
- a Listof elements in the provided stream
- Since:
- 1.0
 
 - 
forEachpublic static <T> void forEach(Stream<T> stream, Closure<T> consumer) Consume each element of the stream to do a provided operation.- Parameters:
- stream- stream data source
- consumer- the closure to apply to each item
- Since:
- 1.0
 
 - 
groupBy@GloopObjectParameter("output:a grouping of items from a stream{\ngroups[]{\nkey\nelements[]{\n}\n}\n}") public static GloopModel groupBy(Stream<GloopModel> stream, Collection<GloopModel> collection, String groupBy) Group together elements based on a Gloop model property.- Parameters:
- stream- stream data source
- collection- array data source
- groupBy- the property that will be used to group items
- Returns:
- a grouping of items from a stream
- Throws:
- IllegalArgumentException- if both- streamand- collectionare non-null and non-empty
- Since:
- 1.0
 
 
- 
 
-