Enum Class TypedProperty

java.lang.Object
java.lang.Enum<TypedProperty>
nz.org.riskscape.engine.bind.TypedProperty
All Implemented Interfaces:
Serializable, Comparable<TypedProperty>, Constable, nz.org.riskscape.engine.bind.ParameterProperty

public enum TypedProperty extends Enum<TypedProperty> implements nz.org.riskscape.engine.bind.ParameterProperty

Describes the type of value we expect for this parameter, i.e. what the parameter should bind against (Java type, not RiskScape type). This property can be used to bind a generic 'expression' parameter against a more specific type, e.g. it must be a number.

The idea is we want a simple, flexible set of types here. RiskScape types can be a little too prescriptive (e.g. there's integer or there's floating - there is no 'number'), and can confuse even expert users (e.g. relation(struct(foo: floating,...)) vs 'bookmark'). However, we don't want to make the types too Java-ry for the user either, e.g. we don't want the user typing properties = UsgsShakemapBookmarkResolver.

To try to do the 'right thing', RiskScape may infer (guess) properties for a parameter, e.g. "this thing looks like a number". Guessing a prescriptive type (e.g. integer) would be annoying, as the user might also want to enter floating values.

Ultimately, these typed parameters need to be converted back into a RiskScape expression, so that the value can be injected into pipeline DSL.

  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    The parameter should accept either a bookmark or file.
    A user can explicitly state that a parameter takes an expression to avoid RiskScape inferring the wrong type.
    Used to explicitly state the parameter should only accept whole numbers, e.g.
    We don't really support binding against a Java List, so just bind lists as expressions.
    We don't support binding to just 'Number', but Double should work for anything that accepts either a float or integer RiskScape type
    Used to explicitly state the parameter should be a text string, e.g.
  • Method Summary

    Modifier and Type
    Method
    Description
    findBest(Collection<nz.org.riskscape.engine.bind.ParameterProperty> properties)
     
    List<nz.org.riskscape.engine.bind.ParameterProperty>
     
     
     
    boolean
    isCompatible(nz.org.riskscape.engine.bind.ParameterProperty that)
     
    Returns the enum constant of this class with the specified name.
    static TypedProperty[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface nz.org.riskscape.engine.bind.ParameterProperty

    getValueOr, hasKeyValuePair, implies, validate, withValue, withValue
  • Enum Constant Details

    • NUMERIC

      public static final TypedProperty NUMERIC

      We don't support binding to just 'Number', but Double should work for anything that accepts either a float or integer RiskScape type

    • INTEGER

      public static final TypedProperty INTEGER
      Used to explicitly state the parameter should only accept whole numbers, e.g. 'year_built'.
    • TEXT

      public static final TypedProperty TEXT
      Used to explicitly state the parameter should be a text string, e.g. 'foo'. In general, you'd be better off either using BOOKMARK or specifying the possible values as choices, rather than accepting any old text string, i.e. `param.example.choices = 'foo', 'bar', 'baz'`. One case for using text might be if you wanted to parameterize a column name or output filename
    • LIST

      public static final TypedProperty LIST
      We don't really support binding against a Java List, so just bind lists as expressions. Using InputFieldProperty.MULTISELECT or InputFieldProperty.CHECKBOX instead should cover most cases in the UI where the user needs to enter a list of values, but this is here for completeness.
    • BOOKMARK

      public static final TypedProperty BOOKMARK
      The parameter should accept either a bookmark or file. TODO we don't differentiate between the two currently, but we might need to. You can't always use a bookmark in places that expect a filepath
    • EXPRESSION

      public static final TypedProperty EXPRESSION
      A user can explicitly state that a parameter takes an expression to avoid RiskScape inferring the wrong type. E.g. even though the default value is a numeric constant, the user still wants to be able to specify `exposure.road_width`.
  • Method Details

    • values

      public static TypedProperty[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static TypedProperty valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • findBest

      public static Optional<TypedProperty> findBest(Collection<nz.org.riskscape.engine.bind.ParameterProperty> properties)
      Returns:
      the best TypedProperty to use (i.e. for binding), if any
    • isCompatible

      public boolean isCompatible(nz.org.riskscape.engine.bind.ParameterProperty that)
      Specified by:
      isCompatible in interface nz.org.riskscape.engine.bind.ParameterProperty
    • getKeyword

      public String getKeyword()
      Specified by:
      getKeyword in interface nz.org.riskscape.engine.bind.ParameterProperty
    • getParameterType

      public Class<?> getParameterType()
    • getImplied

      public List<nz.org.riskscape.engine.bind.ParameterProperty> getImplied()
      Specified by:
      getImplied in interface nz.org.riskscape.engine.bind.ParameterProperty