Package com.complexible.common.base
Class Streams
java.lang.Object
com.complexible.common.base.Streams
Utility for streams
- Since:
- 4.0
- Version:
- 4.0
- Author:
- Michael Grove
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfacestatic interfacestatic interfacestatic interfacestatic interfacestatic interfacestatic final classException indicating that Checked* threw an exception and the default handler was used -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final booleanstatic final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <Input,Output>
OutputapplyTerminalAndClose(Stream<Input> theStream, Function<Stream<Input>, Output> theFinisher) Apply the given terminal operation to the stream returning the result and close the stream.static <T> Stream<T> static <T> Predicate<? super T> distinctByKey(Function<? super T, Object> theKey) A simple stateful predicate for filtering out stream elements which agree on their key values.static <T> CloseableIterator<T> flatIterator(Stream<Stream<T>> theStream) static <T> Stream<T> static <T,E extends Throwable>
voidforEachChecked(Stream<T> theStream, Streams.CheckedConsumer<T> theConsumer) optional()static <T> Stream<T> static <T> Stream<T> static <T> Stream<T> static <In1,In2, Out>
BiFunction<In1, In2, Out> unchecked(Streams.CheckedBiFunction<In1, In2, Out> theBiFunction) static <In1,In2, Out>
BiFunction<In1, In2, Out> unchecked(Streams.CheckedBiFunction<In1, In2, Out> theBiFunction, Consumer<Throwable> theHandler) static <In,Out> Function <In, Out> unchecked(Streams.CheckedFunction<In, Out> theFunction) static <In,Out> Function <In, Out> unchecked(Streams.CheckedFunction<In, Out> theFunction, Consumer<Throwable> theHandler) static <U,T> BiConsumer <U, T> uncheckedConsumer(Streams.CheckedBiConsumer<U, T> theConsumer) static <U,T> BiConsumer <U, T> uncheckedConsumer(Streams.CheckedBiConsumer<U, T> theConsumer, Consumer<Throwable> theHandler) static <T> Consumer<T> uncheckedConsumer(Streams.CheckedConsumer<T> theConsumer) static <T> Consumer<T> uncheckedConsumer(Streams.CheckedConsumer<T> theConsumer, Consumer<Throwable> theHandler) static <In> Predicate<In> uncheckedPredicate(Streams.CheckedPredicate<In> thePredicate) static <In> Predicate<In> uncheckedPredicate(Streams.CheckedPredicate<In> thePredicate, Consumer<Throwable> theHandler)
-
Field Details
-
NOT_PARALLEL
public static final boolean NOT_PARALLEL- See Also:
-
PARALLEL
public static final boolean PARALLEL- See Also:
-
UNKNOWN_SIZE
public static final long UNKNOWN_SIZE- See Also:
-
-
Constructor Details
-
Streams
public Streams()
-
-
Method Details
-
optional
Returns a function that will collapse aStreamofoptionalsinto aStreamof the references they hold. To be used withStream.flatMap(Function).- Type Parameters:
T- the optional's type- Returns:
- a Function which unrolls optionals
-
stream
- Parameters:
theIterable- the iterable- Returns:
- a stream over the iterable
-
stream
-
stream
-
concat
@SafeVarargs public static <T> Stream<T> concat(Stream<T> theStream, Stream<T> theOtherStream, Stream<T>... theMoreStreams) -
applyTerminalAndClose
public static <Input,Output> Output applyTerminalAndClose(Stream<Input> theStream, Function<Stream<Input>, Output> theFinisher) Apply the given terminal operation to the stream returning the result and close the stream.- Parameters:
theStream- the streamtheFinisher- the function which will apply the terminal operation and return the result- Returns:
- the result of the terminal operation.
-
forEachChecked
public static <T,E extends Throwable> void forEachChecked(Stream<T> theStream, Streams.CheckedConsumer<T> theConsumer) throws E - Throws:
E
-
unchecked
-
unchecked
public static <In,Out> Function<In,Out> unchecked(Streams.CheckedFunction<In, Out> theFunction, Consumer<Throwable> theHandler) -
unchecked
public static <In1,In2, BiFunction<In1,Out> In2, uncheckedOut> (Streams.CheckedBiFunction<In1, In2, Out> theBiFunction) -
unchecked
public static <In1,In2, BiFunction<In1,Out> In2, uncheckedOut> (Streams.CheckedBiFunction<In1, In2, Out> theBiFunction, Consumer<Throwable> theHandler) -
uncheckedPredicate
-
uncheckedPredicate
public static <In> Predicate<In> uncheckedPredicate(Streams.CheckedPredicate<In> thePredicate, Consumer<Throwable> theHandler) -
uncheckedConsumer
-
uncheckedConsumer
-
uncheckedConsumer
public static <U,T> BiConsumer<U,T> uncheckedConsumer(Streams.CheckedBiConsumer<U, T> theConsumer, Consumer<Throwable> theHandler) -
uncheckedConsumer
public static <T> Consumer<T> uncheckedConsumer(Streams.CheckedConsumer<T> theConsumer, Consumer<Throwable> theHandler) -
flatIterator
-
flatten
-
distinctByKey
A simple stateful predicate for filtering out stream elements which agree on their key values. TODO let the outer code create more optimized distinct filters e.g. for value types. -
entriesToMap
-