Class LenientClassUtils

    • Method Detail

      • getLenientConstructor

        public static com.noleme.commons.container.Pair<Constructor<?>,​Object[]> getLenientConstructor​(Class<?> type,
                                                                                                             Class<?>[] parameterTypes,
                                                                                                             Object[] parameters)
                                                                                                      throws NoSuchMethodException
        Attempts to find a constructor for the provided class matching with the provided parameter types, if the search fails, it will attempt to make type conversions from String arguments.
        Parameters:
        type - the type of the class on which to perform the lookup
        parameterTypes - the types of arguments expected for the constructor signature
        parameters - the original expected arguments for the constructor
        Returns:
        a matching Constructor instance paired with a functional set of arguments (with possible type re-interpretations)
        Throws:
        NoSuchMethodException - thrown if no matching constructor could be found and/or type conversions failed
      • getLenientMethod

        public static com.noleme.commons.container.Pair<Method,​Object[]> getLenientMethod​(Class<?> type,
                                                                                                String methodName,
                                                                                                Class<?>[] parameterTypes,
                                                                                                Object[] parameters)
                                                                                         throws NoSuchMethodException
        Attempts to find a method for the provided class matching with the provided parameter types.
        Parameters:
        type - the type of the class on which to perform the lookup
        methodName - the name of the method
        parameterTypes - the types of the arguments expected for the method signature
        parameters - the original expected arguments for the method
        Returns:
        a matching Method instance paired with a functional set of arguments (with possible type re-interpretations)
        Throws:
        NoSuchMethodException - thrown if no matching method could be found and/or type conversions failed
      • attemptTypeConversion

        public static <T> T attemptTypeConversion​(String value,
                                                  Class<T> type)
        Type Parameters:
        T -
        Parameters:
        value -
        type -
        Returns:
      • isConversionTarget

        public static boolean isConversionTarget​(Class<?> type)
        Parameters:
        type -
        Returns: