Class EvaluationAccessor
- java.lang.Object
-
- net.ssehub.easy.varModel.cstEvaluation.EvaluationAccessor
-
- Direct Known Subclasses:
AbstractDecisionVariableEvaluationAccessor,ConstantAccessor
public abstract class EvaluationAccessor extends java.lang.ObjectDefines 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 Modifier and Type Field Description private EvaluationContextcontextprivate java.util.List<IDecisionVariable>nestedElements
-
Constructor Summary
Constructors Constructor Description EvaluationAccessor()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddBoundContainerElement(IDecisionVariable element)Addselementto 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.voidclearContainerElements()Clears the bound container elements.protected IDecisionVariabledereferenceIfNeeded(IDecisionVariable variable, Value value)Dereferencesvariableif of reference type andvalueis not of reference type.IDecisionVariablegetBoundContainerElement(int index)Returns a container element.intgetBoundContainerElementCount()Returns the number of container elements.EvaluationContextgetContext()Returns the evaluation context.ValuegetDereferencedValue()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 ValuegetReferenceValue()Returns the value of a reference to the accessed element.abstract ValuegetValue()Returns the value of the accessed element.EvaluationAccessorgetValue(EvaluationAccessor accessor)Returns a nested value based on the given accessor.abstract IDecisionVariablegetVariable()Returns the underlying variable.abstract booleanisAssignable()Returns whether values can be assigned to this evaluator.booleanisAssigned()Returns whether the underlying value is assigned or still undefined.booleanisConstant()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.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 booleansetValue(Value value, boolean asAssignment)Defines a new value for the accessed element.voidvalidateContext(EvaluationContext context)Validates the context and sets the contained context tocontextif not given.
-
-
-
Field Detail
-
context
private EvaluationContext context
-
nestedElements
private java.util.List<IDecisionVariable> nestedElements
-
-
Method Detail
-
bind
protected void bind(EvaluationContext context)
Binds the accessor to the given context.- Parameters:
context- the context to bind the accessor to- See Also:
clear()
-
clear
public void clear()
Clears the accessor for reuse.
-
getContext
public EvaluationContext getContext()
Returns the evaluation context.- Returns:
- the evaluation context
-
getValue
public abstract Value getValue()
Returns the value of the accessed element.- Returns:
- the value (may be null if undefined)
-
getDereferencedValue
public Value 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:
getValue()
-
getReferenceValue
public abstract Value getReferenceValue()
Returns the value of a reference to the accessed element.- Returns:
- the value (may be null if undefined)
-
setValue
public abstract boolean setValue(Value value, boolean asAssignment)
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
public EvaluationAccessor getValue(EvaluationAccessor accessor)
Returns a nested value based on the given accessor.- Parameters:
accessor- the accessor to determine the nested value- Returns:
- the nested value
-
setValue
public void setValue(EvaluationAccessor accessor, Value value)
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
public abstract IDecisionVariable getVariable()
Returns the underlying variable.- Returns:
- the underlying variable (may be null)
-
release
public static <T extends EvaluationAccessor> T release(T accessor)
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
public void validateContext(EvaluationContext context)
Validates the context and sets the contained context tocontextif not given.- Parameters:
context- the context to validate with
-
dereferenceIfNeeded
protected IDecisionVariable dereferenceIfNeeded(IDecisionVariable variable, Value value)
Dereferencesvariableif of reference type andvalueis not of reference type.- Parameters:
variable- the variablevalue- the value to consider- Returns:
variableor the dereferenced variable
-
bindContainer
public void bindContainer(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.- Parameters:
container- the
-
addBoundContainerElement
public void addBoundContainerElement(EvaluationAccessor accessor, int index)
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
public void addBoundContainerElement(IDecisionVariable element)
Addselementto the bound container elements.- Parameters:
element- the element to add (may be null for none
-
bindContainer
public void bindContainer(EvaluationAccessor accessor)
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
public IDecisionVariable getBoundContainerElement(int index)
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
-
-