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
Fields Modifier and Type Field Description private java.util.List<DecisionVariableDeclaration>allDeclarationsThis includes allDecisionVariableDeclaration, including nestedDecisionVariableDeclarations of attribute assignments.private java.util.List<AttributeAssignment>assignmentsprivate java.util.List<Constraint>constraintsprivate java.util.List<DecisionVariableDeclaration>elementsprivate java.util.List<ContainableModelElement>modelElementsprivate java.util.Set<java.lang.String>names
-
Constructor Summary
Constructors Constructor Description BasicDecisionVariableContainer()Creates a container instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(IModelVisitor visitor)Accept method for the visitor.voidadd(AttributeAssignment assignment)Adds a nested assignment.voidadd(Comment comment)Adds a comment to the list of contained elements.booleanadd(DecisionVariableDeclaration elem)Method 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.booleancontains(DecisionVariableDeclaration var)Returns whether this element containsvar.booleancontainsByName(java.lang.String name)Returns whether this project contains an element and its name.voidforceUpdate()Forces theIDecisionVariableContainerto update cached lists of nestedDecisionVariableDeclarations.AttributeAssignmentgetAssignment(int index)Returns the assignment specified byindex.intgetAssignmentCount()Returns the number of assignments.ConstraintgetConstraint(int index)Returns the specified contained constraint.intgetConstraintsCount()Returns the number of contained constraints.DecisionVariableDeclarationgetDeclaration(int index)Returns the specifiedDecisionVariableDeclaration.intgetDeclarationCount()Returns the number of all nestedDecisionVariableDeclarations including nestedDecisionVariableDeclarations ofAttributeAssignments.DecisionVariableDeclarationgetElement(int index)Returns the element specified byindex.DecisionVariableDeclarationgetElement(java.lang.String name)Returns the element specified byname.intgetElementCount()Returns the number of elements.ContainableModelElementgetModelElement(int index)Returns a contained model element specified byindex.intgetModelElementCount()Returns the number of contained elements.ConstraintgetRealizing(int index)Returns the specified realizing constraint.intgetRealizingCount()Returns the number of realizing constraints.booleanpropagateAttribute(Attribute attribute)Propagates an attribute application from the parent to this element or contained elements.booleanremoveModelElement(ContainableModelElement element)Removes the specified model element from this container (if it exists).voidsortContainedElements(java.util.Comparator<ContainableModelElement> comp)Sorts the contained elements (and creates the related datastructure if needed) according to the specified comparator.java.lang.StringtoString()-
Methods inherited from class net.ssehub.easy.varModel.model.ModelElement
findAttribute, getComment, getName, getNameSpace, getParent, getQualifiedName, getUniqueName, isTransparent, setComment, setName
-
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.model.IModelElement
getComment, getName, getNameSpace, getParent, getQualifiedName, getUniqueName, isTransparent, setComment
-
-
-
-
Field Detail
-
elements
private java.util.List<DecisionVariableDeclaration> elements
-
constraints
private java.util.List<Constraint> constraints
-
assignments
private java.util.List<AttributeAssignment> assignments
-
modelElements
private java.util.List<ContainableModelElement> modelElements
-
names
private java.util.Set<java.lang.String> names
-
allDeclarations
private java.util.List<DecisionVariableDeclaration> allDeclarations
This includes allDecisionVariableDeclaration, including nestedDecisionVariableDeclarations of attribute assignments. This list will only be generated on demand, i.e. if getDeclarationCount() is called.
-
-
Method Detail
-
sortContainedElements
public void sortContainedElements(java.util.Comparator<ContainableModelElement> comp)
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
public void add(AttributeAssignment assignment)
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
public void add(EvaluationBlock eval)
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
public AttributeAssignment getAssignment(int index)
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
public ContainableModelElement getModelElement(int index)
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
public DecisionVariableDeclaration getElement(java.lang.String name)
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
public boolean contains(DecisionVariableDeclaration var)
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
public boolean containsByName(java.lang.String name)
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
public void add(Comment comment)
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
public DecisionVariableDeclaration getElement(int index)
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
public boolean add(DecisionVariableDeclaration elem)
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
public Constraint getConstraint(int index)
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
public void addConstraint(Constraint constraint, boolean internal)
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
public Constraint getRealizing(int index)
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
public boolean propagateAttribute(Attribute attribute)
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
public void accept(IModelVisitor visitor)
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
public DecisionVariableDeclaration getDeclaration(int index)
Description copied from interface:IDecisionVariableContainerReturns the specifiedDecisionVariableDeclaration.- Specified by:
getDeclarationin interfaceIDecisionVariableContainer- Parameters:
index- the index of theDecisionVariableDeclarationto be returned- Returns:
- the specified
DecisionVariableDeclaration
-
removeModelElement
public boolean removeModelElement(ContainableModelElement element)
Removes the specified model element from this container (if it exists).- Parameters:
element- TheConstraint,DecisionVariableDeclaration, orAttributeAssignmentto remove. If null nothing will happen.- Returns:
- true if the model element was part of this container and was removed successfully.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classModelElement
-
-