package de.nclazz.commons.func; import java.rmi.server.ExportException; import java.util.function.*; public abstract class Checked { private Checked() { /* no-op */ } @FunctionalInterface public interface CheckedConsumer { void accept(T t) throws Exception; } @FunctionalInterface public interface CheckedBiConsumer { void accept(T t, U u) throws Exception; } @FunctionalInterface public interface CheckedFunction { R apply(T t) throws Exception; } @FunctionalInterface public interface CheckedBiFunction { R apply(T t, U u) throws Exception; } @FunctionalInterface public interface CheckedPredicate { boolean test(T t) throws Exception; } @FunctionalInterface public interface CheckedBiPredicate { boolean test(T t, U u) throws Exception; } @FunctionalInterface public interface CheckedRunnable { void run() throws Exception; } @FunctionalInterface public interface CheckedSupplier { T get() throws Exception; } public static Consumer checked(CheckedConsumer consumer) { return t -> { try { consumer.accept(t); }catch(Exception e) { throw new RuntimeException(e); } }; } public static BiConsumer checked(CheckedBiConsumer consumer) { return (t, u) -> { try { consumer.accept(t, u); }catch(Exception e) { throw new RuntimeException(e); } }; } public static Function checked(CheckedFunction function) { return t -> { try { return function.apply(t); }catch(Exception e) { throw new RuntimeException(e); } }; } public static BiFunction checked(CheckedBiFunction function) { return (t, u) -> { try { return function.apply(t, u); }catch(Exception e) { throw new RuntimeException(e); } }; } public static Predicate checked(Predicate predicate) { return t -> { try { return predicate.test(t); }catch(Exception e) { throw new RuntimeException(e); } }; } public static BiPredicate checked(CheckedBiPredicate predicate) { return (t, u) -> { try { return predicate.test(t, u); }catch(Exception e) { throw new RuntimeException(e); } }; } public static Runnable checked(CheckedRunnable runnable) { return () -> { try { runnable.run(); }catch(Exception e) { throw new RuntimeException(e); } }; } public static Supplier checked(CheckedSupplier supplier) { return () -> { try { return supplier.get(); }catch(Exception e) { throw new RuntimeException(e); } }; } }