public class CheckedStream extends Object
Modifier and Type | Class and Description |
---|---|
static class |
CheckedStream.ConvertedToRuntimeException
An exception that wraps another exception, but exposes itself as a
RuntimeException . |
Modifier and Type | Method and Description |
---|---|
static <T,E extends Exception> |
filter(java.util.stream.Stream<T> stream,
Class<? extends Exception> throwableClass,
CheckedPredicate<T,E> predicate)
Performs a
Stream.filter(java.util.function.Predicate<? super T>) but accepts a predicate that can throw a checked-exception. |
static <S,T,E extends Exception> |
flatMap(java.util.stream.Stream<S> stream,
Class<? extends Exception> throwableClass,
CheckedFunction<S,java.util.stream.Stream<? extends T>,E> flatMapFunction)
Performs a
Stream.flatMap(java.util.function.Function<? super T, ? extends java.util.stream.Stream<? extends R>>) but accepts a function that can throw a checked-exception |
static <T,E extends Exception> |
forEach(java.util.stream.Stream<T> stream,
Class<? extends Exception> throwableClass,
CheckedConsumer<T,E> consumer)
Performs a
Stream.forEach(java.util.function.Consumer<? super T>) but accepts a consumer that can throw a checked-exception. |
static <S,T,E extends Exception> |
map(java.util.stream.Stream<S> stream,
Class<? extends Exception> throwableClass,
CheckedFunction<S,T,E> mapFunction)
Performs a
Stream.map(java.util.function.Function<? super T, ? extends R>) but accepts a function that can throw a checked-exception. |
static <T,E extends Exception> |
mapIntStream(java.util.stream.IntStream stream,
Class<? extends Exception> throwableClass,
CheckedIntFunction<T,E> mapFunc)
Creates a new feature-list by mapping integers (from a range) each to an optional feature
accepting a checked-exception
|
static <S,E extends Exception> |
mapToInt(java.util.stream.Stream<S> stream,
Class<? extends Exception> throwableClass,
CheckedToIntFunction<S,E> mapFunction)
Performs a
Stream.mapToInt(java.util.function.ToIntFunction<? super T>) but accepts a function that can throw a checked-exception. |
static <T,E extends Exception> |
mapToObj(java.util.stream.IntStream stream,
Class<? extends Exception> throwableClass,
CheckedIntFunction<T,E> mapFunction)
Performs a
IntStream.mapToObj(java.util.function.IntFunction<? extends U>) but accepts a function that can throw a
checked-exception. |
public static <T,E extends Exception> void forEach(java.util.stream.Stream<T> stream, Class<? extends Exception> throwableClass, CheckedConsumer<T,E> consumer) throws E extends Exception
Stream.forEach(java.util.function.Consumer<? super T>)
but accepts a consumer that can throw a checked-exception.
This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be
rethrown wrapped inside a CheckedStream.ConvertedToRuntimeException
.
T
- type to consume.E
- exception that can be thrown by mapFunction
.stream
- the stream to apply the map on.throwableClass
- the class of E
.consumer
- the function to call for each object in the stream.E
- if the exception is thrown during mapping.E extends Exception
public static <T,E extends Exception> java.util.stream.Stream<T> filter(java.util.stream.Stream<T> stream, Class<? extends Exception> throwableClass, CheckedPredicate<T,E> predicate) throws E extends Exception
Stream.filter(java.util.function.Predicate<? super T>)
but accepts a predicate that can throw a checked-exception.
This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be
rethrown wrapped inside a CheckedStream.ConvertedToRuntimeException
.
T
- type to consumeE
- exception that can be thrown by mapFunction
stream
- the stream to apply the map on.throwableClass
- the class of E
.predicate
- the predicate to call for each object in the stream.stream
that match the predicate.E
- if the exception is thrown during filtering.E extends Exception
public static <S,T,E extends Exception> java.util.stream.Stream<T> map(java.util.stream.Stream<S> stream, Class<? extends Exception> throwableClass, CheckedFunction<S,T,E> mapFunction) throws E extends Exception
Stream.map(java.util.function.Function<? super T, ? extends R>)
but accepts a function that can throw a checked-exception.
This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be
rethrown wrapped inside a CheckedStream.ConvertedToRuntimeException
.
S
- input-type to mapT
- output-type of mapE
- exception that can be thrown by mapFunction
stream
- the stream to apply the map on.throwableClass
- the class of E
.mapFunction
- the function to use for mapping.E
- if the exception is thrown during mapping.E extends Exception
public static <S,E extends Exception> java.util.stream.IntStream mapToInt(java.util.stream.Stream<S> stream, Class<? extends Exception> throwableClass, CheckedToIntFunction<S,E> mapFunction) throws E extends Exception
Stream.mapToInt(java.util.function.ToIntFunction<? super T>)
but accepts a function that can throw a checked-exception.
This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be
rethrown wrapped inside a CheckedStream.ConvertedToRuntimeException
.
S
- input-type to mapE
- exception that can be thrown by mapFunction
stream
- the stream to apply the map on.throwableClass
- the class of E
.mapFunction
- the function to use for mapping.E
- if the exception is thrown during mapping.E extends Exception
public static <T,E extends Exception> java.util.stream.Stream<T> mapIntStream(java.util.stream.IntStream stream, Class<? extends Exception> throwableClass, CheckedIntFunction<T,E> mapFunc) throws E extends Exception
This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
T
- end-type for mappingE
- an exception that be thrown during mappingstream
- stream of int
s.throwableClass
- the class of E
.mapFunc
- function for mapping.E
- if mapFunc
throws it.E extends Exception
public static <T,E extends Exception> java.util.stream.Stream<T> mapToObj(java.util.stream.IntStream stream, Class<? extends Exception> throwableClass, CheckedIntFunction<T,E> mapFunction) throws E extends Exception
IntStream.mapToObj(java.util.function.IntFunction<? extends U>)
but accepts a function that can throw a
checked-exception.
This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be
rethrown wrapped inside a CheckedStream.ConvertedToRuntimeException
.
T
- object-type to map-to.E
- exception that can be thrown by mapFunction
.stream
- the stream to apply the map on.throwableClass
- the class of E
.mapFunction
- the function to use for mapping.E
- if the exception is thrown during mapping.E extends Exception
public static <S,T,E extends Exception> java.util.stream.Stream<T> flatMap(java.util.stream.Stream<S> stream, Class<? extends Exception> throwableClass, CheckedFunction<S,java.util.stream.Stream<? extends T>,E> flatMapFunction) throws E extends Exception
Stream.flatMap(java.util.function.Function<? super T, ? extends java.util.stream.Stream<? extends R>>)
but accepts a function that can throw a checked-exception
This uses some internal reflection trickery to suppress the checked exception, and then rethrow it.
As a side-effect, any runtime exceptions that are thrown during the function, will be
rethrown wrapped inside a CheckedStream.ConvertedToRuntimeException
.
S
- input-type to flatMapT
- output-type of flatMapE
- exception that can be thrown by flatMapFunction
.stream
- the stream to apply the flatMap on.throwableClass
- the class of E
.flatMapFunction
- the function to use for flatMapping.E
- if the exception.E extends Exception
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.