Class JdbiClassUtils


  • public final class JdbiClassUtils
    extends java.lang.Object
    Helper 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
      private JdbiClassUtils()  
    • 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 a CheckedCallable instance if possible.
      static boolean isPresent​(java.lang.String klass)
      Returns true if a specific class can be loaded.
      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.
      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.
      • Methods inherited from class java.lang.Object

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

      • NO_ARGS

        private static final java.lang.Object[] NO_ARGS
    • Constructor Detail

      • JdbiClassUtils

        private JdbiClassUtils()
    • 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 tries Class.getMethod(String, Class[]) first, then falls back to Class.getDeclaredMethod(String, Class[]).
        Parameters:
        klass - A class
        methodName - A method name
        parameterTypes - All parameter types for the method
        Returns:
        A Method object
        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 tries Class.getMethod(String, Class[]) first, then falls back to Class.getDeclaredMethod(String, Class[]).
        Parameters:
        klass - A class
        methodName - A method name
        parameterTypes - All parameter types for the method
        Returns:
        A Method object wrapped in an Optional if 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 a CheckedCallable instance if possible.
        Type Parameters:
        T - The type of the new instance
        Parameters:
        creator - A CheckedCallable instance which returns a new instance or throws any of the exceptions out of Class.getConstructor(Class[]) or Constructor.newInstance(Object...)
        Returns:
        A new instance wrapped in an Optional or Optional.empty() if a ReflectiveOperationException or SecurityException occured
      • 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 Stream of Class objects
      • 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