Class Utilities
- java.lang.Object
-
- com.github.collinalpert.java2db.utilities.Utilities
-
public class Utilities extends Object
- Author:
- Collin Alpert
-
-
Constructor Summary
Constructors Constructor Description Utilities()
-
Method Summary
Modifier and Type Method Description static RunnablerunnableHandling(ThrowableRunnable<SQLException> runnable, Consumer<SQLException> exceptionHandling)Handles anSQLExceptionthat gets thrown inside aRunnable.static <V> Supplier<V>supplierHandling(ThrowableSupplier<V,SQLException> supplier, Consumer<SQLException> exceptionHandling)Handles anSQLExceptionthat gets thrown inside aSupplier.static <E extends Throwable>
voidtryAction(ThrowableRunnable<E> runnable)Tries to perform a certain action while considering a checked exception that could occur.static <T,E extends Throwable>
TtryGetValue(ThrowableSupplier<T,E> supplier)Tries to execute a supplier and retrieve its value while considering a checked exception that could occur.
-
-
-
Method Detail
-
supplierHandling
public static <V> Supplier<V> supplierHandling(ThrowableSupplier<V,SQLException> supplier, Consumer<SQLException> exceptionHandling)
Handles anSQLExceptionthat gets thrown inside aSupplier.- Type Parameters:
V- The return type of the operation.- Parameters:
supplier- TheSupplierthat throws the exception.exceptionHandling- The exception handling supplied for this exception.- Returns:
- The original
Supplierbut now with the added exception handling.
-
runnableHandling
public static Runnable runnableHandling(ThrowableRunnable<SQLException> runnable, Consumer<SQLException> exceptionHandling)
Handles anSQLExceptionthat gets thrown inside aRunnable.- Parameters:
runnable- TheRunnablethat throws the exception.exceptionHandling- The exception handling supplied for this exception.- Returns:
- The original
Runnablebut 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- TheRunnableto 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- TheSupplierto try to execute.- Returns:
- The value returned by the supplier, assuming it can be excecuted without throwing an exception.
-
-