Class LambdaUnchecker
- java.lang.Object
-
- org.bytemechanics.commons.functional.LambdaUnchecker
-
public final class LambdaUnchecker extends Object
Utility class to hide checked exceptions. Thanks to:- https://stackoverflow.com/questions/27644361/how-can-i-throw-checked-exceptions-from-inside-java-8-streams#27668305
- http://www.philandstuff.com/2012/04/28/sneakily-throwing-checked-exceptions.html http://www.mail-archive.com/javaposse@googlegroups.com/msg05984.html
- https://softwareengineering.stackexchange.com/questions/225931/workaround-for-java-checked-exceptions?newreg=ddf0dd15e8174af8ba52e091cf85688e
- https://stackoverflow.com/questions/27644361/how-can-i-throw-checked-exceptions-from-inside-java-8-streams
- Since:
- 1.1.0
- Author:
- not sure
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceLambdaUnchecker.BiConsumerWithExceptions<T,U,E extends Exception>Functional interface for biconsumers with checked exceptionsstatic interfaceLambdaUnchecker.ConsumerWithExceptions<T,E extends Exception>Functional interface for consumers with checked exceptionsstatic interfaceLambdaUnchecker.FunctionWithExceptions<T,R,E extends Exception>Functional interface for functions with checked exceptionsstatic interfaceLambdaUnchecker.RunnableWithExceptions<E extends Exception>Functional interface for runnables with checked exceptionsstatic interfaceLambdaUnchecker.SupplierWithExceptions<T,E extends Exception>Functional interface for suppliers with checked exceptions
-
Constructor Summary
Constructors Constructor Description LambdaUnchecker()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,U,E extends Exception>
voidsilencedAccept(LambdaUnchecker.BiConsumerWithExceptions<T,U,E> _biConsumer, T _firstInput, U _secondInput)Accept consumer input but silencing the exception Example:silencedAccept((name,value) -> System.out.println(Class.forName(name)+value));static <T,E extends Exception>
voidsilencedAccept(LambdaUnchecker.ConsumerWithExceptions<T,E> _consumer, T _input)Accept consumer input but silencing the exception Example:uncheckedAccept(name -> System.out.println(Class.forName(name)),"java.util.List");static <T,R,E extends Exception>
RsilencedApply(LambdaUnchecker.FunctionWithExceptions<T,R,E> _function, T _input)Apply function returning the result but returning null when exception and silencing the exception and in this case returning null Example:silencedFunction(name -> Class.forName(name))orsilencedFunction(Class::forName)static <T,U,E extends Exception>
BiConsumer<T,U>silencedBiConsumer(LambdaUnchecker.BiConsumerWithExceptions<T,U,E> _biConsumer)Wraps biconsumer lambda returning the same one but returning null when exception and silencing the exception Example:.forEach(silencedBiConsumer((name,value) -> System.out.println(Class.forName(name)+value)));static <T,E extends Exception>
Consumer<T>silencedConsumer(LambdaUnchecker.ConsumerWithExceptions<T,E> _consumer)Wraps consumer lambda returning the same one but silencing the exception Example:.forEach(silencedConsumer(name -> System.out.println(Class.forName(name))));or.forEach(silencedConsumer(ClassNameUtil::println));static <T,R,E extends Exception>
Function<T,R>silencedFunction(LambdaUnchecker.FunctionWithExceptions<T,R,E> _function)Wraps function lambda returning the same one but returning null when exception and silencing the exception Example:.map(silencedFunction(name -> Class.forName(name)))or.map(silencedFunction(Class::forName))static <T,E extends Exception>
TsilencedGet(LambdaUnchecker.SupplierWithExceptions<T,E> _supplier)Get supplier returning the supplier result or null if exception Example:silencedGet(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8")))static voidsilencedRun(LambdaUnchecker.RunnableWithExceptions _runnable)Run Runnable but silencing any exception Example:silencedGet(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8")))static RunnablesilencedRunnable(LambdaUnchecker.RunnableWithExceptions _runnable)Wraps Runnable lambda returning the same one but returning null when exception and silencing the exception Example:silencedSupplier(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8"))),static <T,E extends Exception>
Supplier<T>silencedSupplier(LambdaUnchecker.SupplierWithExceptions<T,E> _supplier)Wraps supplier lambda returning the same one but returning null when exception and silencing the exception Example:silencedSupplier(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8"))),static <T,U,E extends Exception>
voiduncheckedAccept(LambdaUnchecker.BiConsumerWithExceptions<T,U,E> _biConsumer, T _firstInput, U _secondInput)Accept consumer input but hacking the compiler to avoid compilation check.static <T,E extends Exception>
voiduncheckedAccept(LambdaUnchecker.ConsumerWithExceptions<T,E> _consumer, T _input)Accept consumer input but hacking the compiler to avoid compilation check.static <T,R,E extends Exception>
RuncheckedApply(LambdaUnchecker.FunctionWithExceptions<T,R,E> _function, T _input)Apply function returning the result but hacking the compiler to avoid compilation check.static <T,U,E extends Exception>
BiConsumer<T,U>uncheckedBiConsumer(LambdaUnchecker.BiConsumerWithExceptions<T,U,E> _biConsumer)Wraps biconsumer lambda returning the same one but hacking the compiler to avoid compilation check.static <T,E extends Exception>
Consumer<T>uncheckedConsumer(LambdaUnchecker.ConsumerWithExceptions<T,E> _consumer)Wraps consumer lambda returning the consumer but hacking the compiler to avoid compilation check.static <T,R,E extends Exception>
Function<T,R>uncheckedFunction(LambdaUnchecker.FunctionWithExceptions<T,R,E> _function)Wraps function lambda returning the same one but hacking the compiler to avoid compilation check.static <T,E extends Exception>
TuncheckedGet(LambdaUnchecker.SupplierWithExceptions<T,E> _supplier)Get supplier returning the supplier result but hacking the compiler to avoid compilation check.static voiduncheckedRun(LambdaUnchecker.RunnableWithExceptions _runnable)Run Runnable but hacking the compiler to avoid compilation check.static RunnableuncheckedRunnable(LambdaUnchecker.RunnableWithExceptions _runnable)Wraps Runnable lambda returning the same one but hacking the compiler to avoid compilation check.static <T,E extends Exception>
Supplier<T>uncheckedSupplier(LambdaUnchecker.SupplierWithExceptions<T,E> _supplier)Wraps supplier lambda returning the same one but hacking the compiler to avoid compilation check.
-
-
-
Method Detail
-
uncheckedConsumer
public static <T,E extends Exception> Consumer<T> uncheckedConsumer(LambdaUnchecker.ConsumerWithExceptions<T,E> _consumer)
Wraps consumer lambda returning the consumer but hacking the compiler to avoid compilation check. Example:.forEach(uncheckedConsumer(name -> System.out.println(Class.forName(name))));or.forEach(uncheckedConsumer(ClassNameUtil::println));- Type Parameters:
T- consumer input typeE- checked exception- Parameters:
_consumer- consumer to wrap- Returns:
- wrapped consumer that throws the exceptions produced without compilation check
- See Also:
LambdaUnchecker.ConsumerWithExceptions
-
silencedConsumer
public static <T,E extends Exception> Consumer<T> silencedConsumer(LambdaUnchecker.ConsumerWithExceptions<T,E> _consumer)
Wraps consumer lambda returning the same one but silencing the exception Example:.forEach(silencedConsumer(name -> System.out.println(Class.forName(name))));or.forEach(silencedConsumer(ClassNameUtil::println));- Type Parameters:
T- consumer input typeE- checked exception- Parameters:
_consumer- consumer to wrap- Returns:
- wrapped consumer that silence the exceptions produced without compilation check
- See Also:
LambdaUnchecker.ConsumerWithExceptions
-
uncheckedAccept
public static <T,E extends Exception> void uncheckedAccept(LambdaUnchecker.ConsumerWithExceptions<T,E> _consumer, T _input)
Accept consumer input but hacking the compiler to avoid compilation check. Example:uncheckedAccept(name -> System.out.println(Class.forName(name)),"java.util.List");- Type Parameters:
T- consumer input typeE- checked exception- Parameters:
_consumer- consumer to wrap_input- consumer input- See Also:
LambdaUnchecker.ConsumerWithExceptions
-
silencedAccept
public static <T,E extends Exception> void silencedAccept(LambdaUnchecker.ConsumerWithExceptions<T,E> _consumer, T _input)
Accept consumer input but silencing the exception Example:uncheckedAccept(name -> System.out.println(Class.forName(name)),"java.util.List");- Type Parameters:
T- consumer input typeE- checked exception- Parameters:
_consumer- consumer to wrap_input- consumer input- See Also:
LambdaUnchecker.ConsumerWithExceptions
-
uncheckedBiConsumer
public static <T,U,E extends Exception> BiConsumer<T,U> uncheckedBiConsumer(LambdaUnchecker.BiConsumerWithExceptions<T,U,E> _biConsumer)
Wraps biconsumer lambda returning the same one but hacking the compiler to avoid compilation check. Example:.forEach(uncheckedBiConsumer((name,value) -> System.out.println(Class.forName(name)+value)));- Type Parameters:
T- biconsumer first input typeU- biconsumer second input typeE- checked exception- Parameters:
_biConsumer- biconsumer to wrap- Returns:
- wrapped biconsumer that throws the exceptions produced without compilation check
- See Also:
BiConsumer,LambdaUnchecker.BiConsumerWithExceptions
-
silencedBiConsumer
public static <T,U,E extends Exception> BiConsumer<T,U> silencedBiConsumer(LambdaUnchecker.BiConsumerWithExceptions<T,U,E> _biConsumer)
Wraps biconsumer lambda returning the same one but returning null when exception and silencing the exception Example:.forEach(silencedBiConsumer((name,value) -> System.out.println(Class.forName(name)+value)));- Type Parameters:
T- biconsumer first input typeU- biconsumer second input typeE- checked exception- Parameters:
_biConsumer- biconsumer to wrap- Returns:
- wrapped biconsumer that silence the exceptions produced without compilation check
- See Also:
BiConsumer,LambdaUnchecker.BiConsumerWithExceptions
-
uncheckedAccept
public static <T,U,E extends Exception> void uncheckedAccept(LambdaUnchecker.BiConsumerWithExceptions<T,U,E> _biConsumer, T _firstInput, U _secondInput)
Accept consumer input but hacking the compiler to avoid compilation check. Example:uncheckedAccept((name,value) -> System.out.println(Class.forName(name)+value));- Type Parameters:
T- biconsumer first input typeU- biconsumer second input typeE- checked exception- Parameters:
_biConsumer- biconsumer to wrap_firstInput- biconsumer first input_secondInput- biconsumer second input- See Also:
BiConsumer,LambdaUnchecker.BiConsumerWithExceptions
-
silencedAccept
public static <T,U,E extends Exception> void silencedAccept(LambdaUnchecker.BiConsumerWithExceptions<T,U,E> _biConsumer, T _firstInput, U _secondInput)
Accept consumer input but silencing the exception Example:silencedAccept((name,value) -> System.out.println(Class.forName(name)+value));- Type Parameters:
T- biconsumer first input typeU- biconsumer second input typeE- checked exception- Parameters:
_biConsumer- biconsumer to wrap_firstInput- biconsumer first input_secondInput- biconsumer second input- See Also:
BiConsumer,LambdaUnchecker.BiConsumerWithExceptions
-
uncheckedFunction
public static <T,R,E extends Exception> Function<T,R> uncheckedFunction(LambdaUnchecker.FunctionWithExceptions<T,R,E> _function)
Wraps function lambda returning the same one but hacking the compiler to avoid compilation check. Example:.map(uncheckedFunction(name -> Class.forName(name)))or.map(uncheckedFunction(Class::forName))- Type Parameters:
T- function input typeR- function result typeE- checked exception- Parameters:
_function- biconsumer to wrap- Returns:
- wrapped function that throws the exceptions produced without compilation check
- See Also:
Function,LambdaUnchecker.FunctionWithExceptions
-
silencedFunction
public static <T,R,E extends Exception> Function<T,R> silencedFunction(LambdaUnchecker.FunctionWithExceptions<T,R,E> _function)
Wraps function lambda returning the same one but returning null when exception and silencing the exception Example:.map(silencedFunction(name -> Class.forName(name)))or.map(silencedFunction(Class::forName))- Type Parameters:
T- function input typeR- function result typeE- checked exception- Parameters:
_function- biconsumer to wrap- Returns:
- wrapped function that silence the exceptions produced without compilation check
- See Also:
Function,LambdaUnchecker.FunctionWithExceptions
-
uncheckedApply
public static <T,R,E extends Exception> R uncheckedApply(LambdaUnchecker.FunctionWithExceptions<T,R,E> _function, T _input)
Apply function returning the result but hacking the compiler to avoid compilation check. Example:uncheckedFunction(name -> Class.forName(name))oruncheckedFunction(Class::forName)- Type Parameters:
T- function input typeR- function result typeE- checked exception- Parameters:
_function- biconsumer to wrap_input- function input- Returns:
- function result
- See Also:
Function,LambdaUnchecker.FunctionWithExceptions
-
silencedApply
public static <T,R,E extends Exception> R silencedApply(LambdaUnchecker.FunctionWithExceptions<T,R,E> _function, T _input)
Apply function returning the result but returning null when exception and silencing the exception and in this case returning null Example:silencedFunction(name -> Class.forName(name))orsilencedFunction(Class::forName)- Type Parameters:
T- function input typeR- function result typeE- checked exception- Parameters:
_function- biconsumer to wrap_input- function input- Returns:
- function result or null if exception
- See Also:
Function,LambdaUnchecker.FunctionWithExceptions
-
uncheckedSupplier
public static <T,E extends Exception> Supplier<T> uncheckedSupplier(LambdaUnchecker.SupplierWithExceptions<T,E> _supplier)
Wraps supplier lambda returning the same one but hacking the compiler to avoid compilation check. Example:uncheckedSupplier(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8"))),- Type Parameters:
T- supplier resultE- checked exception- Parameters:
_supplier- supplier to wrap- Returns:
- wrapped function that throws the exceptions produced without compilation check
- See Also:
Supplier,LambdaUnchecker.SupplierWithExceptions
-
silencedSupplier
public static <T,E extends Exception> Supplier<T> silencedSupplier(LambdaUnchecker.SupplierWithExceptions<T,E> _supplier)
Wraps supplier lambda returning the same one but returning null when exception and silencing the exception Example:silencedSupplier(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8"))),- Type Parameters:
T- supplier resultE- checked exception- Parameters:
_supplier- supplier to wrap- Returns:
- wrapped function that silence the exceptions produced without compilation check
- See Also:
Supplier,LambdaUnchecker.SupplierWithExceptions
-
uncheckedGet
public static <T,E extends Exception> T uncheckedGet(LambdaUnchecker.SupplierWithExceptions<T,E> _supplier)
Get supplier returning the supplier result but hacking the compiler to avoid compilation check. Example:uncheckedGet(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8")))- Type Parameters:
T- supplier resultE- checked exception- Parameters:
_supplier- supplier to wrap- Returns:
- supplier result
- See Also:
Supplier,LambdaUnchecker.SupplierWithExceptions
-
silencedGet
public static <T,E extends Exception> T silencedGet(LambdaUnchecker.SupplierWithExceptions<T,E> _supplier)
Get supplier returning the supplier result or null if exception Example:silencedGet(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8")))- Type Parameters:
T- supplier resultE- checked exception- Parameters:
_supplier- supplier to wrap- Returns:
- supplier result or get if exception
- See Also:
Supplier,LambdaUnchecker.SupplierWithExceptions
-
uncheckedRunnable
public static Runnable uncheckedRunnable(LambdaUnchecker.RunnableWithExceptions _runnable)
Wraps Runnable lambda returning the same one but hacking the compiler to avoid compilation check. Example:uncheckedSupplier(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8"))),- Parameters:
_runnable- runnable to wrap- Returns:
- wrapped runnable that throws the exceptions produced without compilation check
- See Also:
Runnable,LambdaUnchecker.RunnableWithExceptions
-
silencedRunnable
public static Runnable silencedRunnable(LambdaUnchecker.RunnableWithExceptions _runnable)
Wraps Runnable lambda returning the same one but returning null when exception and silencing the exception Example:silencedSupplier(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8"))),- Parameters:
_runnable- runnable to wrap- Returns:
- wrapped runnable that silence the exceptions produced without compilation check
- See Also:
Runnable,LambdaUnchecker.RunnableWithExceptions
-
uncheckedRun
public static void uncheckedRun(LambdaUnchecker.RunnableWithExceptions _runnable)
Run Runnable but hacking the compiler to avoid compilation check. Example:uncheckedGet(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8")))- Parameters:
_runnable- runnable to wrap- See Also:
Supplier,LambdaUnchecker.SupplierWithExceptions
-
silencedRun
public static void silencedRun(LambdaUnchecker.RunnableWithExceptions _runnable)
Run Runnable but silencing any exception Example:silencedGet(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8")))- Parameters:
_runnable- runnable to wrap- See Also:
Supplier,LambdaUnchecker.SupplierWithExceptions
-
-