Class LocalDecisionVariable
- java.lang.Object
-
- net.ssehub.easy.varModel.cstEvaluation.LocalDecisionVariable
-
- All Implemented Interfaces:
IConfigurationElement,IConfigurationVisitable,IDecisionVariable,IValueParent
public class LocalDecisionVariable extends java.lang.Object implements IDecisionVariable
A local decision variable representing a parameter or a local variable. A local decision variable must also return local decision variables (in order to remain "local").- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private IConfigurationconfprivate DecisionVariableDeclarationdecl(package private) static java.lang.StringITERATOR_RESULT_VARNAMEprivate IValueChangeListenerlistenerprivate IDecisionVariableparentprivate IAssignmentStatestateprivate Valuevalue
-
Constructor Summary
Constructors Constructor Description LocalDecisionVariable(DecisionVariableDeclaration decl, IConfiguration conf, IDecisionVariable parent)Creates a local decision variable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(IConfigurationVisitor visitor)Accepts and calls the given visitor.booleanenableWasAssignedForIsDefined()Shall we take the localIDecisionVariable.wasAssigned()overIConfigurationElement.getState()in the implementation of IVML "isDefined".voidfreeze(java.lang.String nestedElement)Causes to freeze a nested value.voidfreeze(IFreezeSelector selector)Causes to freeze the current value.IDecisionVariablegetAttribute(int index)Returns a specific attribute.intgetAttributesCount()Returns the number of attributes.ConfigurationgetConfiguration()Returns the topLevel parent.AbstractVariablegetDeclaration()Returns the declaration of the variable.intgetNestedDepth()Returns how many parentIDecisionVariables exist for this variable.IDecisionVariablegetNestedElement(int index)Returns the element specified byindex.IDecisionVariablegetNestedElement(java.lang.String name)Returns an element specified by its name.intgetNestedElementsCount()Returns the number of nested elements.IDecisionVariablegetNestedVariable(java.lang.String slotName)Returns the nested variable for the given slot name.IConfigurationElementgetParent()Returns the element this element is part of.java.lang.StringgetQualifiedName()Returns the qualified name of the declaration instance.IResolutionPathElementgetResolutionPath()Returns a resolution path for this variable.IAssignmentStategetState()Returns the assignment state of this variable.ValuegetValue()Returns the current value of thisIDecisionVariable.private IValueParentgetValueParent(Value value)Returns the value parent ofvalue.IDecisionVariablegetVariable()Returns the underlying variable.booleanhasNullValue()Checks whether the variable has aNullValue.booleanhasValue()Checks whether the variable has a configuredValue.booleanisLocal()Returns whether this variable is local, e.g., as a parameter of a user-defined function, a variable defined by a let-expression, or an iterator in a container operation.booleanisNested()Returns whether this decision variable is nested.booleanisVisible()Returns whether this variable is visible by the user.voidnotifyCreated()Notifies this variable that it was created.private voidnotifyValueChanged(Value oldValue, IAssignmentState oldState, IValueChangeListener.ChangeKind kind)Notifies the change listener if defined.booleannotifyWasAssigned(Value value)Inform the variable independent of its own tracking that we believe that a value was assigned (although we did not due to equal values/performance reasons), in particular after resetting the track throughCommandAssignmentState#compareTo(CommandAssignmentState).private IValueParentobtainValueParent(Value value)Obtains the value parent for the stored value, the given value or the value of one of the parents.booleanremoveDerivedValues()Removes all (nested) values which are in stateAssignmentState.DERIVED, i.e., all values which are propagated bay the reasoner.voidsetHistoryValue(Value value, IAssignmentState state)Changes the value (for incremental buildup) from value history.voidsetValue(Value value, IAssignmentState state)Changes the value (for incremental buildup).voidsetValue(Value value, IAssignmentState state, boolean asAssignment)Changes the value.voidsetValue(Value value, IAssignmentState state, IConfigurationElement nested)Changes the value of a nested variable.voidsetValueChangeListener(IValueChangeListener listener)Defines the value change listener to be informed.voidsetVariable(IDecisionVariable variable)Changes the underlying variable taking precedence over the stored value.voidunfreeze(IAssignmentState state)Causes to unfreeze the current value.booleanwasAssigned()Returns whether a value was assigned (correlated, but independent ofIConfigurationElement.getState()).booleanwasCreated()Returns whether the variable value was explicitly created.
-
-
-
Field Detail
-
ITERATOR_RESULT_VARNAME
static final java.lang.String ITERATOR_RESULT_VARNAME
- See Also:
- Constant Field Values
-
decl
private DecisionVariableDeclaration decl
-
value
private Value value
-
state
private IAssignmentState state
-
conf
private IConfiguration conf
-
parent
private IDecisionVariable parent
-
listener
private IValueChangeListener listener
-
-
Constructor Detail
-
LocalDecisionVariable
public LocalDecisionVariable(DecisionVariableDeclaration decl, IConfiguration conf, IDecisionVariable parent)
Creates a local decision variable.- Parameters:
decl- the defining variable declarationconf- the configurationparent- the parent decision variable for call-by-reference, may be null
-
-
Method Detail
-
getParent
public IConfigurationElement getParent()
Description copied from interface:IConfigurationElementReturns the element this element is part of.- Specified by:
getParentin interfaceIConfigurationElement- Returns:
- the parent element (may be null in case of the top-level configuration)
-
getConfiguration
public Configuration getConfiguration()
Description copied from interface:IConfigurationElementReturns the topLevel parent.- Specified by:
getConfigurationin interfaceIConfigurationElement- Returns:
- should be the configuration
-
isNested
public boolean isNested()
Description copied from interface:IConfigurationElementReturns whether this decision variable is nested. Being member of aConfigurationdoes not imply.isNested== true- Specified by:
isNestedin interfaceIConfigurationElement- Returns:
trueif it is nested in another decision variable,falseelse
-
getState
public IAssignmentState getState()
Description copied from interface:IConfigurationElementReturns the assignment state of this variable.- Specified by:
getStatein interfaceIConfigurationElement- Returns:
- the assignment state
-
notifyValueChanged
private void notifyValueChanged(Value oldValue, IAssignmentState oldState, IValueChangeListener.ChangeKind kind)
Notifies the change listener if defined.- Parameters:
oldValue- the old value before the change, may be nulloldState- the old state ofvariablebefore the changekind- the change kind
-
setValue
public void setValue(Value value, IAssignmentState state, boolean asAssignment) throws ConfigurationException
Description copied from interface:IDecisionVariableChanges the value.- Specified by:
setValuein interfaceIDecisionVariable- Parameters:
value- the value (may be null for incremental buildup)state- the related assignment stateasAssignment- does this call happen as part of evaluating an IVML assignment operation- Throws:
ConfigurationException- in case that the types ofIConfigurationElement.getDeclaration()andvaluedo not comply
-
setValue
public void setValue(Value value, IAssignmentState state) throws ConfigurationException
Description copied from interface:IDecisionVariableChanges the value (for incremental buildup).- Specified by:
setValuein interfaceIDecisionVariable- Parameters:
value- the value (may be null for incremental buildup)state- the related assignment state- Throws:
ConfigurationException- in case that the types ofIConfigurationElement.getDeclaration()andvaluedo not comply
-
setValue
public void setValue(Value value, IAssignmentState state, IConfigurationElement nested) throws ConfigurationException
Description copied from interface:IConfigurationElementChanges the value of a nested variable.- Specified by:
setValuein interfaceIConfigurationElement- Parameters:
value- the new valuestate- the new assignment statenested- the nested variable to be considered in the parent- Throws:
ConfigurationException- in case of type incompatibilities
-
obtainValueParent
private IValueParent obtainValueParent(Value value)
Obtains the value parent for the stored value, the given value or the value of one of the parents.- Parameters:
value- the value to consider (may be null)- Returns:
- the value parent, may be null for none
-
getValueParent
private IValueParent getValueParent(Value value)
Returns the value parent ofvalue.- Parameters:
value- the value to return the parent for (may be null)- Returns:
- the value parent (may be null)
-
freeze
public void freeze(IFreezeSelector selector)
Description copied from interface:IConfigurationElementCauses to freeze the current value.- Specified by:
freezein interfaceIConfigurationElement- Parameters:
selector- determines which parts shall be frozen
-
unfreeze
public void unfreeze(IAssignmentState state)
Description copied from interface:IConfigurationElementCauses to unfreeze the current value.- Specified by:
unfreezein interfaceIConfigurationElement- Parameters:
state- the target state for unfreezing (must not beAssignmentState.FROZEN)
-
freeze
public void freeze(java.lang.String nestedElement)
Description copied from interface:IConfigurationElementCauses to freeze a nested value.- Specified by:
freezein interfaceIConfigurationElement- Parameters:
nestedElement- The name of the nested Element, which should be frozen.
-
getDeclaration
public AbstractVariable getDeclaration()
Description copied from interface:IConfigurationElementReturns the declaration of the variable.- Specified by:
getDeclarationin interfaceIConfigurationElement- Returns:
- the declaration of the decision variable
-
accept
public void accept(IConfigurationVisitor visitor)
Description copied from interface:IConfigurationVisitableAccepts and calls the given visitor.- Specified by:
acceptin interfaceIConfigurationVisitable- Parameters:
visitor- the visitor
-
getValue
public Value getValue()
Description copied from interface:IDecisionVariableReturns the current value of thisIDecisionVariable.- Specified by:
getValuein interfaceIDecisionVariable- Returns:
- the value (may be null)
-
setHistoryValue
public void setHistoryValue(Value value, IAssignmentState state) throws ConfigurationException
Description copied from interface:IDecisionVariableChanges the value (for incremental buildup) from value history.- Specified by:
setHistoryValuein interfaceIDecisionVariable- Parameters:
value- the value (may be null for incremental buildup)state- the related assignment state- Throws:
ConfigurationException- in case that the types ofIConfigurationElement.getDeclaration()andvaluedo not comply
-
getNestedElementsCount
public int getNestedElementsCount()
Description copied from interface:IDecisionVariableReturns the number of nested elements. The return value should be 0 unless thisIDecisionVariableis a- Specified by:
getNestedElementsCountin interfaceIDecisionVariable- Returns:
- An integer value greater or equal to 0.
-
getNestedElement
public IDecisionVariable getNestedElement(int index)
Description copied from interface:IDecisionVariableReturns the element specified byindex. [also req SAP]- Specified by:
getNestedElementin interfaceIDecisionVariable- Parameters:
index- a 0-based index specifying the element to be returned- Returns:
- the element
-
getNestedVariable
public IDecisionVariable getNestedVariable(java.lang.String slotName)
Returns the nested variable for the given slot name.- Parameters:
slotName- the slot name- Returns:
- the nested variable or null if it does not exist
-
getNestedElement
public IDecisionVariable getNestedElement(java.lang.String name)
Description copied from interface:IDecisionVariableReturns an element specified by its name.- Specified by:
getNestedElementin interfaceIDecisionVariable- Parameters:
name- the name of the nested element- Returns:
- the nested element (may be null)
-
getAttributesCount
public int getAttributesCount()
Description copied from interface:IDecisionVariableReturns the number of attributes.- Specified by:
getAttributesCountin interfaceIDecisionVariable- Returns:
- the number of attributes
-
getAttribute
public IDecisionVariable getAttribute(int index)
Description copied from interface:IDecisionVariableReturns a specific attribute.- Specified by:
getAttributein interfaceIDecisionVariable- Parameters:
index- the index of the attribute- Returns:
- the attribute
-
getNestedDepth
public int getNestedDepth()
Description copied from interface:IDecisionVariableReturns how many parentIDecisionVariables exist for this variable.- Specified by:
getNestedDepthin interfaceIDecisionVariable- Returns:
- 0 if the Configuration is the direct parent of this
IDecisionVariable, otherwise a number greater than 0 indicating how manyIDecisionVariables between theConfigurationand this variable exist.
-
isVisible
public boolean isVisible()
Description copied from interface:IDecisionVariableReturns whether this variable is visible by the user.- Specified by:
isVisiblein interfaceIDecisionVariable- Returns:
- false if the variable is hidden by an interface, true otherwise
-
hasValue
public boolean hasValue()
Description copied from interface:IDecisionVariableChecks whether the variable has a configuredValue.- Specified by:
hasValuein interfaceIDecisionVariable- Returns:
- true if the variable has a value, false otherwise.
-
hasNullValue
public boolean hasNullValue()
Description copied from interface:IDecisionVariableChecks whether the variable has aNullValue. Note: this method does not check whether the variable has a value.- Specified by:
hasNullValuein interfaceIDecisionVariable- Returns:
- true if the variable has a
NullValue, false otherwise.
-
removeDerivedValues
public boolean removeDerivedValues()
Description copied from interface:IDecisionVariableRemoves all (nested) values which are in stateAssignmentState.DERIVED, i.e., all values which are propagated bay the reasoner. This will keep all user assignedAssignmentState.ASSIGNEDand frozenAssignmentState.FROZENvalues.- Specified by:
removeDerivedValuesin interfaceIDecisionVariable- Returns:
- true if there was a change, false if the variable keeps unchanged.
-
getQualifiedName
public java.lang.String getQualifiedName()
Description copied from interface:IDecisionVariableReturns the qualified name of the declaration instance. This is build as follows:
<Project name> :: [<Parent name>::]* <Declaration name>- Specified by:
getQualifiedNamein interfaceIDecisionVariable- Returns:
- The qualified and unique name of the variable.
-
getResolutionPath
public IResolutionPathElement getResolutionPath()
Description copied from interface:IDecisionVariableReturns a resolution path for this variable.- Specified by:
getResolutionPathin interfaceIDecisionVariable- Returns:
- the resolution path
-
isLocal
public boolean isLocal()
Description copied from interface:IDecisionVariableReturns whether this variable is local, e.g., as a parameter of a user-defined function, a variable defined by a let-expression, or an iterator in a container operation.- Specified by:
isLocalin interfaceIDecisionVariable- Returns:
- false if the variable is not local and part of an usual configuration,
trueif the variable is local
-
setVariable
public void setVariable(IDecisionVariable variable)
Changes the underlying variable taking precedence over the stored value.- Parameters:
variable- the variable (may be null) to ignore
-
getVariable
public IDecisionVariable getVariable()
Returns the underlying variable.- Returns:
- variable the variable (may be null)
-
setValueChangeListener
public void setValueChangeListener(IValueChangeListener listener)
Defines the value change listener to be informed.- Parameters:
listener- the listener instance or null for none
-
wasCreated
public boolean wasCreated()
Description copied from interface:IConfigurationElementReturns whether the variable value was explicitly created.- Specified by:
wasCreatedin interfaceIConfigurationElement- Returns:
truefor created,falseelse
-
notifyCreated
public void notifyCreated()
Description copied from interface:IDecisionVariableNotifies this variable that it was created.- Specified by:
notifyCreatedin interfaceIDecisionVariable
-
notifyWasAssigned
public boolean notifyWasAssigned(Value value)
Description copied from interface:IDecisionVariableInform the variable independent of its own tracking that we believe that a value was assigned (although we did not due to equal values/performance reasons), in particular after resetting the track throughCommandAssignmentState#compareTo(CommandAssignmentState).- Specified by:
notifyWasAssignedin interfaceIDecisionVariable- Parameters:
value- the new value- Returns:
truewhether this variable was defined before,falseelse
-
wasAssigned
public boolean wasAssigned()
Description copied from interface:IDecisionVariableReturns whether a value was assigned (correlated, but independent ofIConfigurationElement.getState()).- Specified by:
wasAssignedin interfaceIDecisionVariable- Returns:
trueif a value was assigned,falseelse
-
enableWasAssignedForIsDefined
public boolean enableWasAssignedForIsDefined()
Description copied from interface:IDecisionVariableShall we take the localIDecisionVariable.wasAssigned()overIConfigurationElement.getState()in the implementation of IVML "isDefined".- Specified by:
enableWasAssignedForIsDefinedin interfaceIDecisionVariable- Returns:
truetakeIDecisionVariable.wasAssigned(),falseforIConfigurationElement.getState().
-
-