Class Parameter

java.lang.Object
nz.org.riskscape.engine.bind.Parameter

public class Parameter extends Object

Parameters are the inputs and toggles that ultimately control how Riskscape works. They are used by the data and modelling constructs to allow users to customize and inspect how riskscape works.

Care has been taken to make this API usable from jvm languages other than Java, and so does not rely on language features such as annotations for their definition (although those are available as an add on convenience for java programmers)

  • Field Details

  • Constructor Details

    • Parameter

      public Parameter(@NonNull @NonNull String name, @NonNull @NonNull Class<?> type, @NonNull @NonNull Optional<BiFunction<BindingContext,Parameter,List<?>>> function, int min, int max)
      Parameters:
      name - The name that identifies this parameter among others on the model
      type - The java type of this parameter.
      function - a function that can return a default value for this parameter
  • Method Details

    • required

      public static <T> Parameter required(String name, Class<T> type)
    • required

      public static <T> Parameter required(String name, Class<T> type, T constantDefault)
    • range

      public static <T> Parameter range(String name, Class<T> type, int min, int max)

      Constructs a Parameter with a specific min and max number of parameters and no defaults

    • optional

      public static Parameter optional(String name, Class<?> type)
    • optional

      public static Parameter optional(String name, Class<?> type, int max)
    • clone

      protected Parameter clone(Consumer<Parameter.MutableFields> mutator)
    • getDefaultValues

      public List<?> getDefaultValues(BindingContext modelContext) throws ParameterBindingException
      Throws:
      ParameterBindingException
    • isOptional

      public boolean isOptional()
      Returns:
      true if a value is not required for this parameter, e.g. the model should be able to run without it
    • isMany

      public boolean isMany()
      Returns:
      true if this parameter supports more than one value, e.g. a list or a set.
    • hasDefaultValue

      public boolean hasDefaultValue()
      Returns:
      true if this parameter has a default value set, e.g. getDefaultValues() should return at least one object
    • withNewDefaults

      public Parameter withNewDefaults(BiFunction<BindingContext,Parameter,List<?>> newDefaultFunction)

      Builds a new Parameter based on this one, but with new default value(s)

      Parameters:
      newDefaultFunction - a function that yields new default values
      Returns:
      a new parameter.
    • withNewName

      public Parameter withNewName(String newName)
    • getTypeName

      public String getTypeName()
    • getArity

      public String getArity()
    • hasCorrectArity

      public boolean hasCorrectArity(int numValues)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • withNewType

      public Parameter withNewType(Class<?> newType)
      Returns:
      a clone of this parameter with the type set to newType
    • withValidation

      public Parameter withValidation(BiFunction<BindingContext,Object,List<Problem>> validationFunction)
      Returns:
      a clone of this parameter with additional validation of the value supplied for the parameter
    • validate

      public List<Problem> validate(BindingContext context, Object boundValue)

      Performs optional additional validation on a value bound to this parameter. E.g. the parameter might expect not only an integer value, but a value between 1 and 100.

      Returns:
      a list of problems, if the bound value is invalid
    • getType

      @NonNull public @NonNull Class<?> getType()
    • getDefaultFunction

      @NonNull public @NonNull Optional<BiFunction<BindingContext,Parameter,List<?>>> getDefaultFunction()
    • getMinRequired

      public int getMinRequired()
    • getMaxRequired

      public int getMaxRequired()
    • getValidation

      @NonNull public @NonNull BiFunction<BindingContext,Object,List<Problem>> getValidation()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getName

      @NonNull public @NonNull String getName()