Class AbstractCloser<S,​E extends Exception>

    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractCloser()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> S push​(ClosingOperator<T,​? extends E> operator, T objectToClose)
      If the given objectToClose is non-null, execute the given close operator immediately on objectToClose, swallowing any throwable in order to add it as suppressed to a previously caught throwable, or to re-throw it later.
      <T,​U>
      S
      push​(ClosingOperator<T,​? extends E> operator, U objectToExtractFrom, Function<U,​T> extract)
      If the given objectToExtractFrom is non-null, and an object can be extracted from it using extract, execute the given close operator immediately on the object to close, swallowing any throwable in order to add it as suppressed to a previously caught throwable, or to re-throw it later.
      <T,​U>
      S
      pushAll​(ClosingOperator<T,​? extends E> operator, Iterable<? extends U> objectsToExtractFrom, Function<U,​T> extract)
      Execute the given close operator immediately on an object extracted from each element of the given iterable, swallowing any throwable in order to add it as suppressed to a previously caught throwable, or to re-throw it later.
      <T> S pushAll​(ClosingOperator<T,​? extends E> operator, Iterable<T> objectsToClose)
      Execute the given close operator immediately on each element of the given iterable, swallowing any throwable in order to add it as suppressed to a previously caught throwable, or to re-throw it later.
      <T> S pushAll​(ClosingOperator<T,​? extends E> operator, T... objectsToClose)
      Execute the given close operator immediately on each element of the given array, swallowing any throwable in order to add it as suppressed to a previously caught throwable, or to re-throw it later.
    • Constructor Detail

      • AbstractCloser

        public AbstractCloser()
    • Method Detail

      • push

        public <T> S push​(ClosingOperator<T,​? extends E> operator,
                          T objectToClose)
        If the given objectToClose is non-null, execute the given close operator immediately on objectToClose, swallowing any throwable in order to add it as suppressed to a previously caught throwable, or to re-throw it later.
        Parameters:
        operator - An operator to close objectToClose. Accepts lambdas such as MyType::close.
        objectToClose - An object to close.
        Returns:
        this, for method chaining.
      • push

        public <T,​U> S push​(ClosingOperator<T,​? extends E> operator,
                                  U objectToExtractFrom,
                                  Function<U,​T> extract)
        If the given objectToExtractFrom is non-null, and an object can be extracted from it using extract, execute the given close operator immediately on the object to close, swallowing any throwable in order to add it as suppressed to a previously caught throwable, or to re-throw it later.
        Parameters:
        operator - An operator to close objectToClose. Accepts lambdas such as MyType::close.
        objectToExtractFrom - An object from which to extract the object to close.
        extract - A function to extract an object to close from objectToExtractFrom. Accepts lambdas such as MyType::get.
        Returns:
        this, for method chaining.
      • pushAll

        public <T> S pushAll​(ClosingOperator<T,​? extends E> operator,
                             Iterable<T> objectsToClose)
        Execute the given close operator immediately on each element of the given iterable, swallowing any throwable in order to add it as suppressed to a previously caught throwable, or to re-throw it later.
        Parameters:
        operator - An operator to close each element in objectsToClose. Accepts lambdas such as MyType::close.
        objectsToClose - An iterable of objects to close.
        Returns:
        this, for method chaining.
      • pushAll

        public <T,​U> S pushAll​(ClosingOperator<T,​? extends E> operator,
                                     Iterable<? extends U> objectsToExtractFrom,
                                     Function<U,​T> extract)
        Execute the given close operator immediately on an object extracted from each element of the given iterable, swallowing any throwable in order to add it as suppressed to a previously caught throwable, or to re-throw it later.
        Parameters:
        operator - An operator to close each element in objectsToClose. Accepts lambdas such as MyType::close.
        objectsToExtractFrom - An iterable of objects from which to extract the objects to close.
        extract - A function to extract an object to close from the elements of objectsToExtractFrom. Accepts lambdas such as MyType::get.
        Returns:
        this, for method chaining.
      • pushAll

        @SafeVarargs
        public final <T> S pushAll​(ClosingOperator<T,​? extends E> operator,
                                   T... objectsToClose)
        Execute the given close operator immediately on each element of the given array, swallowing any throwable in order to add it as suppressed to a previously caught throwable, or to re-throw it later.
        Parameters:
        operator - An operator to close each element in objectsToClose. Accepts lambdas such as MyType::close.
        objectsToClose - An array of objects to close.
        Returns:
        this, for method chaining.