Class LambdaUtil


  • public final class LambdaUtil
    extends Object
    This class offers utility functions for Java's lambda features.
    • Method Detail

      • applyToAllWhileSuppressingExceptions

        public static <T> void applyToAllWhileSuppressingExceptions​(Iterable<T> inputs,
                                                                    ThrowingConsumer<T,​? extends Exception> throwingConsumer)
                                                             throws Exception
        This method supplies all elements from the input to the consumer. Exceptions that happen on elements are suppressed until all elements are processed. If exceptions happened for one or more of the inputs, they are reported in a combining suppressed exception.
        Type Parameters:
        T - the type of input.
        Parameters:
        inputs - iterator for all inputs to the throwingConsumer.
        throwingConsumer - this consumer will be called for all elements delivered by the input iterator.
        Throws:
        Exception - collected exceptions that happened during the invocation of the consumer on the input elements.
      • withContextClassLoader

        public static <E extends Throwable> void withContextClassLoader​(ClassLoader cl,
                                                                        ThrowingRunnable<E> r)
                                                                 throws E extends Throwable
        Runs the given runnable with the given ClassLoader as the thread's context class loader.

        The method will make sure to set the context class loader of the calling thread back to what it was before after the runnable completed.

        Throws:
        E extends Throwable
      • withContextClassLoader

        public static <R,​E extends Throwable> R withContextClassLoader​(ClassLoader cl,
                                                                             SupplierWithException<R,​E> s)
                                                                      throws E extends Throwable
        Runs the given runnable with the given ClassLoader as the thread's context class loader.

        The method will make sure to set the context class loader of the calling thread back to what it was before after the runnable completed.

        Throws:
        E extends Throwable