Class Compound
java.lang.Object
net.ssehub.easy.varModel.model.ModelElement
net.ssehub.easy.varModel.model.ContainableModelElement
net.ssehub.easy.varModel.model.datatypes.CustomDatatype
net.ssehub.easy.varModel.model.datatypes.StructuredDatatype
net.ssehub.easy.varModel.model.datatypes.Compound
- All Implemented Interfaces:
IContainableElementsSorter,IDatatype,IDatatypeVisitable,IResolutionScope,IConstraintHolder,IDecisionVariableContainer,IModelElement
public class Compound
extends StructuredDatatype
implements IResolutionScope, IDecisionVariableContainer, IConstraintHolder
A compound type groups multiple types into a single named unit.
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:
- heiko beck, Holger Eichelberger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Operationprivate BasicDecisionVariableContainerstatic final Operation(package private) static final DelegatingTypestatic final Operationstatic final Operationstatic final Operationprivate booleanstatic final Operationstatic final Operationprivate Compound[]static final IDatatypeThis constant represents the common type of all compounds.static final Operation -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateCompound()Creates the singleton instance forTYPE.Compound(String name, ModelElement parent) Constructor for a non-abstract compound.Compound(String name, ModelElement parent, boolean isAbstract, Compound refines) Constructor for a (potentially abstract, refined) compound.Compound(String name, ModelElement parent, boolean isAbstract, Compound... refines) Constructor for a (potentially abstract, refined) compound.Compound(String name, ModelElement parent, Compound refines) Constructor for a non-abstract (potentially refined) compound.Compound(String name, ModelElement parent, Compound... refines) Constructor for a non-abstract (potentially refined) compound. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(IDatatypeVisitor visitor) Accepts a specialized visitor for creating a textual representation of the identity of this type.voidaccept(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) Adds a constraint.voidaddConstraint(Constraint constraint, boolean internal) Adds a constraint.allImplementing(IResolutionScope scope) Finds all implementing compound types for this compound searching withinscopeand transitive imports.closestRefining(Collection<Compound> compounds) Returns the compounds fromcompoundsthat have minimumrefines distanceto this.booleanReturns whether this element containsvar.booleancontainsByName(String name) Returns whether this project contains an element and its name.booleancontainsByNameRefines(String name) Returns whethernameis already contained in this or a refined compound.private intfindRefinesDistanceTo(int res, Compound cmp) Iterates overgetRefines(int)to identify the refines distance from this tocmpusingresas initial result.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 a contained model element specified byindex.getElement(String name) Returns a contained model element specified by itsname.intReturns the number of contained elements.getImport(int index) Returns the project import specified byindex.intReturns the number of imports.getInheritedElement(int index) Same behavior asgetElement(int)but also considers inherited elements if this compound is a refinement of another compound.intSame behavior asgetElementCount(), but also considers inherited elements if this compound is a refinement of another compound.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.getRefines(int index) Returns the compound which is refined by this compound.intThe number of refines.intDetermines the (absolute) refinement distance from this tocmpconsidering this orcmpas alternative bases to search the hierarchy for.private intgetRefinesDistanceTo(Compound cmp, boolean checkOpposite) Determines the (absolute) refinement distance from this tocmpoptionally considering this orcmpas alternative bases to search the hierarchy for.booleanReturns whether this scope has interfaces.Finds the implementing non-abstract types for this compound, i.e., the ones that may instantiate this compound.booleanReturns whether this compound is abstract, i.e., whether it can be instantiated.booleanisAssignableFrom(IDatatype type) Determines if the data type represented by this object is either the same as, or is a supertype oftype.booleanReturns whether this scope is an interfaces.booleanisRefinedFrom(Compound cmp, boolean transitive) Whether this compound is directly or indirectly refined fromcmp.booleanpropagateAttribute(Attribute attribute) Propagates an attribute application from the parent to this element or contained elements.private static Collection<Compound> prune(Collection<Compound> compounds, boolean pruneAbstract) Prunes fromcompounds.static Collection<Compound> pruneAbstract(Collection<Compound> compounds) Prunes abstract compounds fromcompounds.static Collection<Compound> pruneNonAbstract(Collection<Compound> compounds) Prunes non-abstract compounds fromcompounds.booleanremoveConstraint(ContainableModelElement element) Removes the specified model element from this compound (if it exists).voidsetRefines(Compound[] refines) Setter for the parent/ super compound of a refinement.voidSorts the contained elements (and creates the related datastructure if needed) according to the specified comparator.Methods inherited from class net.ssehub.easy.varModel.model.datatypes.CustomDatatype
getGenericType, getGenericTypeCount, getOperation, getOperationCount, getType, getTypeClass, isPrimitive, isPseudoType, isTypeMethods inherited from class net.ssehub.easy.varModel.model.ContainableModelElement
getNameSpace, getParent, getProject, getQualifiedName, getTopLevelParent, isTopLevel, setParentMethods inherited from class net.ssehub.easy.varModel.model.ModelElement
findAttribute, getComment, getName, getUniqueName, isTransparent, setComment, setName, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.ssehub.easy.varModel.model.datatypes.IDatatype
getName, getNameSpace, getQualifiedName, getUniqueNameMethods inherited from interface net.ssehub.easy.varModel.model.IModelElement
getComment, getName, getNameSpace, getParent, getQualifiedName, getUniqueName, isTransparent, setCommentMethods inherited from interface net.ssehub.easy.varModel.model.datatypes.IResolutionScope
getName, getParent
-
Field Details
-
DTYPE
-
TYPE
This constant represents the common type of all compounds. Each specific compound type is assignable to this type. -
TYPE_OF
-
EQUALS
-
NOTEQUALS
-
NOTEQUALS_ALIAS
-
ASSIGNMENT
-
IS_DEFINED
-
IF_DEFINED
-
COPY
-
isAbstract
private boolean isAbstract -
refines
-
container
-
-
Constructor Details
-
Compound
private Compound()Creates the singleton instance forTYPE. -
Compound
Constructor for a non-abstract compound.- Parameters:
name- name of the compoundparent- the object, in which this specific one is embedded
-
Compound
Constructor for a non-abstract (potentially refined) compound. [convenience]- Parameters:
name- name of the compoundparent- the object, in which this specific one is embeddedrefines- the super compound (may be null if there is no refinement).
-
Compound
Constructor for a non-abstract (potentially refined) compound.- Parameters:
name- name of the compoundparent- the object, in which this specific one is embeddedrefines- the super compounds (may be null if there is no refinement, no entry must be null).
-
Compound
Constructor for a (potentially abstract, refined) compound. [convenience]- Parameters:
name- name of the compoundparent- the object, in which this specific one is embeddedisAbstract- whether this compound is abstractrefines- the super compound (may be null if there is no refinement)
-
Compound
Constructor for a (potentially abstract, refined) compound.- Parameters:
name- name of the compoundparent- the object, in which this specific one is embeddedisAbstract- whether this compound is abstractrefines- the super compound(s) (may be null if there is no refinement, no entry must be null)
-
-
Method Details
-
setRefines
Setter for the parent/ super compound of a refinement. This method is for incremental build during parsing a IVML file.- Parameters:
refines- The super/parent compounds of this compound (may be null, no entry must be null).
-
getImportsCount
public int getImportsCount()Description copied from interface:IResolutionScopeReturns the number of imports.- Specified by:
getImportsCountin interfaceIResolutionScope- Returns:
- the number of imports
-
getImport
Description copied from interface:IResolutionScopeReturns the project import specified byindex.- Specified by:
getImportin interfaceIResolutionScope- Parameters:
index- a 0-based index specifying the import to be returned- Returns:
- the project import
-
hasInterfaces
public boolean hasInterfaces()Description copied from interface:IResolutionScopeReturns whether this scope has interfaces.- Specified by:
hasInterfacesin interfaceIResolutionScope- Returns:
trueif it has interfaces,falseelse
-
isInterface
public boolean isInterface()Description copied from interface:IResolutionScopeReturns whether this scope is an interfaces.- Specified by:
isInterfacein interfaceIResolutionScope- Returns:
trueif it is an interface,falseelse
-
getRefinesCount
public int getRefinesCount()The number of refines.- Returns:
- the number of refines
-
getRefines
Returns the compound which is refined by this compound.- Parameters:
index- the index of the refined compound to return- Returns:
- the refined compound
- Throws:
IndexOutOfBoundsException- ifindex < 0 || index>=getRefinesCount()
-
accept
Accept method for the visitor.- Specified by:
acceptin interfaceIModelElement- Parameters:
visitor- The visitor, which should process this model element.
-
accept
Accepts a specialized visitor for creating a textual representation of the identity of this type.- Specified by:
acceptin interfaceIDatatypeVisitable- Overrides:
acceptin classContainableModelElement- Parameters:
visitor- the visitor to accept
-
isAssignableFrom
Determines if the data type represented by this object is either the same as, or is a supertype oftype.- Specified by:
isAssignableFromin interfaceIDatatype- Overrides:
isAssignableFromin classCustomDatatype- Parameters:
type- the type being checked- Returns:
trueif this type is either the same or a supertype oftype,trueelse
-
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
-
containsByNameRefines
Returns whethernameis already contained in this or a refined compound.- Parameters:
name- the name of the element- Returns:
truefor contained,falseelse
-
isRefinedFrom
Whether this compound is directly or indirectly refined fromcmp.- Parameters:
cmp- the cmp to look fortransitive- whether refines of refines shall be considered- Returns:
trueif this compound is directly or indirectly refined fromcmp
-
getElementCount
public int getElementCount()Description copied from interface:IResolutionScopeReturns the number of contained elements.- Specified by:
getElementCountin interfaceIDecisionVariableContainer- Specified by:
getElementCountin interfaceIResolutionScope- Returns:
- the number of contained elements
-
getElement
Description copied from interface:IResolutionScopeReturns a contained model element specified byindex.- Specified by:
getElementin interfaceIDecisionVariableContainer- Specified by:
getElementin interfaceIResolutionScope- Parameters:
index- a 0-based index specifying the operation to be returned- Returns:
- the contained element
-
getInheritedElementCount
public int getInheritedElementCount()Same behavior asgetElementCount(), but also considers inherited elements if this compound is a refinement of another compound.- Returns:
- The number of contained elements
-
getInheritedElement
Same behavior asgetElement(int)but also considers inherited elements if this compound is a refinement of another compound.- Parameters:
index- a 0-based index specifying the nested element to be returned, inherited elements come first, elements of this compound at the end- Returns:
- the contained element
- Throws:
IndexOutOfBoundsException- ifindex<0 || index>=getElementCount()
-
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
-
getElement
Description copied from interface:IResolutionScopeReturns a contained model element specified by itsname.- Specified by:
getElementin interfaceIDecisionVariableContainer- Specified by:
getElementin interfaceIResolutionScope- Parameters:
name- the qualified or unqualified name to search for- Returns:
- the related element or null if no such element is known
-
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)
-
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
-
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
-
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()Description copied from interface:IDecisionVariableContainerReturns 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
-
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
-
add
Description copied from interface:IDecisionVariableContainerAdds a nested assignment.- Specified by:
addin interfaceIDecisionVariableContainer- Parameters:
assignment- the assignment which should be added
-
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
-
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
-
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
-
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
-
isAbstract
public boolean isAbstract()Returns whether this compound is abstract, i.e., whether it can be instantiated.- Returns:
trueif this compound is abstract,falseelse
-
addConstraint
Description copied from interface:IConstraintHolderAdds a constraint.- Specified by:
addConstraintin interfaceIConstraintHolder- Parameters:
constraint- the constraint to be added
-
removeConstraint
Removes the specified model element from this compound (if it exists).- Parameters:
element- TheConstraint,DecisionVariableDeclaration, orAttributeAssignmentto remove. If null nothing will happen.- Returns:
trueif the model element was part of this compound and was removed successfully.
-
add
Description copied from interface:IDecisionVariableContaineradds a nested evaluation block.- Specified by:
addin interfaceIDecisionVariableContainer- Parameters:
eval- the eval block
-
containsByName
Description copied from interface:IDecisionVariableContainerReturns 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
-
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
-
getRefinesDistanceTo
Determines the (absolute) refinement distance from this tocmpconsidering this orcmpas alternative bases to search the hierarchy for.- Parameters:
cmp- the compound to determine the distance to- Returns:
- the (absolute) refines distance between this and
cmp,0for the same,-1for no common refinement hierarchy
-
getRefinesDistanceTo
Determines the (absolute) refinement distance from this tocmpoptionally considering this orcmpas alternative bases to search the hierarchy for.- Parameters:
cmp- the compound to determine the distance tocheckOpposite- if also the distance betweencmpand this shall be considered as result (top-level non-recursive call)- Returns:
- the (absolute) refines distance between this and
cmp,0for the same,-1for no common refinement hierarchy
-
findRefinesDistanceTo
Iterates overgetRefines(int)to identify the refines distance from this tocmpusingresas initial result. No search is performed ifresis not negative, i.e., already a distance was determined.- Parameters:
res- the initial result to start withcmp- the compound to search the refines hierarchy in a recursive manner- Returns:
- the refines distance,
0for the same,-1for no common refinement hierarchy
-
allImplementing
Finds all implementing compound types for this compound searching withinscopeand transitive imports.- Parameters:
scope- the scope to search for- Returns:
- the implementing compound types including this
- See Also:
-
implementingNonAbstract
Finds the implementing non-abstract types for this compound, i.e., the ones that may instantiate this compound. Searches withinscopeand transitive imports.- Parameters:
scope- the scope to search for- Returns:
- the implementing non-abstract compound types considering this
- See Also:
-
pruneAbstract
Prunes abstract compounds fromcompounds.- Parameters:
compounds- the compounds to consider (may be null, the the result is also null)- Returns:
compoundswithout abstract compounds (modifiescompounds)
-
pruneNonAbstract
Prunes non-abstract compounds fromcompounds.- Parameters:
compounds- the compounds to consider (may be null, the the result is also null)- Returns:
compoundswithout non-abstract compounds (modifiescompounds)
-
prune
Prunes fromcompounds.- Parameters:
compounds- the compounds to consider (may be null, the the result is also null)pruneAbstract- iftrueprune abstract compounds, iffalseprune non-abstract compounds- Returns:
compoundswithout those to be pruned (modifiescompounds)
-
closestRefining
Returns the compounds fromcompoundsthat have minimumrefines distanceto this.- Parameters:
compounds- the compounds to analyze- Returns:
- the selected compounds, may be empty
- See Also:
-