Interface ThrowingBiFunction<T,U,R>

Type Parameters:
T - the type of the first argument to the function
U - the type of the second argument to the function
R - the type of the result of the function
All Superinterfaces:
BiFunction<T,U,R>

public interface ThrowingBiFunction<T,U,R> extends BiFunction<T,U,R>
A BiFunction that allows invocation of code that throws a checked exception.
Since:
6.0
Author:
Stephane Nicoll, Phillip Webb
  • Method Details

    • applyWithException

      R applyWithException(T t, U u) throws Exception
      Applies this function to the given argument, possibly throwing a checked exception.
      Parameters:
      t - the first function argument
      u - the second function argument
      Returns:
      the function result
      Throws:
      Exception - on error
    • apply

      default R apply(T t, U u)
      Default BiFunction.apply(Object, Object) that wraps any thrown checked exceptions (by default in a RuntimeException).
      Specified by:
      apply in interface BiFunction<T,U,R>
      Parameters:
      t - the first function argument
      u - the second function argument
      Returns:
      the function result
      See Also:
    • apply

      default R apply(T t, U u, BiFunction<String,Exception,RuntimeException> exceptionWrapper)
      Applies this function to the given argument, wrapping any thrown checked exceptions using the given exceptionWrapper.
      Parameters:
      t - the first function argument
      u - the second function argument
      exceptionWrapper - BiFunction that wraps the given message and checked exception into a runtime exception
      Returns:
      a result
    • throwing

      default ThrowingBiFunction<T,U,R> throwing(BiFunction<String,Exception,RuntimeException> exceptionWrapper)
      Return a new ThrowingBiFunction where the apply(Object, Object) method wraps any thrown checked exceptions using the given exceptionWrapper.
      Parameters:
      exceptionWrapper - BiFunction that wraps the given message and checked exception into a runtime exception
      Returns:
      the replacement ThrowingBiFunction instance
    • of

      static <T, U, R> ThrowingBiFunction<T,U,R> of(ThrowingBiFunction<T,U,R> function)
      Lambda friendly convenience method that can be used to create a ThrowingBiFunction where the apply(Object, Object) method wraps any checked exception thrown by the supplied lambda expression or method reference.

      This method can be especially useful when working with method references. It allows you to easily convert a method that throws a checked exception into an instance compatible with a regular BiFunction.

      For example:

       map.replaceAll(ThrowingBiFunction.of(Example::methodThatCanThrowCheckedException));
       
      Type Parameters:
      T - the type of the first argument to the function
      U - the type of the second argument to the function
      R - the type of the result of the function
      Parameters:
      function - the source function
      Returns:
      a new ThrowingFunction instance
    • of

      static <T, U, R> ThrowingBiFunction<T,U,R> of(ThrowingBiFunction<T,U,R> function, BiFunction<String,Exception,RuntimeException> exceptionWrapper)
      Lambda friendly convenience method that can be used to create a ThrowingBiFunction where the apply(Object, Object) method wraps any thrown checked exceptions using the given exceptionWrapper.

      This method can be especially useful when working with method references. It allows you to easily convert a method that throws a checked exception into an instance compatible with a regular BiFunction.

      For example:

       map.replaceAll(ThrowingBiFunction.of(Example::methodThatCanThrowCheckedException, IllegalStateException::new));
       
      Type Parameters:
      T - the type of the first argument to the function
      U - the type of the second argument to the function
      R - the type of the result of the function
      Parameters:
      function - the source function
      exceptionWrapper - the exception wrapper to use
      Returns:
      a new ThrowingFunction instance