Package org.jdbi.v3.core.internal
Class JdbiClassUtils
- java.lang.Object
-
- org.jdbi.v3.core.internal.JdbiClassUtils
-
public final class JdbiClassUtils extends java.lang.ObjectHelper class for various internal reflection operations.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Object[]NO_ARGS
-
Constructor Summary
Constructors Modifier Constructor Description privateJdbiClassUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.Optional<T>createInstanceIfPossible(CheckedCallable<T> creator)Creates a new instance from aCheckedCallableinstance if possible.static booleanisPresent(java.lang.String klass)Returns true if a specific class can be loaded.static java.lang.reflect.MethodmethodLookup(java.lang.Class<?> klass, java.lang.String methodName, java.lang.Class<?>... parameterTypes)Lookup a specific method name related to a class.static java.util.Optional<java.lang.reflect.Method>safeMethodLookup(java.lang.Class<?> klass, java.lang.String methodName, java.lang.Class<?>... parameterTypes)Lookup a specific method name related to a class.static java.lang.Object[]safeVarargs(java.lang.Object... args)Safely move arguments passed from from a varargs call to a call that expects an array of objects.static java.util.stream.Stream<java.lang.Class<?>>superTypes(java.lang.Class<?> type)Returns all supertypes to a given type.
-
-
-
Method Detail
-
isPresent
public static boolean isPresent(java.lang.String klass)
Returns true if a specific class can be loaded.- Parameters:
klass- The class- Returns:
- True if it can be loaded, false otherwise
-
methodLookup
public static java.lang.reflect.Method methodLookup(java.lang.Class<?> klass, java.lang.String methodName, java.lang.Class<?>... parameterTypes)Lookup a specific method name related to a class. This helper triesClass.getMethod(String, Class[])first, then falls back toClass.getDeclaredMethod(String, Class[]).- Parameters:
klass- A classmethodName- A method nameparameterTypes- All parameter types for the method- Returns:
- A
Methodobject - Throws:
java.lang.IllegalStateException- If the method could not be found
-
safeMethodLookup
public static java.util.Optional<java.lang.reflect.Method> safeMethodLookup(java.lang.Class<?> klass, java.lang.String methodName, java.lang.Class<?>... parameterTypes)Lookup a specific method name related to a class. This helper triesClass.getMethod(String, Class[])first, then falls back toClass.getDeclaredMethod(String, Class[]).- Parameters:
klass- A classmethodName- A method nameparameterTypes- All parameter types for the method- Returns:
- A
Methodobject wrapped in anOptionalif the method could be found,Optional.empty()otherwise
-
createInstanceIfPossible
public static <T> java.util.Optional<T> createInstanceIfPossible(CheckedCallable<T> creator)
Creates a new instance from aCheckedCallableinstance if possible.- Type Parameters:
T- The type of the new instance- Parameters:
creator- ACheckedCallableinstance which returns a new instance or throws any of the exceptions out ofClass.getConstructor(Class[])orConstructor.newInstance(Object...)- Returns:
- A new instance wrapped in an
OptionalorOptional.empty()if aReflectiveOperationExceptionorSecurityExceptionoccured
-
superTypes
public static java.util.stream.Stream<java.lang.Class<?>> superTypes(java.lang.Class<?> type)
Returns all supertypes to a given type.- Parameters:
type- A type- Returns:
- A
StreamofClassobjects
-
safeVarargs
public static java.lang.Object[] safeVarargs(java.lang.Object... args)
Safely move arguments passed from from a varargs call to a call that expects an array of objects.- Parameters:
args- A list of objects. May be null or empty- Returns:
- Returns an Array of objects. If the input was null, returns an empty array, otherwise all arguments as an array
-
-