Class Utilities


  • public class Utilities
    extends Object
    Author:
    Collin Alpert
    • Constructor Detail

      • Utilities

        public Utilities()
    • Method Detail

      • supplierHandling

        public static <V> Supplier<V> supplierHandling​(ThrowableSupplier<V,​SQLException> supplier,
                                                       Consumer<SQLException> exceptionHandling)
        Handles an SQLException that gets thrown inside a Supplier.
        Type Parameters:
        V - The return type of the operation.
        Parameters:
        supplier - The Supplier that throws the exception.
        exceptionHandling - The exception handling supplied for this exception.
        Returns:
        The original Supplier but now with the added exception handling.
      • runnableHandling

        public static Runnable runnableHandling​(ThrowableRunnable<SQLException> runnable,
                                                Consumer<SQLException> exceptionHandling)
        Handles an SQLException that gets thrown inside a Runnable.
        Parameters:
        runnable - The Runnable that throws the exception.
        exceptionHandling - The exception handling supplied for this exception.
        Returns:
        The original Runnable but now with the added exception handling.
      • tryAction

        public static <E extends Throwable> void tryAction​(ThrowableRunnable<E> runnable)
        Tries to perform a certain action while considering a checked exception that could occur.
        Type Parameters:
        E - The type of checked exception.
        Parameters:
        runnable - The Runnable to try to execute.
      • tryGetValue

        public static <T,​E extends Throwable> T tryGetValue​(ThrowableSupplier<T,​E> supplier)
        Tries to execute a supplier and retrieve its value while considering a checked exception that could occur.
        Type Parameters:
        T - The type of value to return.
        E - The type of checked exception.
        Parameters:
        supplier - The Supplier to try to execute.
        Returns:
        The value returned by the supplier, assuming it can be excecuted without throwing an exception.