fr.profi.mzdb.util.lambda.JavaStreamExceptionWrappers Maven / Gradle / Ivy
package fr.profi.mzdb.util.lambda;
public interface JavaStreamExceptionWrappers {
}
//
//import java.util.function.Consumer;
//import java.util.function.Function;
//import java.util.function.Supplier;
//
//// Code copie from: http://stackoverflow.com/questions/14039995/java-8-mandatory-checked-exceptions-handling-in-lambda-expressions-why-mandato
//public class JavaStreamExceptionWrappers {
//
// @FunctionalInterface
// public interface Consumer_WithExceptions {
// void accept(T t) throws Exception;
// }
//
// @FunctionalInterface
// public interface Function_WithExceptions {
// R apply(T t) throws Exception;
// }
//
// @FunctionalInterface
// public interface Supplier_WithExceptions {
// T get() throws Exception;
// }
//
// @FunctionalInterface
// public interface Runnable_WithExceptions {
// void accept() throws Exception;
// }
//
// public static Consumer rethrowConsumer(Consumer_WithExceptions consumer) {
// return t -> {
// try { consumer.accept(t); }
// catch (Exception exception) { throwAsUnchecked(exception); }
// };
// }
//
// /** .map(rethrowFunction(name -> Class.forName(name))) or .map(rethrowFunction(Class::forName)) */
// public static Function rethrowFunction(Function_WithExceptions function) {
// return t -> {
// try { return function.apply(t); }
// catch (Exception exception) { throwAsUnchecked(exception); return null; }
// };
// }
//
// /** rethrowSupplier(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8"))), */
// public static Supplier rethrowSupplier(Supplier_WithExceptions function) {
// return () -> {
// try { return function.get(); }
// catch (Exception exception) { throwAsUnchecked(exception); return null; }
// };
// }
//
// /** uncheck(() -> Class.forName("xxx")); */
// public static void uncheck(Runnable_WithExceptions t)
// {
// try { t.accept(); }
// catch (Exception exception) { throwAsUnchecked(exception); }
// }
//
// /** uncheck(() -> Class.forName("xxx")); */
// public static R uncheck(Supplier_WithExceptions supplier)
// {
// try { return supplier.get(); }
// catch (Exception exception) { throwAsUnchecked(exception); return null; }
// }
//
// /** uncheck(Class::forName, "xxx"); */
// public static R uncheck(Function_WithExceptions function, T t) {
// try { return function.apply(t); }
// catch (Exception exception) { throwAsUnchecked(exception); return null; }
// }
//
// @SuppressWarnings ("unchecked")
// private static void throwAsUnchecked(Exception exception) throws E { throw (E)exception; }
//
//}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy