Class AlgorithmBuilderUtil

java.lang.Object
es.urjc.etsii.grafo.autoconfig.builder.AlgorithmBuilderUtil

public class AlgorithmBuilderUtil extends Object
Magic (based on reflection) util methods to create instances of algorithm components at runtime
  • 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 class
      args - arguments for the constructor
      Returns:
      instance if class built with the given params
    • getProvidedValue

      public static Object getProvidedValue(Parameter p, List<ParameterProvider> paramProviders)
    • 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 class
      mandatoryParams - argument map of all parameters that must be used
      optionalParams - 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

      public static <T> Constructor<T> findAutoconfigConstructor(Class<T> clazz)
      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

      public static boolean isAssignable(Class<?> origin, Class<?> target)
    • prepareParameterValue

      public static Object prepareParameterValue(Object value, Class<?> target)
    • prepareNumericParameterValue

      public static Object prepareNumericParameterValue(Number value, Class<?> target)
    • checkLoss

      public static void checkLoss(double value, double reference)