Interface RealizedExpression

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
RealizedExpressionWrapper

public interface RealizedExpression extends AutoCloseable

Represents an Expression that has been realized against a specific RiskScape type. Given an object that conforms to that type, this expression can be safely evaluated against it.

  • Method Details

    • getInputType

      Type getInputType()
      Returns:
      the type that this expression was realized for
    • getResultType

      Type getResultType()
      Returns:
      the type that this expression yields
    • evaluate

      Object evaluate(Object input)

      Evaluate this expression against the given object

      Parameters:
      input - an object that must conform to getInputType()
      Returns:
      an object that must conform to getResultType()
    • evaluateValues

      default Object evaluateValues(Object... values)

      Convenience form of evaluate(java.lang.Object) for expressions that you know accept a Struct input type.

      This method will return evaluate(Tuple.ofValues(getInputType().asStruct(), values)

    • getExpression

      Expression getExpression()
      Returns:
      the AST that this expression was realized from.
    • getDependencies

      List<RealizedExpression> getDependencies()
      Returns:
      any RealizedExpressions that are inputs in to this realized expression
    • close

      default void close()

      Destroy/release/abandon any resources associated with this expression. Note that a realized expression should propagate closing to any dependencies, as the default implementation does.

      See Javadoc Realized for more discussion on the life-cycle of executable objects like these.

      Specified by:
      close in interface AutoCloseable
    • isConstant

      boolean isConstant()

      Determine whether this expression is constant, that is the return value of evaluateConstant() never changes. Note that the same can not be said of evaluate(Object), as the underlying expression may not be deterministic - the implementation of evaluateConstant should ensure that the expressions result is memoized and the same value returned each time.

      Returns:
      true if calls to evaluateConstant() are allowed against this realized expression.
    • evaluateConstant

      Object evaluateConstant()
      Returns:
      the result of evaluation without access to scope.
      Throws:
      IllegalStateException - if this expression is not constant.