FEAT FIX Checked missing CheckedSupplier interface
NClazz/java-commons/pipeline/head This commit looks good
Details
NClazz/java-commons/pipeline/head This commit looks good
Details
parent
053765e369
commit
9ddc17aaa1
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue