Class ParameterTemplate

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

public class ParameterTemplate extends Object

Wraps a Parameter and extends it with metadata useful for modelers when building their models.

Some of the fields affect their presentation (in the CLI or the Web UI), some supply rules for transforming them before converting them in to expressions that a model can use.

  • Field Details

  • Constructor Details

    • ParameterTemplate

      public ParameterTemplate(Optional<String> label, Optional<String> description, Set<ParameterProperty> properties, List<ParameterTemplate.Choice> choices)
    • ParameterTemplate

      public ParameterTemplate(Optional<String> label, Optional<String> description, Set<ParameterProperty> properties, List<ParameterTemplate.Choice> choices, Optional<String> defaultValue)

      Creates a new ParameterTemplate instance.

      Parameters:
      label - A human-readable label, as an alternative to the parameter's name (which tends to follow slug conventions).
      description - A description of this parameter, typically detailing its use in the model or the project.
      properties - The set of properties that customise this parameter template. These typically apply validation and transformations to the raw value before it gets converted in to an expression.
      choices - A set of pre-defined choices for this parameter that the modeller has deemed correct.
      defaultValue - A default value. NB work out how this relates to the existing default that lives on a Parameter
  • Method Details

    • hasProperty

      public boolean hasProperty(ParameterProperty property)
    • getProperty

      public <T extends ParameterProperty> Optional<T> getProperty(T property)

      Returns the specified property, if present in the template. This is mainly useful for KeyValueProperty, where the actual ParameterProperty instance has more info associated with it.

    • withLabel

      public ParameterTemplate withLabel(String newLabel)
    • withProperties

      public ParameterTemplate withProperties(Set<ParameterProperty> newProperties)
      Returns:
      a cloned copy of this template with the newProperties specified
    • withDefaultValue

      public ParameterTemplate withDefaultValue(String newDefault)
    • validate

      public List<Problem> validate(BindingContext context, Object bound)
      Returns:
      a list of problems when validating this bound parameter. These validation rules are in addition to the type-based validation that the Parameter binding already provides.
    • getProperties

      public Set<ParameterProperty> getProperties()

      Returns all properties for the parameter. These properties may be explicitly set by the user, implied (e.g. MIN_VALUE implies NUMERIC), or inferred (e.g. if no properties are explicitly set, then we can tell from the default value [1,2,3] that the parameter is both NUMERIC and a LIST).

    • getLabel

      public Optional<String> getLabel()

      A human-readable label, as an alternative to the parameter's name (which tends to follow slug conventions).

    • getDescription

      public Optional<String> getDescription()

      A description of this parameter, typically detailing its use in the model or the project.

    • getChoices

      public List<ParameterTemplate.Choice> getChoices()

      A set of pre-defined choices for this parameter that the modeller has deemed correct.

    • getDefaultValue

      public Optional<String> getDefaultValue()

      A default value. NB work out how this relates to the existing default that lives on a Parameter

    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object