Class Utilities


  • public class Utilities
    extends java.lang.Object
    Author:
    Collin Alpert
    • Constructor Summary

      Constructors 
      Constructor Description
      Utilities()  
    • Method Summary

      Modifier and Type Method Description
      static java.lang.Runnable runnableHandling​(ThrowableRunnable<java.sql.SQLException> runnable, java.util.function.Consumer<java.sql.SQLException> exceptionHandling)
      Handles an SQLException that gets thrown inside a Runnable.
      static <V> java.util.function.Supplier<V> supplierHandling​(ThrowableSupplier<V,​java.sql.SQLException> supplier, java.util.function.Consumer<java.sql.SQLException> exceptionHandling)
      Handles an SQLException that gets thrown inside a Supplier.
      static <E extends java.lang.Throwable>
      void
      tryAction​(ThrowableRunnable<E> runnable)
      Tries to perform a certain action while considering a checked exception that could occur.
      static <T,​E extends java.lang.Throwable>
      T
      tryGetValue​(ThrowableSupplier<T,​E> supplier)
      Tries to execute a supplier and retrieve its value while considering a checked exception that could occur.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Utilities

        public Utilities()
    • Method Detail

      • supplierHandling

        public static <V> java.util.function.Supplier<V> supplierHandling​(ThrowableSupplier<V,​java.sql.SQLException> supplier,
                                                                          java.util.function.Consumer<java.sql.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 java.lang.Runnable runnableHandling​(ThrowableRunnable<java.sql.SQLException> runnable,
                                                          java.util.function.Consumer<java.sql.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 java.lang.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 java.lang.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.