Package net.ssehub.easy.varModel.model
Class BasicDecisionVariableContainer
java.lang.Object
net.ssehub.easy.varModel.model.ModelElement
net.ssehub.easy.varModel.model.BasicDecisionVariableContainer
- All Implemented Interfaces:
IContainableElementsSorter,IDecisionVariableContainer,IModelElement
- Direct Known Subclasses:
FullDecisionVariableContainer
public class BasicDecisionVariableContainer
extends ModelElement
implements IDecisionVariableContainer
This class basically realizes a decision variable container (this class does not support realizing constraints).
However, this type of class (regarding the interface) may be used from a data type as well as from a containable
model element in two different parts of the same inheritance hierarchy. This would duplicate code. As multiple
inheritance is not supported in Java, we implement the basic functionality here and support reuse by delegation.
So far we refrained from defining (multiple) recursive iterators (over the assignments) due to different style and
potential performance issues of the generic code.
- Author:
- Holger Eichelberger
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List<DecisionVariableDeclaration> This includes allDecisionVariableDeclaration, including nestedDecisionVariableDeclarations of attribute assignments.private List<AttributeAssignment> private List<Constraint> private List<DecisionVariableDeclaration> private List<ContainableModelElement> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(IModelVisitor visitor) Accept method for the visitor.voidadd(AttributeAssignment assignment) Adds a nested assignment.voidAdds a comment to the list of contained elements.booleanMethod to add an object to the elements list of the project.voidadd(EvaluationBlock eval) adds a nested evaluation block.voidaddConstraint(Constraint constraint, boolean internal) Adds a constraint.booleanReturns whether this element containsvar.booleancontainsByName(String name) Returns whether this project contains an element and its name.voidForces theIDecisionVariableContainerto update cached lists of nestedDecisionVariableDeclarations.getAssignment(int index) Returns the assignment specified byindex.intReturns the number of assignments.getConstraint(int index) Returns the specified contained constraint.intReturns the number of contained constraints.getDeclaration(int index) Returns the specifiedDecisionVariableDeclaration.intReturns the number of all nestedDecisionVariableDeclarations including nestedDecisionVariableDeclarations ofAttributeAssignments.getElement(int index) Returns the element specified byindex.getElement(String name) Returns the element specified byname.intReturns the number of elements.getModelElement(int index) Returns a contained model element specified byindex.intReturns the number of contained elements.getRealizing(int index) Returns the specified realizing constraint.intReturns the number of realizing constraints.booleanpropagateAttribute(Attribute attribute) Propagates an attribute application from the parent to this element or contained elements.booleanRemoves the specified model element from this container (if it exists).voidSorts the contained elements (and creates the related datastructure if needed) according to the specified comparator.toString()Methods inherited from class net.ssehub.easy.varModel.model.ModelElement
findAttribute, getComment, getName, getNameSpace, getParent, getQualifiedName, getUniqueName, isTransparent, setComment, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.ssehub.easy.varModel.model.IModelElement
getComment, getName, getNameSpace, getParent, getQualifiedName, getUniqueName, isTransparent, setComment
-
Field Details
-
elements
-
constraints
-
assignments
-
modelElements
-
names
-
allDeclarations
This includes allDecisionVariableDeclaration, including nestedDecisionVariableDeclarations of attribute assignments. This list will only be generated on demand, i.e. ifgetDeclarationCount()is called.
-
-
Constructor Details
-
BasicDecisionVariableContainer
public BasicDecisionVariableContainer()Creates a container instance.
-
-
Method Details
-
sortContainedElements
Description copied from interface:IContainableElementsSorterSorts the contained elements (and creates the related datastructure if needed) according to the specified comparator. Please note the following requirements for applying this method:- All Elements which were added before this operation must still be member of this project after executing this operation.
- Comments related to an element must occur before the element in the final sequence.
- Specified by:
sortContainedElementsin interfaceIContainableElementsSorter- Parameters:
comp- a comparator which fulfills the requirements above
-
add
Description copied from interface:IDecisionVariableContainerAdds a nested assignment.- Specified by:
addin interfaceIDecisionVariableContainer- Parameters:
assignment- the assignment which should be added
-
forceUpdate
public void forceUpdate()Description copied from interface:IDecisionVariableContainerForces theIDecisionVariableContainerto update cached lists of nestedDecisionVariableDeclarations. This is only necessary if multipleIDecisionVariableContainerare nested into each other and only during incremental build up if an inner element is updated while already added to the outer element.- Specified by:
forceUpdatein interfaceIDecisionVariableContainer
-
add
adds a nested evaluation block.- Specified by:
addin interfaceIDecisionVariableContainer- Parameters:
eval- the eval block
-
getAssignmentCount
public int getAssignmentCount()Description copied from interface:IDecisionVariableContainerReturns the number of assignments.- Specified by:
getAssignmentCountin interfaceIDecisionVariableContainer- Returns:
- the number of assignments
-
getAssignment
Description copied from interface:IDecisionVariableContainerReturns the assignment specified byindex.- Specified by:
getAssignmentin interfaceIDecisionVariableContainer- Parameters:
index- a 0-based index specifying the element to be returned- Returns:
- the assignment
-
getModelElement
Description copied from interface:IDecisionVariableContainerReturns a contained model element specified byindex. Please note that this method returns all contained model elements, i.e., decision variables and constraints and is intended to restore the input sequence correctly.- Specified by:
getModelElementin interfaceIDecisionVariableContainer- Parameters:
index- a 0-based index specifying the operation to be returned- Returns:
- the contained element
-
getModelElementCount
public int getModelElementCount()Returns the number of contained elements. Please note that this method refers to all contained model elements, i.e., decision variables and constraints and is intended to restore the input sequence correctly.- Specified by:
getModelElementCountin interfaceIDecisionVariableContainer- Returns:
- the number of contained elements
-
getElement
Description copied from interface:IDecisionVariableContainerReturns the element specified byname.- Specified by:
getElementin interfaceIDecisionVariableContainer- Parameters:
name- the name of the element- Returns:
- the element, null if none was found
-
contains
Description copied from interface:IDecisionVariableContainerReturns whether this element containsvar.- Specified by:
containsin interfaceIDecisionVariableContainer- Parameters:
var- the variable declaration to search for- Returns:
trueif found,falseelse
-
containsByName
Returns whether this project contains an element and its name.- Specified by:
containsByNamein interfaceIDecisionVariableContainer- Parameters:
name- the name to search for- Returns:
trueif this project contains the specified element,falseelse
-
add
Description copied from interface:IDecisionVariableContainerAdds a comment to the list of contained elements.- Specified by:
addin interfaceIDecisionVariableContainer- Parameters:
comment- the comment to be added
-
getElementCount
public int getElementCount()Description copied from interface:IDecisionVariableContainerReturns the number of elements.- Specified by:
getElementCountin interfaceIDecisionVariableContainer- Returns:
- the number of elements
-
getElement
Description copied from interface:IDecisionVariableContainerReturns the element specified byindex.- Specified by:
getElementin interfaceIDecisionVariableContainer- Parameters:
index- a 0-based index specifying the element to be returned- Returns:
- the element
-
add
Description copied from interface:IDecisionVariableContainerMethod to add an object to the elements list of the project.- Specified by:
addin interfaceIDecisionVariableContainer- Parameters:
elem- which should be added- Returns:
trueif the addition was successful,falseelse due to duplicated variable declaration
-
getConstraintsCount
public int getConstraintsCount()Description copied from interface:IDecisionVariableContainerReturns the number of contained constraints.- Specified by:
getConstraintsCountin interfaceIDecisionVariableContainer- Returns:
- the number of constraints
-
getConstraint
Description copied from interface:IDecisionVariableContainerReturns the specified contained constraint.- Specified by:
getConstraintin interfaceIDecisionVariableContainer- Parameters:
index- the index of the constraint to be returned- Returns:
- the specified constraint
-
addConstraint
Description copied from interface:IDecisionVariableContainerAdds a constraint.- Specified by:
addConstraintin interfaceIDecisionVariableContainer- Parameters:
constraint- the constraint to be addedinternal- whether the constraint is internally created while building up the model (ignored)
-
getRealizingCount
public int getRealizingCount()Description copied from interface:IDecisionVariableContainerReturns the number of realizing constraints. Please note that these constraints are derived and not originally specified in the input IVML model.- Specified by:
getRealizingCountin interfaceIDecisionVariableContainer- Returns:
- the number of constraints
-
getRealizing
Description copied from interface:IDecisionVariableContainerReturns the specified realizing constraint. Please note that these constraints are derived and not originally specified in the input IVML model.- Specified by:
getRealizingin interfaceIDecisionVariableContainer- Parameters:
index- the index of the constraint to be returned- Returns:
- the specified constraint
-
propagateAttribute
Description copied from interface:IModelElementPropagates an attribute application from the parent to this element or contained elements. This may imply the creation of clones of the givenattribute.- Specified by:
propagateAttributein interfaceIModelElement- Overrides:
propagateAttributein classModelElement- Parameters:
attribute- the attribute to be propagated- Returns:
trueif the operation was successful,falseif the element is about being attributed multiple times with the same attribute
-
accept
Description copied from interface:IModelElementAccept method for the visitor.- Specified by:
acceptin interfaceIModelElement- Parameters:
visitor- The visitor, which should process this model element.
-
getDeclarationCount
public int getDeclarationCount()Description copied from interface:IDecisionVariableContainerReturns the number of all nestedDecisionVariableDeclarations including nestedDecisionVariableDeclarations ofAttributeAssignments.- Specified by:
getDeclarationCountin interfaceIDecisionVariableContainer- Returns:
- The number of all nested
DecisionVariableDeclarations. This will be greater or equal to 0.
-
getDeclaration
Description copied from interface:IDecisionVariableContainerReturns the specifiedDecisionVariableDeclaration.- Specified by:
getDeclarationin interfaceIDecisionVariableContainer- Parameters:
index- the index of theDecisionVariableDeclarationto be returned- Returns:
- the specified
DecisionVariableDeclaration
-
removeModelElement
Removes the specified model element from this container (if it exists).- Parameters:
element- TheConstraint,DecisionVariableDeclaration, orAttributeAssignmentto remove. If null nothing will happen.- Returns:
trueif the model element was part of this container and was removed successfully.
-
toString
- Overrides:
toStringin classModelElement
-