Class StreamUtils
java.lang.Object
org.aksw.commons.collections.utils.StreamUtils
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Stream<T>appendAction(Stream<? extends T> stream, Runnable runnable) Creates a new stream which upon reaching its end performs and action.static <T> TexpectOneItem(Stream<T> stream) static <T> TexpectZeroOrOneItems(Stream<T> stream) static <T,R, E> Stream<T> fromEnumerableResource(Callable<R> resourceSupplier, ThrowingFunction<? super R, E> toEnumerable, ThrowingFunction<? super E, T> nextRecord, BiPredicate<T, ? super E> hasEnded, ThrowingBiConsumer<? super R, ? super E> closer) Creates a stream over a resource via an enumerable.static <T> Iterable<T>Create a single-useIterablefrom a stream.mapToBatch(Stream<T> stream, int batchSize) Note we could implement another version where each batch's List is lazy loaded from the stream - but this would probably require complete consumption of each batch in orderstatic <T> Stream<T>static <S,X> Stream<X> stream(BiConsumer<S, Consumer<X>> fn, S baseSolution) streamToPairs(Stream<T> stream) static <T> Stream<T>
-
Constructor Details
-
StreamUtils
public StreamUtils()
-
-
Method Details
-
iterable
Create a single-useIterablefrom a stream. Allows for easier use of Streams in for-loops:Stream<T> stream = ...; for (T item : StreamUtils.iterableOf(stream)) { }- Type Parameters:
T-- Parameters:
stream-- Returns:
-
expectOneItem
-
expectZeroOrOneItems
-
streamToPairs
-
mapToBatch
Note we could implement another version where each batch's List is lazy loaded from the stream - but this would probably require complete consumption of each batch in order- Parameters:
stream-batchSize-- Returns:
-
appendAction
Creates a new stream which upon reaching its end performs and action. It concatenates the original stream with one having a single item that is filtered out again. The action is run as- part of the filter.- Parameters:
stream-runnable-- Returns:
-
stream
-
fromEnumerableResource
public static <T,R, Stream<T> fromEnumerableResourceE> (Callable<R> resourceSupplier, ThrowingFunction<? super R, E> toEnumerable, ThrowingFunction<? super E, T> nextRecord, BiPredicate<T, ? super E> hasEnded, ThrowingBiConsumer<? super R, ? super E> closer) Creates a stream over a resource via an enumerable. The resource is initialized lazily once the first item is read from the stream. The returned stream should be used in a try-with-resources block in order to close the underlying resource.- Type Parameters:
T- The record type (e.g. an array of Strings)R- The resource type (e.g. a java.sql.Connection)E- An enumerable (e.g. a java.sql.ResultSet)- Parameters:
resourceSupplier-toEnumerable-nextRecord-closer-- Returns:
-
viaList
-
println
-