Class EvaluationAccessor
java.lang.Object
net.ssehub.easy.varModel.cstEvaluation.EvaluationAccessor
- Direct Known Subclasses:
AbstractDecisionVariableEvaluationAccessor,ConstantAccessor
Defines a unified accessor to variables, constants, slots etc. Please note that individual implementations
shall be accessible via pools. Also records nested variables as evaluation context, e.g., to carry variables
over a container aggregation function and to allow access to slots/attributes in following expressions.
[public for testing]
- Author:
- Holger Eichelberger
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAddselementto the bound container elements.voidaddBoundContainerElement(EvaluationAccessor accessor, int index) Adds the bound container element stored atindexinaccessorto this accessor.protected voidbind(EvaluationContext context) Binds the accessor to the given context.voidbindContainer(IDecisionVariable container) Binds acontaineras provider for nested variables against this accessor in order to carry information about the underlying variables as long as possible through the evaluation.voidbindContainer(EvaluationAccessor accessor) Binds all bound container elements stored inaccessorto this accessor.voidclear()Clears the accessor for reuse.voidClears the bound container elements.protected IDecisionVariabledereferenceIfNeeded(IDecisionVariable variable, Value value) Dereferencesvariableif of reference type andvalueis not of reference type.getBoundContainerElement(int index) Returns a container element.intReturns the number of container elements.Returns the evaluation context.Returns the value of the accessed element, referred values are dereferenced.
Note: This method is expensive as it may create a newEvaluationVisitorto resolve reference expressions.abstract ValueReturns the value of a reference to the accessed element.abstract ValuegetValue()Returns the value of the accessed element.getValue(EvaluationAccessor accessor) Returns a nested value based on the given accessor.abstract IDecisionVariableReturns the underlying variable.abstract booleanReturns whether values can be assigned to this evaluator.booleanReturns whether the underlying value is assigned or still undefined.booleanReturns whether this accessor represents a constant in the sense of the evaluation process, i.e., a value that is already evaluated to its very end and not linked to any decision variable.abstract voidrelease()Releases this instance.static <T extends EvaluationAccessor>
Trelease(T accessor) Releases the given accessor.voidsetValue(EvaluationAccessor accessor, Value value) Changes a nested value based on the given accessor.abstract booleanDefines a new value for the accessed element.voidvalidateContext(EvaluationContext context) Validates the context and sets the contained context tocontextif not given.
-
Field Details
-
context
-
nestedElements
-
-
Constructor Details
-
EvaluationAccessor
public EvaluationAccessor()
-
-
Method Details
-
bind
Binds the accessor to the given context.- Parameters:
context- the context to bind the accessor to- See Also:
-
clear
public void clear()Clears the accessor for reuse. -
getContext
Returns the evaluation context.- Returns:
- the evaluation context
-
getValue
Returns the value of the accessed element.- Returns:
- the value (may be null if undefined)
-
getDereferencedValue
Returns the value of the accessed element, referred values are dereferenced.
Note: This method is expensive as it may create a newEvaluationVisitorto resolve reference expressions.- Returns:
- the dereferenced value (may be null if undefined)
- See Also:
-
getReferenceValue
Returns the value of a reference to the accessed element.- Returns:
- the value (may be null if undefined)
-
setValue
Defines a new value for the accessed element. In case of failures, add appropriate messages to the context.- Parameters:
value- the new valueasAssignment- does this happen through an IVML assignment operation- Returns:
trueif successful,falseelse
-
getValue
Returns a nested value based on the given accessor.- Parameters:
accessor- the accessor to determine the nested value- Returns:
- the nested value
-
setValue
Changes a nested value based on the given accessor.- Parameters:
accessor- the accessor to determine the nested valuevalue- the new nested value
-
isAssigned
public boolean isAssigned()Returns whether the underlying value is assigned or still undefined.- Returns:
trueif a value is assigned,falseelse
-
release
public abstract void release()Releases this instance. -
getVariable
Returns the underlying variable.- Returns:
- the underlying variable (may be null)
-
release
Releases the given accessor.- Type Parameters:
T- the type of the accessor- Parameters:
accessor- the accessor to be released (may be null)- Returns:
- always null (to ease clearing local variables)
-
isAssignable
public abstract boolean isAssignable()Returns whether values can be assigned to this evaluator.- Returns:
trueif values can be assigned,falseelse
-
validateContext
Validates the context and sets the contained context tocontextif not given.- Parameters:
context- the context to validate with
-
dereferenceIfNeeded
Dereferencesvariableif of reference type andvalueis not of reference type.- Parameters:
variable- the variablevalue- the value to consider- Returns:
variableor the dereferenced variable
-
bindContainer
Binds acontaineras provider for nested variables against this accessor in order to carry information about the underlying variables as long as possible through the evaluation.- Parameters:
container- the
-
addBoundContainerElement
Adds the bound container element stored atindexinaccessorto this accessor. If the bound container element does not exist, null will be added.- Parameters:
accessor- the accessor to take the bound container element fromindex- the index
-
clearContainerElements
public void clearContainerElements()Clears the bound container elements. -
addBoundContainerElement
Addselementto the bound container elements.- Parameters:
element- the element to add (may be null for none
-
bindContainer
Binds all bound container elements stored inaccessorto this accessor. Clears already bound elements in this accessor.- Parameters:
accessor- the accessor to take the elements from
-
getBoundContainerElement
Returns a container element. This method intentionally does not throw the typical exceptions.- Parameters:
index- the 0-based index- Returns:
- the element or null if it does not exist/is stored.
-
getBoundContainerElementCount
public int getBoundContainerElementCount()Returns the number of container elements.- Returns:
- the number of container elements
-
isConstant
public boolean isConstant()Returns whether this accessor represents a constant in the sense of the evaluation process, i.e., a value that is already evaluated to its very end and not linked to any decision variable.- Returns:
truefor constant,falseelse
-