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 ObjectBuild algorithm component given a set of parametersstatic voidcheckLoss(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 ObjectgetProvidedValue(Class<?> pType, String pName, List<ParameterProvider> paramProviders) static ObjectgetProvidedValue(Parameter p, List<ParameterProvider> paramProviders) static booleanisAssignable(Class<?> origin, Class<?> target) static ObjectprepareNumericParameterValue(Number value, Class<?> target) static ObjectprepareParameterValue(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)
-