Package org.wso2.carbon.utils
Class LambdaExceptionUtils
java.lang.Object
org.wso2.carbon.utils.LambdaExceptionUtils
A Utility which provides a way to throw checked exceptions from the lambda expressions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents aBiConsumerinterface which can throw exceptions.static interfaceRepresents aConsumerinterface which can throw exceptions.static interfaceRepresents aFunctioninterface which can throw exceptions.static interfaceRepresents aRunnableinterface which can throw exceptions.static interfaceRepresents aSupplierinterface which can throw exceptions. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,U, E extends Exception>
BiConsumer<T, U> rethrowBiConsumer(LambdaExceptionUtils.BiConsumerWithExceptions<T, U, E> biConsumer) This method allows a BiConsumer which throws exceptions to be used in places which expects a BiConsumer.rethrowConsumer(LambdaExceptionUtils.ConsumerWithExceptions<T, E> consumer) This method allows a Consumer which throws exceptions to be used in places which expects a Consumer.rethrowFunction(LambdaExceptionUtils.FunctionWithExceptions<T, R, E> function) This method allows a Function which throws exceptions to be used in places which expects a Function.rethrowSupplier(LambdaExceptionUtils.SupplierWithExceptions<T, E> function) This method allows a Supplier which throws exceptions to be used in places which expects a Supplier.
-
Constructor Details
-
LambdaExceptionUtils
public LambdaExceptionUtils()
-
-
Method Details
-
rethrowConsumer
public static <T,E extends Exception> Consumer<T> rethrowConsumer(LambdaExceptionUtils.ConsumerWithExceptions<T, E> consumer) This method allows a Consumer which throws exceptions to be used in places which expects a Consumer.- Type Parameters:
T- the type of the input to the functionE- the type of Exception- Parameters:
consumer- instances of theConsumerWithExceptionsfunctional interface- Returns:
- an instance of the
Consumer
-
rethrowBiConsumer
public static <T,U, BiConsumer<T,E extends Exception> U> rethrowBiConsumer(LambdaExceptionUtils.BiConsumerWithExceptions<T, U, E> biConsumer) This method allows a BiConsumer which throws exceptions to be used in places which expects a BiConsumer.- Type Parameters:
T- the type of the input to the functionU- the type of the input to the functionE- the type of Exception- Parameters:
biConsumer- instances of theBiConsumerWithExceptionsfunctional interface- Returns:
- an instance of the
BiConsumer
-
rethrowFunction
public static <T,R, Function<T,E extends Exception> R> rethrowFunction(LambdaExceptionUtils.FunctionWithExceptions<T, R, E> function) This method allows a Function which throws exceptions to be used in places which expects a Function.- Type Parameters:
T- Any Object.R- Any ObjectE- Any Exception.- Parameters:
function- Function to apply for given arguments.- Returns:
- Any Object that result from the function passed.
-
rethrowSupplier
public static <T,E extends Exception> Supplier<T> rethrowSupplier(LambdaExceptionUtils.SupplierWithExceptions<T, E> function) This method allows a Supplier which throws exceptions to be used in places which expects a Supplier.- Type Parameters:
T- Any Object.E- Any Exception.- Parameters:
function- Function to apply for given arguments.- Returns:
- Supplier of the results.
-