public class ExceptionSoftener
extends java.lang.Object
throw ExceptionSoftener.throwSoftenedException(new IOException("hello"));
Or soften lambda's and method references
interface IO{
static String load() throws IOException
}
Supplier<String> supplier = ExceptionSoftener.soften(IO::load);
Constructor and Description |
---|
ExceptionSoftener() |
Modifier and Type | Method and Description |
---|---|
static <T1,T2> java.util.function.BiConsumer<T1,T2> |
softenBiConsumer(org.jooq.lambda.fi.util.function.CheckedBiConsumer<T1,T2> fn)
Soften a CheckedBiConsumer that can throw Checked Exceptions to a standard BiConsumer that can also throw Checked Exceptions (without declaring them)
e.g.
|
static <T1,T2,R> java.util.function.BiFunction<T1,T2,R> |
softenBiFunction(org.jooq.lambda.fi.util.function.CheckedBiFunction<T1,T2,R> fn)
Soften a CheckedBiFunction that can throw Checked Exceptions to a standard BiFunction that can also throw Checked Exceptions (without declaring them)
|
static <T1,T2> java.util.function.BiPredicate<T1,T2> |
softenBiPredicate(org.jooq.lambda.fi.util.function.CheckedBiPredicate<T1,T2> fn)
Soften a CheckedBiPredicate that can throw Checked Exceptions to a standard BiPredicate that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.BooleanSupplier |
softenBooleanSupplier(org.jooq.lambda.fi.util.function.CheckedBooleanSupplier s)
Soften a BooleanSuppler that throws a checked exception into one that still throws the exception, but doesn't need to declare it.
|
static <T> java.util.function.Supplier<T> |
softenCallable(java.util.concurrent.Callable<T> s)
Soften a Callable that throws a ChecekdException into a Supplier
|
static <T> java.util.function.Consumer<T> |
softenConsumer(org.jooq.lambda.fi.util.function.CheckedConsumer<T> fn)
Soften a CheckedConsumer that can throw Checked Exceptions to a standard Consumer that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.DoubleConsumer |
softenDoubleConsumer(org.jooq.lambda.fi.util.function.CheckedDoubleConsumer fn)
Soften a CheckedDoubleConsumer that can throw Checked Exceptions to a standard DoubleConsumer that can also throw Checked Exceptions (without declaring them)
e.g.
|
static <R> java.util.function.DoubleFunction<R> |
softenDoubleFunction(org.jooq.lambda.fi.util.function.CheckedDoubleFunction<R> fn)
Soften a CheckedDoubleFunction that can throw Checked Exceptions to a standard DoubleFunction that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.DoublePredicate |
softenDoublePredicate(org.jooq.lambda.fi.util.function.CheckedDoublePredicate fn)
Soften a CheckedDoublePredicate that can throw Checked Exceptions to a standard DoublePredicate that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.DoubleSupplier |
softenDoubleSupplier(org.jooq.lambda.fi.util.function.CheckedDoubleSupplier s)
Soften a CheckedDoubleSupplier to an DoubleSupplier that doesn't need to declare any checked exceptions thrown
e.g.
|
static java.util.function.DoubleToIntFunction |
softenDoubleToIntFunction(org.jooq.lambda.fi.util.function.CheckedDoubleToIntFunction fn)
Soften a CheckedDoubleToIntFunction that can throw Checked Exceptions to a standard DoubleToIntFunction that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.DoubleToLongFunction |
softenDoubleToLongFunction(org.jooq.lambda.fi.util.function.CheckedDoubleToLongFunction fn)
Soften a CheckedDoubleToLongFunction that can throw Checked Exceptions to a standard DoubleToLongFunction that can also throw Checked Exceptions (without declaring them)
e.g.
|
static <T,R> java.util.function.Function<T,R> |
softenFunction(org.jooq.lambda.fi.util.function.CheckedFunction<T,R> fn)
Soften a CheckedFunction that can throw Checked Exceptions to a standard Function that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.IntConsumer |
softenIntConsumer(org.jooq.lambda.fi.util.function.CheckedIntConsumer fn)
Soften a CheckedIntConsumer that can throw Checked Exceptions to a standard IntConsumer that can also throw Checked Exceptions (without declaring them)
e.g.
|
static <R> java.util.function.IntFunction<R> |
softenIntFunction(org.jooq.lambda.fi.util.function.CheckedIntFunction<R> fn)
Soften a CheckedIntFunction that can throw Checked Exceptions to a standard IntFunction that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.IntPredicate |
softenIntPredicate(org.jooq.lambda.fi.util.function.CheckedIntPredicate fn)
Soften a CheckedIntPredicate that can throw Checked Exceptions to a standard IntPredicate that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.IntSupplier |
softenIntSupplier(org.jooq.lambda.fi.util.function.CheckedIntSupplier s)
Soften a CheckedIntSupplier to an IntSupplier that doesn't need to declare any checked exceptions thrown
e.g.
|
static java.util.function.IntToDoubleFunction |
softenIntToDoubleFunction(org.jooq.lambda.fi.util.function.CheckedIntToDoubleFunction fn)
Soften a CheckedIntToDoubleFunction that can throw Checked Exceptions to a standard IntToDoubleFunction that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.IntToLongFunction |
softenIntToLongFunction(org.jooq.lambda.fi.util.function.CheckedIntToLongFunction fn)
Soften a CheckedIntToLongFunction that can throw Checked Exceptions to a standard IntToLongFunction that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.LongConsumer |
softenLongConsumer(org.jooq.lambda.fi.util.function.CheckedLongConsumer fn)
Soften a CheckedLongConsumer that can throw Checked Exceptions to a standard LongConsumer that can also throw Checked Exceptions (without declaring them)
e.g.
|
static <R> java.util.function.LongFunction<R> |
softenLongFunction(org.jooq.lambda.fi.util.function.CheckedLongFunction<R> fn)
Soften a CheckedLongFunction that can throw Checked Exceptions to a standard LongFunction that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.LongPredicate |
softenLongPredicate(org.jooq.lambda.fi.util.function.CheckedLongPredicate fn)
Soften a CheckedLongPredicate that can throw Checked Exceptions to a standard LongPredicate that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.LongSupplier |
softenLongSupplier(org.jooq.lambda.fi.util.function.CheckedLongSupplier s)
Soften a CheckedLongSupplier to an LongSupplier that doesn't need to declare any checked exceptions thrown
e.g.
|
static java.util.function.LongToDoubleFunction |
softenLongToDoubleFunction(org.jooq.lambda.fi.util.function.CheckedLongToDoubleFunction fn)
Soften a CheckedLongToDoubleFunction that can throw Checked Exceptions to a standard LongToDoubleFunction that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.util.function.LongToIntFunction |
softenLongToIntFunction(org.jooq.lambda.fi.util.function.CheckedLongToIntFunction fn)
Soften a CheckedLongToIntFunction that can throw Checked Exceptions to a standard LongToIntFunction that can also throw Checked Exceptions (without declaring them)
e.g.
|
static <T> java.util.function.Predicate<T> |
softenPredicate(org.jooq.lambda.fi.util.function.CheckedPredicate<T> fn)
Soften a CheckedPredicate that can throw Checked Exceptions to a standard Predicate that can also throw Checked Exceptions (without declaring them)
e.g.
|
static java.lang.Runnable |
softenRunnable(org.jooq.lambda.fi.lang.CheckedRunnable s)
Soften a Runnable that throws a ChecekdException into a plain old Runnable
|
static <T> java.util.function.Supplier<T> |
softenSupplier(org.jooq.lambda.fi.util.function.CheckedSupplier<T> s)
Soften a Supplier that throws a ChecekdException into a plain old Supplier
|
static <X extends java.lang.Throwable> |
throwIf(X e,
java.util.function.Predicate<X> p)
Throw the exception as upwards if the predicate holds, otherwise do nothing
|
static <X extends java.lang.Throwable> |
throwOrHandle(X e,
java.util.function.Predicate<X> p,
java.util.function.Consumer<X> handler)
Throw the exception as upwards if the predicate holds, otherwise pass to the handler
|
static java.lang.RuntimeException |
throwSoftenedException(java.lang.Throwable e)
Convert any throwable into an unchecked exception.
|
public static java.lang.Runnable softenRunnable(org.jooq.lambda.fi.lang.CheckedRunnable s)
Runnable runnable = ExceptionSoftener.softenRunnable(this::run);
runnable.run() //thows IOException but doesn't need to declare it
private void run() throws IOException{
throw new IOException();
}
ExceptionSoftener.softenRunnable(()->Thread.sleep(1000));
s
- Supplier with CheckedExceptionpublic static <T> java.util.function.Supplier<T> softenSupplier(org.jooq.lambda.fi.util.function.CheckedSupplier<T> s)
Supplier<String> supplier = ExceptionSoftener.softenSupplier(this::get);
supplier.get(); //thows IOException but doesn't need to declare it
private String get() throws IOException{
return "hello";
}
s
- Supplier with CheckedExceptionpublic static <T> java.util.function.Supplier<T> softenCallable(java.util.concurrent.Callable<T> s)
Supplier<String> supplier = ExceptionSoftener.softenCallable(this);
supplier.get(); //thows IOException but doesn't need to declare it
public String call() throws IOException{
return "hello";
}
s
- Callable with CheckedExceptionpublic static java.util.function.BooleanSupplier softenBooleanSupplier(org.jooq.lambda.fi.util.function.CheckedBooleanSupplier s)
assertThat(ExceptionSoftener.softenBooleanSupplier(()->true).getAsBoolean(),equalTo(true));
BooleanSupplier supplier = ExceptionSoftener.softenBooleanSupplier(()->{throw new IOException();});
supplier.get() //throws IOException but doesn't need to declare it
s
- CheckedBooleanSupplier to softenpublic static java.util.function.IntSupplier softenIntSupplier(org.jooq.lambda.fi.util.function.CheckedIntSupplier s)
IntSupplier supplier = ExceptionSoftener.softenIntSupplier(()->{throw new IOException();})
supplier.getAsInt();//throws IOException but doesn't need to declare it
//as a method reference
ExceptionSoftener.softenIntSupplier(this::getInt);
s
- CheckedIntSupplier to softenpublic static java.util.function.LongSupplier softenLongSupplier(org.jooq.lambda.fi.util.function.CheckedLongSupplier s)
LongSupplier supplier = ExceptionSoftener.softenLongSupplier(()->{throw new IOException();})
supplier.getAsLong();//throws IOException but doesn't need to declare it
//as a method reference
ExceptionSoftener.softenLongSupplier(this::getLong);
s
- CheckedLongSupplier to softenpublic static java.util.function.DoubleSupplier softenDoubleSupplier(org.jooq.lambda.fi.util.function.CheckedDoubleSupplier s)
DoubleSupplier supplier = ExceptionSoftener.softenDoubleSupplier(()->{throw new IOException();})
supplier.getAsDouble();//throws IOException but doesn't need to declare it
//as a method reference
ExceptionSoftener.softenDoubleSupplier(this::getDouble);
s
- CheckedDoubleSupplier to softenpublic static <T,R> java.util.function.Function<T,R> softenFunction(org.jooq.lambda.fi.util.function.CheckedFunction<T,R> fn)
{@code Data loaded = ExceptionSoftener.softenFunction(this::load).apply(fileName); public Data load(String file) throws IOException
fn
- CheckedFunction to be converted to a standard Functionpublic static <R> java.util.function.IntFunction<R> softenIntFunction(org.jooq.lambda.fi.util.function.CheckedIntFunction<R> fn)
{@code int loaded = ExceptionSoftener.softenFunction(this::load).apply(id); public int load(int it) throws IOException
fn
- CheckedIntFunction to be converted to a standard IntFunctionpublic static <R> java.util.function.LongFunction<R> softenLongFunction(org.jooq.lambda.fi.util.function.CheckedLongFunction<R> fn)
{@code long loaded = ExceptionSoftener.softenFunction(this::load).apply(id); public long load(long it) throws IOException
fn
- CheckedLongFunction to be converted to a standard LongFunctionpublic static <R> java.util.function.DoubleFunction<R> softenDoubleFunction(org.jooq.lambda.fi.util.function.CheckedDoubleFunction<R> fn)
{@code double loaded = ExceptionSoftener.softenFunction(this::load).apply(id); public double load(double it) throws IOException
fn
- CheckedDoubleFunction to be converted to a standard DoubleFunctionpublic static java.util.function.LongToDoubleFunction softenLongToDoubleFunction(org.jooq.lambda.fi.util.function.CheckedLongToDoubleFunction fn)
{@code double loaded = ExceptionSoftener.softenFunction(this::load).apply(id); public double load(long it) throws IOException
fn
- CheckedLongToDoubleFunction to be converted to a standard LongToDoubleFunctionpublic static java.util.function.LongToIntFunction softenLongToIntFunction(org.jooq.lambda.fi.util.function.CheckedLongToIntFunction fn)
{@code int loaded = ExceptionSoftener.softenFunction(this::load).apply(id); public int load(long it) throws IOException
fn
- CheckedLongToIntFunction to be converted to a standard LongToIntFunctionpublic static java.util.function.IntToDoubleFunction softenIntToDoubleFunction(org.jooq.lambda.fi.util.function.CheckedIntToDoubleFunction fn)
{@code double loaded = ExceptionSoftener.softenFunction(this::load).apply(id); public double load(int it) throws IOException
fn
- CheckedIntToDoubleFunction to be converted to a standard IntToDoubleFunctionpublic static java.util.function.IntToLongFunction softenIntToLongFunction(org.jooq.lambda.fi.util.function.CheckedIntToLongFunction fn)
{@code double loaded = ExceptionSoftener.softenFunction(this::load).apply(id); public long load(int it) throws IOException
fn
- CheckedIntToLongFunction to be converted to a standard IntToLongFunctionpublic static java.util.function.DoubleToIntFunction softenDoubleToIntFunction(org.jooq.lambda.fi.util.function.CheckedDoubleToIntFunction fn)
{@code int loaded = ExceptionSoftener.softenFunction(this::load).apply(id); public int load(double it) throws IOException
fn
- CheckedDoubleToIntFunction to be converted to a standard DoubleToIntFunctionpublic static java.util.function.DoubleToLongFunction softenDoubleToLongFunction(org.jooq.lambda.fi.util.function.CheckedDoubleToLongFunction fn)
{@code long loaded = ExceptionSoftener.softenFunction(this::load).apply(id); public long load(double it) throws IOException
fn
- CheckedDoubleToLongFunction to be converted to a standard DoubleToLongFunctionpublic static <T1,T2,R> java.util.function.BiFunction<T1,T2,R> softenBiFunction(org.jooq.lambda.fi.util.function.CheckedBiFunction<T1,T2,R> fn)
ExceptionSoftener.softenBiFunction(this::loadDir).apply(".core","/tmp/dir");
public String loadDir(String fileExt,String dir) throws IOException
fn
- CheckedBiLongFunction to be converted to a standard BiFunctionpublic static <T> java.util.function.Predicate<T> softenPredicate(org.jooq.lambda.fi.util.function.CheckedPredicate<T> fn)
{@code boolean loaded = ExceptionSoftener.softenPredicate(this::exists).test(id); public boolean exists(Double id) throws IOException
fn
- CheckedPredicate to be converted to a standard Predicatepublic static java.util.function.DoublePredicate softenDoublePredicate(org.jooq.lambda.fi.util.function.CheckedDoublePredicate fn)
{@code boolean loaded = ExceptionSoftener.softenDoublePredicate(this::exists).test(id); public boolean exists(double id) throws IOException
fn
- CheckedDoublePredicate to be converted to a standard DoublePredicatepublic static java.util.function.IntPredicate softenIntPredicate(org.jooq.lambda.fi.util.function.CheckedIntPredicate fn)
{@code boolean loaded = ExceptionSoftener.softenIntPredicate(this::exists).test(id); public boolean exists(int id) throws IOException
fn
- CheckedIntPredicate to be converted to a standard IntPredicatepublic static java.util.function.LongPredicate softenLongPredicate(org.jooq.lambda.fi.util.function.CheckedLongPredicate fn)
{@code boolean loaded = ExceptionSoftener.softenLongPredicate(this::exists).test(id); public boolean exists(long id) throws IOException
fn
- CheckedLongPredicate to be converted to a standard LongPredicatepublic static <T1,T2> java.util.function.BiPredicate<T1,T2> softenBiPredicate(org.jooq.lambda.fi.util.function.CheckedBiPredicate<T1,T2> fn)
{@code boolean loaded = ExceptionSoftener.softenBiPredicate(this::exists).test(id,"db"); public boolean exists(int id, String context) throws IOException
fn
- CheckedBiPredicate to be converted to a standard BiPredicatepublic static <T> java.util.function.Consumer<T> softenConsumer(org.jooq.lambda.fi.util.function.CheckedConsumer<T> fn)
{@code ExceptionSoftener.softenConsumer(this::save).accept(data); public void save(Data data) throws IOException
fn
- CheckedConsumer to be converted to a standard Consumerpublic static java.util.function.DoubleConsumer softenDoubleConsumer(org.jooq.lambda.fi.util.function.CheckedDoubleConsumer fn)
{@code ExceptionSoftener.softenDoubleConsumer(this::save).accept(data); public void save(double data) throws IOException
fn
- CheckedDoubleConsumer to be converted to a standard DoubleConsumerpublic static java.util.function.IntConsumer softenIntConsumer(org.jooq.lambda.fi.util.function.CheckedIntConsumer fn)
{@code ExceptionSoftener.softenIntConsumer(this::save).accept(data); public void save(int data) throws IOException
fn
- CheckedIntConsumer to be converted to a standard IntConsumerpublic static java.util.function.LongConsumer softenLongConsumer(org.jooq.lambda.fi.util.function.CheckedLongConsumer fn)
{@code ExceptionSoftener.softenLongConsumer(this::save).accept(data); public void save(long data) throws IOException
fn
- CheckedLongConsumer to be converted to a standard LongConsumerpublic static <T1,T2> java.util.function.BiConsumer<T1,T2> softenBiConsumer(org.jooq.lambda.fi.util.function.CheckedBiConsumer<T1,T2> fn)
{@code ExceptionSoftener.softenBiConsumer(this::save).accept(data,System.currentTimeMillis()); public void save(Data data,long timestamp) throws IOException
fn
- CheckedBiConsumer to be converted to a standard BiConsumerpublic static java.lang.RuntimeException throwSoftenedException(java.lang.Throwable e)
//IOException does not need to be declared
public Data load(String input) {
try{
}catch(IOException e) {
throw ExceptionSoftener.throwSoftenedException(e);
}
}
e
- public static <X extends java.lang.Throwable> void throwIf(X e, java.util.function.Predicate<X> p)
e
- Exceptionp
- Predicate to check exception should be thrown or notpublic static <X extends java.lang.Throwable> void throwOrHandle(X e, java.util.function.Predicate<X> p, java.util.function.Consumer<X> handler)
e
- Exceptionp
- Predicate to check exception should be thrown or nothandler
- Handles exceptions that should not be thrown