Class NullSafeFunction

java.lang.Object
nz.org.riskscape.engine.function.NullSafeFunction
All Implemented Interfaces:
AutoCloseable, RiskscapeFunction, UntypedFunction

public class NullSafeFunction extends Object implements RiskscapeFunction

A RiskscapeFunction that wraps another one to short-circuit the target function to return null if any of the args are null.

  • Constructor Details

    • NullSafeFunction

      protected NullSafeFunction(RiskscapeFunction target, List<Type> argumentTypes, Type returnType, boolean[] notNullableIndices)
  • Method Details

    • wrap

      public static RiskscapeFunction wrap(RiskscapeFunction target)

      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

      public static RiskscapeFunction wrapIgnoringArgs(RiskscapeFunction target)

      Wrap the given target function in a null-safe version.

    • call

      public Object call(List<Object> args)
      Description copied from interface: UntypedFunction

      Execute the function with the given arguments.

      Specified by:
      call in interface UntypedFunction
      Parameters:
      args - list of arguments to the function that should conform to the types in ArgumentList.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 RealizedExpressions 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 interface AutoCloseable
      Specified by:
      close in interface UntypedFunction
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getTarget

      public RiskscapeFunction getTarget()
    • getArgumentTypes

      public List<Type> getArgumentTypes()
      Specified by:
      getArgumentTypes in interface RiskscapeFunction
      Returns:
      the types that this function expects
    • getReturnType

      public Type getReturnType()
      Specified by:
      getReturnType in interface RiskscapeFunction
      Returns:
      the type that this function should return
    • getNotNullableIndices

      public boolean[] getNotNullableIndices()

      for each argument, records true if the original receiver is not nullable