Class FunctionArgument

java.lang.Object
nz.org.riskscape.engine.function.FunctionArgument

public class FunctionArgument extends Object
  • Constructor Details

    • FunctionArgument

      public FunctionArgument(int index, Type type)
    • FunctionArgument

      public FunctionArgument(String keyword, Type type)
    • FunctionArgument

      public FunctionArgument(String keyword, Type type, Optional<Object> defaultValue)
  • Method Details

    • hasKeyword

      public boolean hasKeyword()
    • toString

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

      public Optional<FunctionCall.Argument> getFunctionCallArgument(FunctionCall fc)
      Returns:
      the actual FunctionCall FunctionCall.Argument supplied by the user (if any)
    • evaluateConstant

      public <T> ResultOrProblems<T> evaluateConstant(RealizationContext context, FunctionCall functionCall, Class<T> requiredJavaType)

      Helper method for a RealizableFunction to extract a constant from the arguments with various error handling along the way. This method will fail if the expression is not a constant expression (e.g. it depends on values extracted from scope).

      Type Parameters:
      T - the java return type
      Parameters:
      context - context in which realization is happening - typically the argument that was passed to RealizableFunction.realize(RealizationContext, FunctionCall, List)
      functionCall - the functionCall expression that contains an argument to be realized constantly
      requiredJavaType - the desired java type of the constant - must map to a built-in riskscape type via Types.fromJavaType(Class)
      Returns:
      the constant value from the function call expression, or a failed result
    • mapFunctionCall

      public <T> ResultOrProblems<T> mapFunctionCall(FunctionCall fc, Function<FunctionCall.Argument,ResultOrProblems<T>> mapper)

      Convenience method to apply a mapping to actual value that was supplied (i.e. the FunctionCall FunctionCall.Argument), with appropriate boilerplate error handling if the mapping failed. E.g. use like this:

      result = argumentList.get("my-arg").mapFunctionCall(fc, arg -> { // do stuff to the supplied FunctionCall.Argument... }).getOrThrow();

    • getKeyword

      public String getKeyword()
    • getType

      public Type getType()
    • getDefaultValue

      public Optional<Object> getDefaultValue()
    • getIndex

      public int getIndex()
    • setIndex

      public void setIndex(int index)
    • 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