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
ConstructorsModifierConstructorDescriptionprotectedNullSafeFunction(RiskscapeFunction target, List<Type> argumentTypes, Type returnType, boolean[] notNullableIndices) Creates a newNullSafeFunctioninstance. -
Method Summary
Modifier and TypeMethodDescriptionExecute the function with the given arguments.voidclose()boolean[]for each argument, records true if the original receiver is not nullabletoString()static RiskscapeFunctionwrap(RiskscapeFunction target) Wrap the given target function in a null-safe version.static RiskscapeFunctionwrapIgnoringArgs(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, waitMethods 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) Creates a new
NullSafeFunctioninstance.- Parameters:
target-argumentTypes-returnType-notNullableIndices- for each argument, records true if the original receiver is not nullable
-
-
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
NullSafeFunctionwith 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:UntypedFunctionExecute the function with the given arguments.
- Specified by:
callin interfaceUntypedFunction- Parameters:
args- list of arguments to the function that should conform to the types inArgumentList.getArgumentTypes()
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceRiskscapeFunction
-
toString
-
getTarget
-
getArgumentTypes
- Specified by:
getArgumentTypesin interfaceRiskscapeFunction- Returns:
- the types that this function expects
-
getReturnType
- Specified by:
getReturnTypein 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
-