Interface RiskscapeFunction
- All Superinterfaces:
AutoCloseable
,UntypedFunction
- All Known Subinterfaces:
IdentifiedFunction
- All Known Implementing Classes:
AddAggregationFunction
,AggregationFunctionAdapter
,BinaryFunction
,BinaryOperatorFunction
,BinaryPredicateFunction
,ConstantFunction
,IdentifiedFunction.Wrapping
,JavaFunction
,MetadataBasedFunction
,NullSafeFunction
,RealizableFunction.MetadataIdentifiedRealizableFunction
,UnaryFunction
General interface for any kind of function that accepts and returns riskscape types values.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptiondefault IdentifiedFunction
builtin
(String id, IdentifiedFunction.Category category) static RiskscapeFunction
Create aRiskscapeFunction
from the given types and untyped function.default Optional<AggregationFunction>
default ArgumentList
default Optional<OverloadedFunction>
default Optional<RealizableFunction>
default IdentifiedFunction
identified
(String id) default IdentifiedFunction
identified
(String id, String description, String source, IdentifiedFunction.Category category) default <T extends RiskscapeFunction>
Optional<T>default void
setProblemReporter
(Consumer<Problem> problemReporter) Set a problem report that this function may use to issueProblem
s to if any are encountered whilst the function is being called.default ResultOrProblems<Boolean>
validate
(RealizationContext context) Validate that the function can be run.Methods inherited from interface nz.org.riskscape.engine.function.UntypedFunction
call, close
-
Field Details
-
BUILT_IN
- See Also:
-
-
Method Details
-
create
static RiskscapeFunction create(Object source, List<Type> argumentTypes, Type returnType, UntypedFunction function) Create a
RiskscapeFunction
from the given types and untyped function. Note that this won't add any type checking or coercion around the function call, it simply serves as a way to add the type metadata to anUntypedFunction
to make it fulfill theRiskscapeFunction
interface.- Parameters:
source
- an object to use in the toString of this function to track where it came from, or null to just use the function as the sourcefunction
- a function we are extending with type metadata.- Returns:
- a RiskscapeFunction that can be used as part of a RiskScape expression
-
getArgumentTypes
- Returns:
- the types that this function expects
-
getReturnType
Type getReturnType()- Returns:
- the type that this function should return
-
validate
Validate that the function can be run.
To be considered valid there should be no
Problem
s found that are at error or fatal. Finding problems of lower severity should not make a function invalid.- Returns:
- ResultOrProblems indicating if function is valid
-
getRealizable
- Returns:
- a
RealizableFunction
that can realize thisRiskscapeFunction
against a type, or empty if this function does not support realization.
-
getOverloaded
- Returns:
- an
OverloadedFunction
that offers alternative input types for use within an expression, or empty if this function does not support overloading
-
getAggregationFunction
- Returns:
- An
AggregationFunction
that is functionally the same operation as this, but works with aRealizedAggregateExpression
, rather than against aRealizedExpression
with anRSList
.
-
getArguments
-
getTypesFromArguments
-
setProblemReporter
Set a problem report that this function may use to issue
Problem
s to if any are encountered whilst the function is being called.Any
Problem
s sent to the problemReporter should clearly state what function they came from.- Parameters:
problemReporter
-
-
identified
default IdentifiedFunction identified(String id, String description, String source, IdentifiedFunction.Category category) - Returns:
- an
IdentifiedFunction
that wraps this function with the given metadata. Note that for built-in functions,builtin(String, IdentifiedFunction.Category)
is probably a better choice to use (i.e. is simpler and encourages i18n description).
-
builtin
- Returns:
- an
IdentifiedFunction
that wraps this function with the given metadata
-
identified
- Returns:
- alternative to
identified(String, String, String, IdentifiedFunction.Category)
that is suitable for test cases
-
isA
-