Class NullSafeFunction
- All Implemented Interfaces:
AutoCloseable
,RiskscapeFunction
,UntypedFunction
A RiskscapeFunction
that wraps another one to short-circuit the target function to return null if any of the
args are null.
-
Field Summary
Fields inherited from interface nz.org.riskscape.engine.function.RiskscapeFunction
BUILT_IN
-
Constructor Summary
ModifierConstructorDescriptionprotected
NullSafeFunction
(RiskscapeFunction target, List<Type> argumentTypes, Type returnType, boolean[] notNullableIndices) -
Method Summary
Modifier and TypeMethodDescriptionExecute the function with the given arguments.void
close()
Clean up any resources that were allocated with this function.boolean[]
for each argument, records true if the original receiver is not nullabletoString()
static RiskscapeFunction
wrap
(RiskscapeFunction target) Wrap the given target function in a null-safe version.static RiskscapeFunction
wrapIgnoringArgs
(RiskscapeFunction target) Wrap the given target function in a null-safe version.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.function.RiskscapeFunction
builtin, getAggregationFunction, getArguments, getOverloaded, getRealizable, getTypesFromArguments, identified, identified, isA, setProblemReporter, validate
-
Constructor Details
-
NullSafeFunction
protected NullSafeFunction(RiskscapeFunction target, List<Type> argumentTypes, Type returnType, boolean[] notNullableIndices)
-
-
Method Details
-
wrap
Wrap the given target function in a null-safe version. If any of the target function's arguments are not nullable, then the resulting function will be a
NullSafeFunction
with those arguments that are not marked as nullable being wrapped and applying the null-short-circuit behaviour when the function is called -
wrapIgnoringArgs
Wrap the given target function in a null-safe version.
-
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()
-
close
public void close()Description copied from interface:UntypedFunction
Clean up any resources that were allocated with this function. This can include large objects, so that any memory used can be reclaimed.
See
Realized
for more information on the life-cycle of executable pipeline objects.Note that there is no standard mechanism for cleaning up resources allocated to functions that realize lambda expressions - the closing of any
RealizedExpression
s or related objects must be done by the function when it's closed. This is probably something that should be addressed once some standard patterns have been established for the implementation of lambda-accepting functions.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceUntypedFunction
-
toString
-
getTarget
-
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
-
getNotNullableIndices
public boolean[] getNotNullableIndices()for each argument, records true if the original receiver is not nullable
-