/** * Unwrap to find the outermost function that is an instance of {@code clazz}. * @param <C> Type of class. * @param clazz Implementation class to search for. * @return outermost function that is an instance of {@code clazz}, * {@code null} if {@code clazz} is not implemented by {@code this} * or any function it wraps. * * @see WrappedFunction#unwrap(Class, Object) */ public <C> C unwrap(Class<C> clazz) { return unwrap(clazz, this); }
/** * Unwrap to find the outermost function that is an instance of {@code clazz}. * @param <C> Type of class. * @param clazz Implementation class to search for. * @return outermost function that is an instance of {@code clazz}, * {@code null} if {@code clazz} is not implemented by {@code this} * or any function it wraps. * * @see WrappedFunction#unwrap(Class, Object) */ public <C> C unwrap(Class<C> clazz) { return unwrap(clazz, this); }
/** * Close the function. * If {@code function} is an instance of {@code AutoCloseable} * then close is called, otherwise no action is taken. * @param function Function to be closed. * @throws Exception Error throwing function. */ public static void closeFunction(Object function) throws Exception { AutoCloseable closeable = WrappedFunction.unwrap(AutoCloseable.class, function); if (closeable != null) closeable.close(); }
/** * Close the function. * If {@code function} is an instance of {@code AutoCloseable} * then close is called, otherwise no action is taken. * @param function Function to be closed. * @throws Exception Error throwing function. */ public static void closeFunction(Object function) throws Exception { AutoCloseable closeable = WrappedFunction.unwrap(AutoCloseable.class, function); if (closeable != null) closeable.close(); }