Package nz.org.riskscape.engine.function
Class FunctionArgument
java.lang.Object
nz.org.riskscape.engine.function.FunctionArgument
-
Constructor Summary
ConstructorDescriptionFunctionArgument
(int index, Type type) FunctionArgument
(String keyword, Type type) FunctionArgument
(String keyword, Type type, Optional<Object> defaultValue) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
boolean
<T> ResultOrProblems<T>
evaluateConstant
(RealizationContext context, FunctionCall functionCall, Class<T> requiredJavaType) Helper method for aRealizableFunction
to extract a constant from the arguments with various error handling along the way.int
getIndex()
getType()
int
hashCode()
boolean
<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.void
setIndex
(int index) toString()
-
Constructor Details
-
FunctionArgument
-
FunctionArgument
-
FunctionArgument
-
-
Method Details
-
hasKeyword
public boolean hasKeyword() -
toString
-
getFunctionCallArgument
- 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 toRealizableFunction.realize(RealizationContext, FunctionCall, List)
functionCall
- the functionCall expression that contains an argument to be realized constantlyrequiredJavaType
- the desired java type of the constant - must map to a built-in riskscape type viaTypes.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
-
getType
-
getDefaultValue
-
getIndex
public int getIndex() -
setIndex
public void setIndex(int index) -
equals
-
canEqual
-
hashCode
public int hashCode()
-