Class LambdaExceptionUtils

java.lang.Object
org.wso2.carbon.utils.LambdaExceptionUtils

public final class LambdaExceptionUtils extends Object
A Utility which provides a way to throw checked exceptions from the lambda expressions.
  • 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 function
      E - the type of Exception
      Parameters:
      consumer - instances of the ConsumerWithExceptions functional interface
      Returns:
      an instance of the Consumer
    • rethrowBiConsumer

      public static <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.
      Type Parameters:
      T - the type of the input to the function
      U - the type of the input to the function
      E - the type of Exception
      Parameters:
      biConsumer - instances of the BiConsumerWithExceptions functional interface
      Returns:
      an instance of the BiConsumer
    • rethrowFunction

      public static <T, R, E extends Exception> Function<T,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 Object
      E - 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.