Class EvaluationAccessor

java.lang.Object
net.ssehub.easy.varModel.cstEvaluation.EvaluationAccessor
Direct Known Subclasses:
AbstractDecisionVariableEvaluationAccessor, ConstantAccessor

public abstract class EvaluationAccessor extends Object
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 Details

  • Constructor Details

    • EvaluationAccessor

      public EvaluationAccessor()
  • Method Details

    • 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

      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 new EvaluationVisitor to resolve reference expressions.
      Returns:
      the dereferenced value (may be null if undefined)
      See Also:
    • 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 value
      asAssignment - does this happen through an IVML assignment operation
      Returns:
      true if successful, false else
    • 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 value
      value - the new nested value
    • isAssigned

      public boolean isAssigned()
      Returns whether the underlying value is assigned or still undefined.
      Returns:
      true if a value is assigned, false else
    • 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:
      true if values can be assigned, false else
    • validateContext

      public void validateContext(EvaluationContext context)
      Validates the context and sets the contained context to context if not given.
      Parameters:
      context - the context to validate with
    • dereferenceIfNeeded

      protected IDecisionVariable dereferenceIfNeeded(IDecisionVariable variable, Value value)
      Dereferences variable if of reference type and value is not of reference type.
      Parameters:
      variable - the variable
      value - the value to consider
      Returns:
      variable or the dereferenced variable
    • bindContainer

      public void bindContainer(IDecisionVariable container)
      Binds a container as 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 at index in accessor to this accessor. If the bound container element does not exist, null will be added.
      Parameters:
      accessor - the accessor to take the bound container element from
      index - the index
    • clearContainerElements

      public void clearContainerElements()
      Clears the bound container elements.
    • addBoundContainerElement

      public void addBoundContainerElement(IDecisionVariable element)
      Adds element to 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 in accessor to 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:
      true for constant, false else