Package nz.org.riskscape.engine.function
Class NullSafeFunction
java.lang.Object
nz.org.riskscape.engine.function.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, LOG
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
NullSafeFunction
(RiskscapeFunction target, List<Type> argumentTypes, Type returnType, boolean[] notNullableIndices) -
Method Summary
Modifier and TypeMethodDescriptionExecute the function with the given arguments.void
close()
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()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceRiskscapeFunction
-
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
-