Class DecisionVariable
- java.lang.Object
-
- net.ssehub.easy.varModel.confModel.DecisionVariable
-
- All Implemented Interfaces:
IConfigurationElement,IConfigurationVisitable,IDecisionVariable,IValueParent
- Direct Known Subclasses:
BasisVariable,StructuredVariable
abstract class DecisionVariable extends java.lang.Object implements IDecisionVariable
Implements a decision variable representing a specific decision. Initializes and stores attributes on decision variables.- Author:
- Holger Eichelberger, El-Sharkawy
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classDecisionVariable.InitializationAnnotationVisitorInitializes annotation variables of the containing decision variable.
-
Field Summary
Fields Modifier and Type Field Description private IDecisionVariable[]attributesprivate VariableConfigProviderconfigProviderprivate AbstractVariabledeclarationprivate booleanisAttributeprivate booleanisVisibleprivate IConfigurationElementparentprivate booleanwasAssigned
-
Constructor Summary
Constructors Modifier Constructor Description protectedDecisionVariable(IConfigurationElement parent, AbstractVariable varDeclaration, boolean isVisible, boolean isAttribute)Creates a new decision variable representing a specific decision.
-
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(IFreezeSelector selector)Causes to freeze the current value.IDecisionVariablegetAttribute(int index)Returns a specific attribute.intgetAttributesCount()Returns the number of attributes.(package private) VariableConfigProvidergetConfigProvider()Getter for theVariableConfigProvider.ConfigurationgetConfiguration()Returns the topLevel parent.AbstractVariablegetDeclaration()Returns the declaration of the variable.IDatatypegetInstantiatableType()Returns one of the actual types required to instantiate this variable.intgetNestedDepth()Returns how many parentIDecisionVariables exist for this variable.IDecisionVariablegetNestedElement(java.lang.String name)Returns an element specified by its name.IConfigurationElementgetParent()Returns the element this element is part of.protected IResolutionPathElementgetPathForNestedElement(IDecisionVariable nested)Returns the resolution path for a nested element.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.booleanhasNullValue()Checks whether the variable has aNullValue.booleanhasValue()Checks whether the variable has a configuredValue.protected booleanisAttribute()Returns whether this decision variable represents an attribute.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.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).(package private) booleanownStateAllowed()Returns whether this variable can have its ownIAssignmentState.voidsetHistoryValue(Value value, IAssignmentState state)Changes the value (for incremental buildup) from value history.(package private) voidsetIndex(int newIndex)Changes the index of the nestedDecisionVariable.(package private) voidsetState(IAssignmentState state)For setting states of nested variables.voidsetValue(Value value, IAssignmentState state)Changes the value (for incremental buildup).voidsetValue(Value value, IAssignmentState state, boolean asAssignment)Changes the value.java.lang.StringtoString()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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.ssehub.easy.varModel.confModel.IConfigurationElement
freeze, setValue
-
Methods inherited from interface net.ssehub.easy.varModel.confModel.IDecisionVariable
getNestedElement, getNestedElementsCount, removeDerivedValues
-
-
-
-
Field Detail
-
parent
private IConfigurationElement parent
-
configProvider
private VariableConfigProvider configProvider
-
declaration
private AbstractVariable declaration
-
attributes
private IDecisionVariable[] attributes
-
isVisible
private boolean isVisible
-
isAttribute
private boolean isAttribute
-
wasAssigned
private boolean wasAssigned
-
-
Constructor Detail
-
DecisionVariable
protected DecisionVariable(IConfigurationElement parent, AbstractVariable varDeclaration, boolean isVisible, boolean isAttribute)
Creates a new decision variable representing a specific decision. The assignment state will beAssignmentState.UNDEFINED.- Parameters:
parent- the parent this variable is part of, typically theConfigurationinstance, but in case of compounds/container also the holdingIDecisionVariablevarDeclaration- 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
-
getAttributesCount
public int getAttributesCount()
Returns the number of attributes.- Specified by:
getAttributesCountin interfaceIDecisionVariable- Returns:
- the number of attributes
-
getAttribute
public IDecisionVariable getAttribute(int index)
Returns a specific attribute.- Specified by:
getAttributein interfaceIDecisionVariable- Parameters:
index- the index of the attribute- Returns:
- the attribute
- Throws:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>=getAttributesCount()
-
isNested
public final 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
-
getParent
public final 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 final Configuration getConfiguration()
Description copied from interface:IConfigurationElementReturns the topLevel parent.- Specified by:
getConfigurationin interfaceIConfigurationElement- Returns:
- should be the configuration
-
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)
-
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, 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
-
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)
-
getState
public IAssignmentState getState()
Description copied from interface:IConfigurationElementReturns the assignment state of this variable.- Specified by:
getStatein interfaceIConfigurationElement- Returns:
- the assignment state
-
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
-
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)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getNestedDepth
public final 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.
-
setIndex
void setIndex(int newIndex)
Changes the index of the nestedDecisionVariable. This method is only supported if this variable is nested inside aContainerVariable. This method must be called after a nested element was removed out of the container, to ensure that this variable will retrieve the correct sub value of the relatedContainerVariable. this method will also ensure that this nested Variable will display the correct name.- Parameters:
newIndex- The new index inside the parentIDecisionVariable. This value must be in the range (this is not checked): (0 <= newIndex < getParent().getNestedElementsCount())
-
getConfigProvider
VariableConfigProvider getConfigProvider()
Getter for theVariableConfigProvider.- Returns:
- Returns the
VariableConfigProviderused in this class. ThisVariableConfigProvidershould not be null, however, it can be null during initialization it can be null.
-
ownStateAllowed
boolean ownStateAllowed()
Returns whether this variable can have its ownIAssignmentState.- Returns:
- false if one of the parents is a
ContainerVariable, otherwise it should be true.
-
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
-
isAttribute
protected boolean isAttribute()
Returns whether this decision variable represents an attribute.- Returns:
truefor attribute,falseelse
-
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
-
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.
-
setState
void setState(IAssignmentState state)
For setting states of nested variables.- Parameters:
state- The state of the parent, which should the nested variable also have.
-
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
-
getPathForNestedElement
protected IResolutionPathElement getPathForNestedElement(IDecisionVariable nested)
Returns the resolution path for a nested element.- Parameters:
nested- the nested element- Returns:
- the resolution path
-
getInstantiatableType
public IDatatype getInstantiatableType()
Returns 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.- Returns:
- the instantiatable type
-
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
-
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().
-
-