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
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault IdentifiedFunctionbuiltin(String id, IdentifiedFunction.Category category) default voidclose()static RiskscapeFunctioncreate(Object source, List<Type> argumentTypes, Type returnType, UntypedFunction function, AutoCloseable... closeThese) Create aRiskscapeFunctionfrom the given types and untyped function.default Optional<AggregationFunction>default ArgumentListdefault Optional<OverloadedFunction>default Optional<RealizableFunction>default IdentifiedFunctionidentified(String id) default IdentifiedFunctionidentified(String id, String description, URI source, IdentifiedFunction.Category category) default <T extends RiskscapeFunction>
Optional<T>default voidsetProblemReporter(Consumer<Problem> problemReporter) Set a problem report that this function may use to issueProblems 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
-
Field Details
-
LOG
static final org.slf4j.Logger LOG -
BUILT_IN
-
-
Method Details
-
create
static RiskscapeFunction create(Object source, List<Type> argumentTypes, Type returnType, UntypedFunction function, AutoCloseable... closeThese) Create a
RiskscapeFunctionfrom 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 anUntypedFunctionto make it fulfill theRiskscapeFunctioninterface.Also accepts an optional list of
AutoCloseableobjects to clean up when the function gets closed. It's worthy of note that there is no standard mechanism for cleaning up resources allocated to functions that realize lambda expressions - the closing of anyRealizedExpressions or related objects must be done by the function when it's closed. If a lambda scope or function is passed around as data in a tuple, then there is no standard way to clean up resources attached to it (see https://gitlab.catalyst.net.nz/riskscape/riskscape/-/issues/1441 as an example of this.- 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.closeThese- anyAutoCloseableresources to clean up when this function is closed. Can pass nulls, they will be skipped/ignored- 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
Problems 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
RealizableFunctionthat can realize thisRiskscapeFunctionagainst a type, or empty if this function does not support realization.
-
getOverloaded
- Returns:
- an
OverloadedFunctionthat offers alternative input types for use within an expression, or empty if this function does not support overloading
-
getAggregationFunction
- Returns:
- An
AggregationFunctionthat is functionally the same operation as this, but works with aRealizedAggregateExpression, rather than against aRealizedExpressionwith anRSList.
-
getArguments
-
getTypesFromArguments
-
setProblemReporter
Set a problem report that this function may use to issue
Problems to if any are encountered whilst the function is being called.Any
Problems sent to the problemReporter should clearly state what function they came from.- Parameters:
problemReporter-
-
identified
default IdentifiedFunction identified(String id, String description, URI source, IdentifiedFunction.Category category) - Returns:
- an
IdentifiedFunctionthat 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
IdentifiedFunctionthat wraps this function with the given metadata
-
identified
- Returns:
- alternative to
#identified(String, String, String, IdentifiedFunction.Category)that is suitable for test cases
-
isA
-
close
default void close()- Specified by:
closein interfaceAutoCloseable
-