FEAT FIX Checked missing CheckedSupplier interface
NClazz/java-commons/pipeline/head This commit looks good Details

master
Niclas Thobaben 2020-12-04 20:02:23 +01:00
parent 053765e369
commit 9ddc17aaa1
1 changed files with 16 additions and 1 deletions

View File

@ -42,6 +42,11 @@ public abstract class Checked {
void run() throws Exception;
}
@FunctionalInterface
public interface CheckedSupplier<T> {
T get() throws Exception;
}
public static <T> Consumer<T> checked(CheckedConsumer<T> consumer) {
return t -> {
try {
@ -103,7 +108,7 @@ public abstract class Checked {
}
public static Runnable checked(Runnable runnable) {
public static Runnable checked(CheckedRunnable runnable) {
return () -> {
try {
runnable.run();
@ -113,5 +118,15 @@ public abstract class Checked {
};
}
public static <T> Supplier<T> checked(CheckedSupplier<T> supplier) {
return () -> {
try {
return supplier.get();
}catch(Exception e) {
throw new RuntimeException(e);
}
};
}
}