Class CompoundVariable
- java.lang.Object
-
- net.ssehub.easy.varModel.confModel.DecisionVariable
-
- net.ssehub.easy.varModel.confModel.StructuredVariable
-
- net.ssehub.easy.varModel.confModel.CompoundVariable
-
- All Implemented Interfaces:
IConfigurationElement,IConfigurationVisitable,IDecisionVariable,IValueParent
public class CompoundVariable extends StructuredVariable
Class for variables of Compounds.- Author:
- El-Sharkawy
-
-
Field Summary
Fields Modifier and Type Field Description private booleancreatedprivate CompoundinstantiatableTypeprivate java.util.Map<java.lang.String,IDecisionVariable>nestedElements
-
Constructor Summary
Constructors Constructor Description CompoundVariable(IConfigurationElement parent, AbstractVariable varDeclaration, boolean isVisible, boolean isAttribute)Sole constructor for creatingContainerVariable's.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) booleanallowsNestedStates()Returns whether this variable support individual states for nested items.private IDecisionVariablecreateNestedElement(AbstractVariable decl, boolean isVisible, boolean isAttribute, boolean force)Creates a nested element due to its declaration and registers it.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.IDatatypegetInstantiatableType()Returns one of the actual types required to instantiate this variable.protected EASyLoggerFactory.EASyLoggergetLogger()Returns the logger for this instance.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 a nestedIDecisionVariable.protected IResolutionPathElementgetPathForNestedElement(IDecisionVariable nested)Returns the resolution path for a nested element.IAssignmentStategetState()Returns the assignment state of this variable.ValuegetValue()Returns the current value of thisIDecisionVariable.private booleanisDirectTypeRecursive(AbstractVariable slot)Returns whetherslothas a directly recursive type (same or somehow refined) to the containing type.voidnotifyCreated()Notifies this variable that it was created.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).booleanremoveDerivedValues()Removes all (nested) values which are in stateAssignmentState.DERIVED, i.e., all values which are propagated bay the reasoner.private voidresolveAssignBlocks(AttributeAssignment assignBlock, java.util.Map<java.lang.String,Value> annotationValues)Second recursive part ofresolveAssignBlocks(Compound), find (nested assign blocks) inside the currently visited compound and set values to the associatedIDecisionVariables.private voidresolveAssignBlocks(Compound cType)Recursive part of the constructor to resolve annotation assignment blocks of (parent/this) compound.voidsetValue(Value value, IAssignmentState state)Changes the value (for incremental buildup).voidsetValue(Value value, IAssignmentState state, IConfigurationElement nested)Changes the value of a nested variable.voidunfreeze(IAssignmentState state)Causes to unfreeze the current value.booleanwasCreated()Returns whether the variable value was explicitly created.-
Methods inherited from class net.ssehub.easy.varModel.confModel.DecisionVariable
accept, getAttribute, getAttributesCount, getConfigProvider, getConfiguration, getDeclaration, getNestedDepth, getParent, getQualifiedName, getResolutionPath, hasNullValue, hasValue, isAttribute, isLocal, isNested, isVisible, ownStateAllowed, setHistoryValue, setIndex, setState, setValue, toString, wasAssigned
-
-
-
-
Field Detail
-
nestedElements
private java.util.Map<java.lang.String,IDecisionVariable> nestedElements
-
instantiatableType
private Compound instantiatableType
-
created
private boolean created
-
-
Constructor Detail
-
CompoundVariable
CompoundVariable(IConfigurationElement parent, AbstractVariable varDeclaration, boolean isVisible, boolean isAttribute)
Sole constructor for creatingContainerVariable's.- Parameters:
parent- the parent this variable is part of, typically theConfigurationinstance, but in case of compounds/container also the containingIDecisionVariablevarDeclaration- the variable declaration instantiated by this decisionisVisible- Specifies whether this variables is exported by an interface or not:- true: The variable is exported by an interface or there is no interface .
- false: There is an interface which does not export this variable .
isAttribute- whether this variable represents (a part of) an attribute or a variable
-
-
Method Detail
-
getInstantiatableType
public IDatatype getInstantiatableType()
Description copied from class:DecisionVariableReturns one of the actual types required to instantiate this variable. This is typically the type of the underlying variable declaration, but, in case of abstract variables, may also be one of the subtypes if defined. As changing the value with a different permitted type leads to a take over of the respective dynamic type, the indeterminism shall not lead to problems.- Overrides:
getInstantiatableTypein classDecisionVariable- Returns:
- the instantiatable type
-
resolveAssignBlocks
private void resolveAssignBlocks(Compound cType)
Recursive part of the constructor to resolve annotation assignment blocks of (parent/this) compound.- Parameters:
cType- The currently analyzed compound (should be called the (refined) compound type of this variable instance).
-
resolveAssignBlocks
private void resolveAssignBlocks(AttributeAssignment assignBlock, java.util.Map<java.lang.String,Value> annotationValues)
Second recursive part ofresolveAssignBlocks(Compound), find (nested assign blocks) inside the currently visited compound and set values to the associatedIDecisionVariables.- Parameters:
assignBlock- The currently visited assign block (start with assign blocks directly nested inside the compound).annotationValues- Mapping of (annotation name, value). Start with an empty map and copy values into a new map for each recursive call.
-
isDirectTypeRecursive
private boolean isDirectTypeRecursive(AbstractVariable slot)
Returns whetherslothas a directly recursive type (same or somehow refined) to the containing type.- Parameters:
slot- the slot to look for- Returns:
truein case of a directly recursive type,falseelse
-
createNestedElement
private IDecisionVariable createNestedElement(AbstractVariable decl, boolean isVisible, boolean isAttribute, boolean force)
Creates a nested element due to its declaration and registers it.- Parameters:
decl- the variable declarationisVisible- specifies whether the parent variable is exported by an interface or notisAttribute- whether this variable represents (a part of) an attribute or a variableforce- enforce creation of nested element even ifisDirectTypeRecursive(AbstractVariable)- Returns:
- the created variable, null if creation did not happen or failed (see log)
-
getState
public IAssignmentState getState()
Description copied from interface:IConfigurationElementReturns the assignment state of this variable.- Specified by:
getStatein interfaceIConfigurationElement- Overrides:
getStatein classDecisionVariable- Returns:
- the assignment state
-
getNestedElementsCount
public int getNestedElementsCount()
Description copied from interface:IDecisionVariableReturns the number of nested elements. The return value should be 0 unless thisIDecisionVariableis a- 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]- Parameters:
index- a 0-based index specifying the element to be returned- Returns:
- the element
-
getNestedElement
public IDecisionVariable getNestedElement(java.lang.String name)
Description copied from interface:IDecisionVariableReturns an element specified by its name.- Specified by:
getNestedElementin interfaceIDecisionVariable- Overrides:
getNestedElementin classDecisionVariable- Parameters:
name- the name of the nested element- Returns:
- the nested element (may be null)
-
setValue
public void setValue(Value value, IAssignmentState state, IConfigurationElement nested) throws ConfigurationException
Description copied from interface:IConfigurationElementChanges the value of a nested variable.- 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
-
setValue
public void setValue(Value value, IAssignmentState state) throws ConfigurationException
Changes the value (for incremental buildup).
Sets also the states for the nested elements.- Specified by:
setValuein interfaceIDecisionVariable- Overrides:
setValuein classDecisionVariable- 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
-
getNestedVariable
public IDecisionVariable getNestedVariable(java.lang.String slotName)
Returns a nestedIDecisionVariable.- Parameters:
slotName- The name of the nestedIDecisionVariableto be returned.- Returns:
- The nested
IDecisionVariablewith the same name or null.
-
freeze
public void freeze(java.lang.String nestedElement)
Description copied from interface:IConfigurationElementCauses to freeze a nested value.- Parameters:
nestedElement- The name of the nested Element, which should be frozen.
-
freeze
public void freeze(IFreezeSelector selector)
Description copied from interface:IConfigurationElementCauses to freeze the current value.- Specified by:
freezein interfaceIConfigurationElement- Overrides:
freezein classDecisionVariable- 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- Overrides:
unfreezein classDecisionVariable- Parameters:
state- the target state for unfreezing (must not beAssignmentState.FROZEN)
-
allowsNestedStates
boolean allowsNestedStates()
Description copied from class:StructuredVariableReturns whether this variable support individual states for nested items.- Specified by:
allowsNestedStatesin classStructuredVariable- Returns:
- true if nested items can have their own states, otherwise false.
-
getValue
public Value getValue()
Description copied from interface:IDecisionVariableReturns the current value of thisIDecisionVariable.- Specified by:
getValuein interfaceIDecisionVariable- Overrides:
getValuein classDecisionVariable- Returns:
- the value (may be null)
-
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.- Returns:
- true if there was a change, false if the variable keeps unchanged.
-
getPathForNestedElement
protected IResolutionPathElement getPathForNestedElement(IDecisionVariable nested)
Returns the resolution path for a nested element.- Overrides:
getPathForNestedElementin classDecisionVariable- Parameters:
nested- the nested element- Returns:
- the resolution path
-
getLogger
protected EASyLoggerFactory.EASyLogger getLogger()
Returns the logger for this instance.- Returns:
- the logger
-
notifyCreated
public void notifyCreated()
Description copied from interface:IDecisionVariableNotifies this variable that it was created.- Specified by:
notifyCreatedin interfaceIDecisionVariable- Overrides:
notifyCreatedin classDecisionVariable
-
wasCreated
public boolean wasCreated()
Description copied from interface:IConfigurationElementReturns whether the variable value was explicitly created.- Specified by:
wasCreatedin interfaceIConfigurationElement- Overrides:
wasCreatedin classDecisionVariable- Returns:
truefor created,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- Overrides:
enableWasAssignedForIsDefinedin classDecisionVariable- Returns:
truetakeIDecisionVariable.wasAssigned(),falseforIConfigurationElement.getState().
-
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- Overrides:
notifyWasAssignedin classDecisionVariable- Parameters:
value- the new value- Returns:
truewhether this variable was defined before,falseelse
-
-