java.util.function package, or more
generally, with Java 8 lambdas. More specifically, it attempts to address the fact that lambdas are supposed not to
throw Exceptions, at least not checked Exceptions, like instances of Exception. This enforces the use of
constructs like:
Consumer<java.lang.reflect.Method> consumer = m -> {
try {
m.invoke(o, args);
} catch (Throwable t) {
throw Failable.rethrow(t);
}
};
By replacing a Consumer<O> with a FailableConsumer<O,? extends Throwable>, this can be written like follows:
Functions.accept(m -> m.invoke(o, args));
Obviously, the second version is much more concise and the spirit of Lambda expressions is met better than the second version.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static < the type of the first argument the consumer accepts T, the type of the second argument the consumer accepts U, the type of checked exception the consumer may throw E extends Throwable> void | accept(final FailableBiConsumer<T, U, E>
the consumer to accept, may be null for a noop. consumer, final T the first object to consume by object1, final U consumerthe second object to consume by object2)consumerConsumes a consumer and rethrows any exception as a |
| public static < the type the consumer accepts T, the type of checked exception the consumer may throw E extends Throwable> void | accept(final FailableConsumer<T, E>
the consumer to accept, may be null for a noop. consumer, final T the object to consume by object)consumerConsumes a consumer and rethrows any exception as a |
| public static < the type of checked exception the consumer may throw E extends Throwable> void | accept(final FailableDoubleConsumer<E>
the consumer to accept, may be null for a noop. consumer, final double the value to consume by value)consumerConsumes a consumer and rethrows any exception as a |
| public static < the type of checked exception the consumer may throw E extends Throwable> void | accept(final FailableIntConsumer<E>
the consumer to accept, may be null for a noop. consumer, final int the value to consume by value)consumerConsumes a consumer and rethrows any exception as a |
| public static < the type of checked exception the consumer may throw E extends Throwable> void | accept(final FailableLongConsumer<E>
the consumer to accept, may be null for a noop. consumer, final long the value to consume by value)consumerConsumes a consumer and rethrows any exception as a |
| public static < the type of the first argument the function accepts T, the type of the second argument the function accepts U, the return type of the function R, the type of checked exception the function may throw E extends Throwable> R | Returns: the value returned from the functionthe function to apply function, final T the first input to apply input1, final U function onthe second input to apply input2)function onApplies a function and rethrows any exception as a |
| public static < the type of the argument the function accepts T, the return type of the function R, the type of checked exception the function may throw E extends Throwable> R | Returns: the value returned from the functionthe function to apply function, final T the input to apply input)function onApplies a function and rethrows any exception as a |
| public static < the type of checked exception the function may throw E extends Throwable> double | Returns: the value returned from the functionthe function to apply function, final double the first input to apply left, final double function onthe second input to apply right)function onApplies a function and rethrows any exception as a |
| public static < The type of the input of this method and the function. T, The type of the result of the function and this method. R, The type of thrown exception or error. E extends Throwable> R | Returns: The result of the function (which may benull) or null if the input value is null.The value to apply the function to, may be value, final FailableFunction<? super T, ? extends R, E> null.The function to apply, must not be mapper)null.Applies a value to a function if the value isn't |
| public static < The type of the input of this method and the first function. T, The type of the result of the first function and the input to the second function. U, The type of the result of the second function and this method. R, The type of thrown exception or error by the first function. E1 extends Throwable, The type of thrown exception or error by the second function. E2 extends Throwable> R | Returns: The result of the final function (which may benull) or null if the input value or any intermediate value is null.The value to apply the functions to, may be value1, final FailableFunction<? super T, ? extends U, E1> null.The first function to apply, must not be mapper1, final FailableFunction<? super U, ? extends R, E2> null.The second function to apply, must not be mapper2)null.Applies values to a chain of functions, where a |
| public static < The type of the input of this method and the first function. T, The type of the result of the first function and the input to the second function. U, The type of the result of the second function and the input to the third function. V, The type of the result of the third function and this method. R, The type of thrown exception or error by the first function. E1 extends Throwable, The type of thrown exception or error by the second function. E2 extends Throwable, The type of thrown exception or error by the second function. E3 extends Throwable> R | Returns: The result of the final function (which may benull) or null if the input value or any intermediate value is null.The value to apply the first function, may be value1, final FailableFunction<? super T, ? extends U, E1> null.The first function to apply, must not be mapper1, final FailableFunction<? super U, ? extends V, E2> null.The second function to apply, must not be mapper2, final FailableFunction<? super V, ? extends R, E3> null.The third function to apply, must not be mapper3)null.Applies values to a chain of functions, where a |
| public static < the type of the first argument of the consumers T, the type of the second argument of the consumers U> BiConsumer | Returns: a standardBiConsumera failable consumer)BiConsumerConverts the given |
| public static < the type of the first argument of the input of the functions T, the type of the second argument of the input of the functions U, the type of the output of the functions R> BiFunction | Returns: a standardBiFunctionConverts the given |
| public static < the type of the first argument used by the predicates T, the type of the second argument used by the predicates U> BiPredicate | Returns: a standardBiPredicateConverts the given |
| public static < the type used by the callables V> Callable | Returns: a standardCallableConverts the given |
| public static < the type used by the consumers T> Consumer | Returns: a standardConsumerConverts the given |
| public static < the type of the input of the functions T, the type of the output of the functions R> Function | Returns: a standardFunctiona {code FailableFunction} function)Converts the given |
| public static < the type used by the predicates T> Predicate | Returns: a standardPredicateConverts the given |
| public static Runnable | Returns: a standardRunnableConverts the given |
| public static < the type supplied by the suppliers T> Supplier | Returns: a standardSupplierConverts the given |
| public static < the return type of the callable V, the type of checked exception the callable may throw E extends Throwable> V | Returns: the value returned from the callablethe callable to call callable)Calls a callable and rethrows any exception as a |
| public static < The suppliers output type. T, The type of checked exception, which the supplier can throw. E extends Throwable> T | Returns: The object, which has been created by the supplierThe supplier to invoke. supplier)Invokes a supplier, and returns the result. |
| public static < The type of checked exception, which the supplier can throw. E extends Throwable> boolean | Returns: The boolean, which has been created by the supplierThe boolean supplier to invoke. supplier)Invokes a boolean supplier, and returns the result. |
| public static < The type of checked exception, which the supplier can throw. E extends Throwable> double | Returns: The double, which has been created by the supplierThe double supplier to invoke. supplier)Invokes a double supplier, and returns the result. |
| public static < The type of checked exception, which the supplier can throw. E extends Throwable> int | Returns: The int, which has been created by the supplierThe int supplier to invoke. supplier)Invokes an int supplier, and returns the result. |
| public static < The type of checked exception, which the supplier can throw. E extends Throwable> long | Returns: The long, which has been created by the supplierThe long supplier to invoke. supplier)Invokes a long supplier, and returns the result. |
| public static < The type of checked exception, which the supplier can throw. E extends Throwable> short | Returns: The short, which has been created by the supplierThe short supplier to invoke. supplier)Invokes a short supplier, and returns the result. |
| public static RuntimeException | |
| public static < the type of checked exception the runnable may throw. E extends Throwable> void | run(final FailableRunnable<E>
The runnable to run, may be null for a noop. runnable)Runs a runnable and rethrows any exception as a |
| private static <E extends Throwable> void | |
| public static < The collections element type. (In turn, the result streams element type.) E> Streams. | Returns: The createdFailableStream.The collection, which is being converted into a collection)FailableStream.Converts the given collection into a |
| public static < The streams element type. T> Streams. | Returns: The createdFailableStream.The stream, which is being converted into a stream)FailableStream.Converts the given stream into a |
| public static < the type of the first argument the predicate tests T, the type of the second argument the predicate tests U, the type of checked exception the predicate may throw E extends Throwable> boolean | Returns: the boolean value returned by the predicatethe predicate to test predicate, final T the first input to test by object1, final U predicatethe second input to test by object2)predicateTests a predicate and rethrows any exception as a |
| public static < the type of argument the predicate tests T, the type of checked exception the predicate may throw E extends Throwable> boolean | Returns: the boolean value returned by the predicatethe predicate to test predicate, final T the input to test by object)predicateTests a predicate and rethrows any exception as a |
| public static void | tryWithResources(final FailableRunnable<? extends Throwable>
The action to execute. This object will always be invoked. action, final FailableConsumer<Throwable, ? extends Throwable> An optional error handler, which will be invoked finally, if any error occurred. The error
handler will receive the first error, AKA errorHandler, final FailableRunnable<? extends Throwable>... Throwable.The resource actions to execute. All resource actions will be invoked, in the given
order. A resource action is an instance of resources)FailableRunnable, which will be executed.A simple try-with-resources implementation, that can be used, if your objects do not implement the
|
| public static void | tryWithResources(final FailableRunnable<? extends Throwable>
The action to execute. This object will always be invoked. action, final FailableRunnable<? extends Throwable>... The resource actions to execute. All resource actions will be invoked, in the given
order. A resource action is an instance of resources)FailableRunnable, which will be executed.A simple try-with-resources implementation, that can be used, if your objects do not implement the
|
| Failable | back to summary |
|---|---|
| private Failable() | |
| accept | back to summary |
|---|---|
| public static <T, U, E extends Throwable> void accept(final FailableBiConsumer<T, U, E> consumer, final T object1, final U object2) Consumes a consumer and rethrows any exception as a
| |
| accept | back to summary |
|---|---|
| public static <T, E extends Throwable> void accept(final FailableConsumer<T, E> consumer, final T object) Consumes a consumer and rethrows any exception as a
| |
| accept | back to summary |
|---|---|
| public static <E extends Throwable> void accept(final FailableDoubleConsumer<E> consumer, final double value) Consumes a consumer and rethrows any exception as a
| |
| accept | back to summary |
|---|---|
| public static <E extends Throwable> void accept(final FailableIntConsumer<E> consumer, final int value) Consumes a consumer and rethrows any exception as a
| |
| accept | back to summary |
|---|---|
| public static <E extends Throwable> void accept(final FailableLongConsumer<E> consumer, final long value) Consumes a consumer and rethrows any exception as a
| |
| apply | back to summary |
|---|---|
| public static <T, U, R, E extends Throwable> R apply(final FailableBiFunction<T, U, R, E> function, final T input1, final U input2) Applies a function and rethrows any exception as a
| |
| apply | back to summary |
|---|---|
| public static <T, R, E extends Throwable> R apply(final FailableFunction<T, R, E> function, final T input) Applies a function and rethrows any exception as a
| |
| applyAsDouble | back to summary |
|---|---|
| public static <E extends Throwable> double applyAsDouble(final FailableDoubleBinaryOperator<E> function, final double left, final double right) Applies a function and rethrows any exception as a
| |
| applyNonNull | back to summary |
|---|---|
| public static <T, R, E extends Throwable> R applyNonNull(final T value, final FailableFunction<? super T, ? extends R, E> mapper) throws E Applies a value to a function if the value isn't
Useful when working with expressions that may return
| |
| applyNonNull | back to summary |
|---|---|
| public static <T, U, R, E1 extends Throwable, E2 extends Throwable> R applyNonNull(final T value1, final FailableFunction<? super T, ? extends U, E1> mapper1, final FailableFunction<? super U, ? extends R, E2> mapper2) throws FailableFunction-:E1, FailableFunction-:E2 Applies values to a chain of functions, where a
Useful when working with expressions that may return
| |
| applyNonNull | back to summary |
|---|---|
| public static <T, U, V, R, E1 extends Throwable, E2 extends Throwable, E3 extends Throwable> R applyNonNull(final T value1, final FailableFunction<? super T, ? extends U, E1> mapper1, final FailableFunction<? super U, ? extends V, E2> mapper2, final FailableFunction<? super V, ? extends R, E3> mapper3) throws FailableFunction-:E1, FailableFunction-:E2, FailableFunction-:E3 Applies values to a chain of functions, where a
Useful when working with expressions that may return
| |
| asBiConsumer | back to summary |
|---|---|
| public static <T, U> BiConsumer Converts the given
| |
| asBiFunction | back to summary |
|---|---|
| public static <T, U, R> BiFunction Converts the given
| |
| asBiPredicate | back to summary |
|---|---|
| public static <T, U> BiPredicate Converts the given
| |
| asCallable | back to summary |
|---|---|
| public static <V> Callable Converts the given
| |
| asConsumer | back to summary |
|---|---|
| public static <T> Consumer Converts the given
| |
| asFunction | back to summary |
|---|---|
| public static <T, R> Function Converts the given
| |
| asPredicate | back to summary |
|---|---|
| public static <T> Predicate Converts the given
| |
| asRunnable | back to summary |
|---|---|
| public static Runnable asRunnable(final FailableRunnable<?> runnable) Converts the given
| |
| asSupplier | back to summary |
|---|---|
| public static <T> Supplier Converts the given
| |
| call | back to summary |
|---|---|
| public static <V, E extends Throwable> V call(final FailableCallable<V, E> callable) Calls a callable and rethrows any exception as a
| |
| get | back to summary |
|---|---|
| public static <T, E extends Throwable> T get(final FailableSupplier<T, E> supplier) Invokes a supplier, and returns the result.
| |
| getAsBoolean | back to summary |
|---|---|
| public static <E extends Throwable> boolean getAsBoolean(final FailableBooleanSupplier<E> supplier) Invokes a boolean supplier, and returns the result.
| |
| getAsDouble | back to summary |
|---|---|
| public static <E extends Throwable> double getAsDouble(final FailableDoubleSupplier<E> supplier) Invokes a double supplier, and returns the result.
| |
| getAsInt | back to summary |
|---|---|
| public static <E extends Throwable> int getAsInt(final FailableIntSupplier<E> supplier) Invokes an int supplier, and returns the result.
| |
| getAsLong | back to summary |
|---|---|
| public static <E extends Throwable> long getAsLong(final FailableLongSupplier<E> supplier) Invokes a long supplier, and returns the result.
| |
| getAsShort | back to summary |
|---|---|
| public static <E extends Throwable> short getAsShort(final FailableShortSupplier<E> supplier) Invokes a short supplier, and returns the result.
| |
| rethrow | back to summary |
|---|---|
| public static RuntimeException rethrow(final Throwable throwable) Rethrows a Note that there is a declared return type for this method, even though it never returns. The reason for that is to support the usual pattern: throw rethrow(myUncheckedException);
instead of just calling the method. This pattern may help the Java compiler to recognize that at that point an
exception will be thrown and the code flow analysis will not demand otherwise mandatory commands that could
follow the method call, like a
| |
| run | back to summary |
|---|---|
| public static <E extends Throwable> void run(final FailableRunnable<E> runnable) Runs a runnable and rethrows any exception as a
| |
| run | back to summary |
|---|---|
| private static <E extends Throwable> void run(final Object test, final FailableRunnable<E> runnable) | |
| stream | back to summary |
|---|---|
| public static <E> Streams. Converts the given collection into a Functions.stream(collection.stream());
| |
| stream | back to summary |
|---|---|
| public static <T> Streams. Converts the given stream into a
| |
| test | back to summary |
|---|---|
| public static <T, U, E extends Throwable> boolean test(final FailableBiPredicate<T, U, E> predicate, final T object1, final U object2) Tests a predicate and rethrows any exception as a
| |
| test | back to summary |
|---|---|
| public static <T, E extends Throwable> boolean test(final FailablePredicate<T, E> predicate, final T object) Tests a predicate and rethrows any exception as a
| |
| tryWithResources | back to summary |
|---|---|
| public static void tryWithResources(final FailableRunnable<? extends Throwable> action, final FailableConsumer<Throwable, ? extends Throwable> errorHandler, final FailableRunnable<? extends Throwable>... resources) A simple try-with-resources implementation, that can be used, if your objects do not implement the
| |
| tryWithResources | back to summary |
|---|---|
| public static void tryWithResources(final FailableRunnable<? extends Throwable> action, final FailableRunnable<? extends Throwable>... resources) A simple try-with-resources implementation, that can be used, if your objects do not implement the
| |