Package nz.org.riskscape.engine.function
Class JavaFunction
java.lang.Object
nz.org.riskscape.engine.function.JavaFunction
- All Implemented Interfaces:
AutoCloseable
,IdentifiedFunction
,RiskscapeFunction
,UntypedFunction
,Identified
Immutable prototype-builder implementation of IdentifiedFunction
TODO given the use of this an all sorts of other implementations, the name of this needs to change to be more like
'BaseFunction' or 'ImmutableFunction'
-
Nested Class Summary
Nested classes/interfaces inherited from interface nz.org.riskscape.engine.function.IdentifiedFunction
IdentifiedFunction.Category, IdentifiedFunction.Wrapping
-
Field Summary
Fields inherited from interface nz.org.riskscape.engine.function.RiskscapeFunction
BUILT_IN
-
Constructor Summary
ConstructorDescriptionJavaFunction
(String id, String source, String description, List<Type> argumentTypes, Type returnType, JavaFunction.Delegate delegate, IdentifiedFunction.Category category) JavaFunction
(FunctionMetadata metadata, JavaFunction.Delegate delegate) -
Method Summary
Modifier and TypeMethodDescriptionstatic JavaFunction
asBuiltin
(String id, IdentifiedFunction.Category category) Execute the function with the given arguments.calling
(JavaFunction.Delegate newDelegate) Returns the argument list fromJavaFunction.Delegate.getArguments()
if this is not null else defers toRiskscapeFunction.getArguments()
.getId()
void
toString()
validate
(RealizationContext context) Validate that the function can be run.withArgumentTypes
(List<Type> newArgumentTypes) withArgumentTypes
(Type... newArgumentTypes) static JavaFunction
static JavaFunction
withIdAndSource
(String id, String source) withReturnType
(Type newReturnType) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface nz.org.riskscape.engine.Identified
getIdentifiedClass
Methods inherited from interface nz.org.riskscape.engine.function.IdentifiedFunction
infoOutput, isBuiltin, toEntity
Methods inherited from interface nz.org.riskscape.engine.function.RiskscapeFunction
builtin, getAggregationFunction, getOverloaded, getRealizable, getTypesFromArguments, identified, identified, isA, setProblemReporter
Methods inherited from interface nz.org.riskscape.engine.function.UntypedFunction
close
-
Field Details
-
ID_PATTERN
REGEX pattern for valid ID's.
ID's may only contain alpha numeric characters, ':', '_' and '-',
-
-
Constructor Details
-
JavaFunction
-
JavaFunction
public JavaFunction(String id, String source, String description, List<Type> argumentTypes, Type returnType, JavaFunction.Delegate delegate, IdentifiedFunction.Category category)
-
-
Method Details
-
asBuiltin
-
withId
-
withIdAndSource
- Parameters:
id
- of the functionsource
- identifies where the function came from. Used when reportingProblem
s- Returns:
- the function
-
call
Description copied from interface:UntypedFunction
Execute the function with the given arguments.
- Specified by:
call
in interfaceUntypedFunction
- Parameters:
args
- list of arguments to the function that should conform to the types inArgumentList.getArgumentTypes()
-
validate
Description copied from interface:RiskscapeFunction
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.- Specified by:
validate
in interfaceRiskscapeFunction
- Returns:
- ResultOrProblems indicating if function is valid
-
getArguments
Returns the argument list from
JavaFunction.Delegate.getArguments()
if this is not null else defers toRiskscapeFunction.getArguments()
.- Specified by:
getArguments
in interfaceRiskscapeFunction
- Returns:
- argument list
-
withArgumentTypes
-
withArgumentTypes
-
withReturnType
-
calling
-
toString
-
getId
- Specified by:
getId
in interfaceIdentified
- Returns:
- id
-
getSource
- Specified by:
getSource
in interfaceIdentifiedFunction
- Returns:
- a string indicating the source of function. file/uri etc.
-
setSource
-
getDescription
- Specified by:
getDescription
in interfaceIdentifiedFunction
- Returns:
- a human readable description of the function
-
getArgumentTypes
- Specified by:
getArgumentTypes
in interfaceRiskscapeFunction
- Returns:
- the types that this function expects
-
getReturnType
- Specified by:
getReturnType
in interfaceRiskscapeFunction
- Returns:
- the type that this function should return
-
getDelegate
-
getCategory
- Specified by:
getCategory
in interfaceIdentifiedFunction
- Returns:
- the category that this function belongs to
-