Class AlgorithmBuilderUtil
java.lang.Object
es.urjc.etsii.grafo.autoconfig.builder.AlgorithmBuilderUtil
Magic (based on reflection) util methods to create instances of algorithm components at runtime
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Build algorithm component given a set of parametersstatic void
checkLoss
(double value, double reference) static <T> Constructor
<T> findAutoconfigConstructor
(Class<T> clazz) Analyze an algorithm component class to find which constructor is annotated with @AutoconfigConstructorstatic <T> Constructor
<T> findConstructor
(Class<T> clazz, Map<String, Class<?>> mandatoryParams, List<ParameterProvider> optionalParams) Find a constructor method in the target class that accepts the given combination of parameter (name, type) in any order.static Object
getProvidedValue
(Class<?> pType, String pName, List<ParameterProvider> paramProviders) static Object
getProvidedValue
(Parameter p, List<ParameterProvider> paramProviders) static boolean
isAssignable
(Class<?> origin, Class<?> target) static Object
prepareNumericParameterValue
(Number value, Class<?> target) static Object
prepareParameterValue
(Object value, Class<?> target)
-
Method Details
-
build
public static Object build(Class<?> clazz, Map<String, Object> args, List<ParameterProvider> paramProviders) Build algorithm component given a set of parameters- Parameters:
clazz
- Algorithm component classargs
- arguments for the constructor- Returns:
- instance if class built with the given params
-
getProvidedValue
-
getProvidedValue
public static Object getProvidedValue(Class<?> pType, String pName, List<ParameterProvider> paramProviders) -
findConstructor
public static <T> Constructor<T> findConstructor(Class<T> clazz, Map<String, Class<?>> mandatoryParams, List<ParameterProvider> optionalParams) Find a constructor method in the target class that accepts the given combination of parameter (name, type) in any order. Autoboxing and widening are allowed, example from int to double, or int to Integer.- Type Parameters:
T
- Constructor for class T- Parameters:
clazz
- target classmandatoryParams
- argument map of all parameters that must be usedoptionalParams
- argument map of all parameters that might be used if necessary- Returns:
- Constructor if found one that matches the given parameters, null if no constructor matches
-
findAutoconfigConstructor
Analyze an algorithm component class to find which constructor is annotated with @AutoconfigConstructor- Parameters:
clazz
- Algorithm component to analyze- Returns:
- constructor annotated with @AutoconfigConstructor if present, null otherwise
-
isAssignable
-
prepareParameterValue
-
prepareNumericParameterValue
-
checkLoss
public static void checkLoss(double value, double reference)
-