Package com.noleme.vault.reflect
Class LenientClassUtils
- java.lang.Object
-
- com.noleme.vault.reflect.LenientClassUtils
-
public final class LenientClassUtils extends Object
- Author:
- Pierre LECERF ([email protected]) Created on 27/04/2021
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
attemptTypeConversion(String value, Class<T> type)
static com.noleme.commons.container.Pair<Constructor<?>,Object[]>
getLenientConstructor(Class<?> type, Class<?>[] parameterTypes, Object[] parameters)
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.static com.noleme.commons.container.Pair<Method,Object[]>
getLenientMethod(Class<?> type, String methodName, Class<?>[] parameterTypes, Object[] parameters)
Attempts to find a method for the provided class matching with the provided parameter types.static boolean
isConversionTarget(Class<?> type)
-
-
-
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 lookupparameterTypes
- the types of arguments expected for the constructor signatureparameters
- 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 lookupmethodName
- the name of the methodparameterTypes
- the types of the arguments expected for the method signatureparameters
- 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:
-
-