Interface RealizedExpression
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
RealizedExpressionWrapper
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 Summary
Modifier and TypeMethodDescriptiondefault voidclose()Destroy/release/abandon any resources associated with this expression.Evaluate this expression against the given objectdefault ObjectevaluateValues(Object... values) Convenience form ofevaluate(java.lang.Object)for expressions that you know accept aStructinput type.booleanDetermine whether this expression is constant, that is the return value ofevaluateConstant()never changes.
-
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
Evaluate this expression against the given object
- Parameters:
input- an object that must conform togetInputType()- Returns:
- an object that must conform to
getResultType()
-
evaluateValues
Convenience form of
evaluate(java.lang.Object)for expressions that you know accept aStructinput 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
Realizedfor more discussion on the life-cycle of executable objects like these.- Specified by:
closein interfaceAutoCloseable
-
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 ofevaluate(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.
-