Class Utilities
java.lang.Object
com.github.collinalpert.java2db.utilities.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.RunnablerunnableHandling(ThrowableRunnable<java.sql.SQLException> runnable, java.util.function.Consumer<java.sql.SQLException> exceptionHandling)Handles anSQLExceptionthat gets thrown inside aRunnable.static <V> java.util.function.Supplier<V>supplierHandling(ThrowableSupplier<V,java.sql.SQLException> supplier, java.util.function.Consumer<java.sql.SQLException> exceptionHandling)Handles anSQLExceptionthat gets thrown inside aSupplier.static <E extends java.lang.Throwable>
voidtryAction(ThrowableRunnable<E> runnable)Tries to perform a certain action while considering a checked exception that could occur.static <T, E extends java.lang.Throwable>
TtryGetValue(ThrowableSupplier<T,E> supplier)Tries to execute a supplier and retrieve its value while considering a checked exception that could occur.
-
Constructor Details
-
Utilities
public Utilities()
-
-
Method Details
-
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 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 java.lang.Runnable runnableHandling(ThrowableRunnable<java.sql.SQLException> runnable, java.util.function.Consumer<java.sql.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
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
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.
-