Class CloseSilentlyFunction<VIN extends Closeable,VOUT,E extends Exception>

java.lang.Object
org.forgerock.util.CloseSilentlyFunction<VIN,VOUT,E>
Type Parameters:
VIN - The type of the function input-parameter, which implements Closeable.
VOUT - The type of the function result, or Void if the function does not return anything (i.e. it only has side-effects).
E - The type of the exception thrown by the function, or NeverThrowsException if no exception is thrown by the function.
All Implemented Interfaces:
Function<VIN,VOUT,E>

public class CloseSilentlyFunction<VIN extends Closeable,VOUT,E extends Exception> extends Object implements Function<VIN,VOUT,E>
Function that silently closes an input-parameter after a delegate-function's Function.apply(Object) is invoked. The static closeSilently(Function) method is provided for convenience.
  • Constructor Details

    • CloseSilentlyFunction

      public CloseSilentlyFunction(Function<VIN,VOUT,E> delegate)
      Creates a new CloseSilentlyFunction instance.
      Parameters:
      delegate - Delegate function.
  • Method Details

    • apply

      public VOUT apply(VIN value) throws E
      Invokes the delegate function's Function.apply(Object) with the input parameter value, closes it, and returns the result.
      Specified by:
      apply in interface Function<VIN extends Closeable,VOUT,E extends Exception>
      Parameters:
      value - Closeable input parameter.
      Returns:
      The result of applying delegate function to value.
      Throws:
      E - Propagates Exception thrown by delegate Function.
    • closeSilently

      public static <IN extends Closeable, OUT, EX extends Exception> Function<IN,OUT,EX> closeSilently(Function<IN,OUT,EX> delegate)
      Wraps a delegate function in a CloseSilentlyFunction.
      Type Parameters:
      IN - The type of the function input-parameter, which implements Closeable.
      OUT - The type of the function result, or Void if the function does not return anything (i.e. it only has side-effects).
      EX - The type of the exception thrown by the function, or NeverThrowsException if no exception is thrown by the function.
      Parameters:
      delegate - Delegate function.
      Returns:
      New CloseSilentlyFunction instance.