All Implemented Interfaces:
IContainableElementsSorter, IDatatype, IDatatypeVisitable, IResolutionScope, IConstraintHolder, IDecisionVariableContainer, IModelElement

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 Details

    • DTYPE

      static final DelegatingType DTYPE
    • TYPE

      public static final IDatatype TYPE
      This constant represents the common type of all compounds. Each specific compound type is assignable to this type.
    • TYPE_OF

      public static final Operation TYPE_OF
    • EQUALS

      public static final Operation EQUALS
    • NOTEQUALS

      public static final Operation NOTEQUALS
    • NOTEQUALS_ALIAS

      public static final Operation NOTEQUALS_ALIAS
    • ASSIGNMENT

      public static final Operation ASSIGNMENT
    • IS_DEFINED

      public static final Operation IS_DEFINED
    • IF_DEFINED

      public static final Operation IF_DEFINED
    • COPY

      public static final Operation COPY
    • isAbstract

      private boolean isAbstract
    • refines

      private Compound[] refines
    • container

      private BasicDecisionVariableContainer container
  • Constructor Details

    • Compound

      private Compound()
      Creates the singleton instance for TYPE.
    • Compound

      public Compound(String name, ModelElement parent)
      Constructor for a non-abstract compound.
      Parameters:
      name - name of the compound
      parent - the object, in which this specific one is embedded
    • Compound

      public Compound(String name, ModelElement parent, Compound refines)
      Constructor for a non-abstract (potentially refined) compound. [convenience]
      Parameters:
      name - name of the compound
      parent - the object, in which this specific one is embedded
      refines - the super compound (may be null if there is no refinement).
    • Compound

      public Compound(String name, ModelElement parent, Compound... refines)
      Constructor for a non-abstract (potentially refined) compound.
      Parameters:
      name - name of the compound
      parent - the object, in which this specific one is embedded
      refines - the super compounds (may be null if there is no refinement, no entry must be null).
    • Compound

      public Compound(String name, ModelElement parent, boolean isAbstract, Compound refines)
      Constructor for a (potentially abstract, refined) compound. [convenience]
      Parameters:
      name - name of the compound
      parent - the object, in which this specific one is embedded
      isAbstract - whether this compound is abstract
      refines - the super compound (may be null if there is no refinement)
    • Compound

      public Compound(String name, ModelElement parent, boolean isAbstract, Compound... refines)
      Constructor for a (potentially abstract, refined) compound.
      Parameters:
      name - name of the compound
      parent - the object, in which this specific one is embedded
      isAbstract - whether this compound is abstract
      refines - the super compound(s) (may be null if there is no refinement, no entry must be null)
  • Method Details

    • setRefines

      public void setRefines(Compound[] refines)
      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: IResolutionScope
      Returns the number of imports.
      Specified by:
      getImportsCount in interface IResolutionScope
      Returns:
      the number of imports
    • getImport

      public ProjectImport getImport(int index)
      Description copied from interface: IResolutionScope
      Returns the project import specified by index.
      Specified by:
      getImport in interface IResolutionScope
      Parameters:
      index - a 0-based index specifying the import to be returned
      Returns:
      the project import
    • hasInterfaces

      public boolean hasInterfaces()
      Description copied from interface: IResolutionScope
      Returns whether this scope has interfaces.
      Specified by:
      hasInterfaces in interface IResolutionScope
      Returns:
      true if it has interfaces, false else
    • isInterface

      public boolean isInterface()
      Description copied from interface: IResolutionScope
      Returns whether this scope is an interfaces.
      Specified by:
      isInterface in interface IResolutionScope
      Returns:
      true if it is an interface, false else
    • getRefinesCount

      public int getRefinesCount()
      The number of refines.
      Returns:
      the number of refines
    • getRefines

      public Compound getRefines(int index) throws IndexOutOfBoundsException
      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 - if index < 0 || index>=getRefinesCount()
    • accept

      public void accept(IModelVisitor visitor)
      Accept method for the visitor.
      Specified by:
      accept in interface IModelElement
      Parameters:
      visitor - The visitor, which should process this model element.
    • accept

      public void accept(IDatatypeVisitor visitor)
      Accepts a specialized visitor for creating a textual representation of the identity of this type.
      Specified by:
      accept in interface IDatatypeVisitable
      Overrides:
      accept in class ContainableModelElement
      Parameters:
      visitor - the visitor to accept
    • isAssignableFrom

      public boolean isAssignableFrom(IDatatype type)
      Determines if the data type represented by this object is either the same as, or is a supertype of type.
      Specified by:
      isAssignableFrom in interface IDatatype
      Overrides:
      isAssignableFrom in class CustomDatatype
      Parameters:
      type - the type being checked
      Returns:
      true if this type is either the same or a supertype of type, true else
    • add

      public boolean add(DecisionVariableDeclaration elem)
      Description copied from interface: IDecisionVariableContainer
      Method to add an object to the elements list of the project.
      Specified by:
      add in interface IDecisionVariableContainer
      Parameters:
      elem - which should be added
      Returns:
      true if the addition was successful, false else due to duplicated variable declaration
    • containsByNameRefines

      public boolean containsByNameRefines(String name)
      Returns whether name is already contained in this or a refined compound.
      Parameters:
      name - the name of the element
      Returns:
      true for contained, false else
    • isRefinedFrom

      public boolean isRefinedFrom(Compound cmp, boolean transitive)
      Whether this compound is directly or indirectly refined from cmp.
      Parameters:
      cmp - the cmp to look for
      transitive - whether refines of refines shall be considered
      Returns:
      true if this compound is directly or indirectly refined from cmp
    • getElementCount

      public int getElementCount()
      Description copied from interface: IResolutionScope
      Returns the number of contained elements.
      Specified by:
      getElementCount in interface IDecisionVariableContainer
      Specified by:
      getElementCount in interface IResolutionScope
      Returns:
      the number of contained elements
    • getElement

      public DecisionVariableDeclaration getElement(int index)
      Description copied from interface: IResolutionScope
      Returns a contained model element specified by index.
      Specified by:
      getElement in interface IDecisionVariableContainer
      Specified by:
      getElement in interface IResolutionScope
      Parameters:
      index - a 0-based index specifying the operation to be returned
      Returns:
      the contained element
    • getInheritedElementCount

      public int getInheritedElementCount()
      Same behavior as getElementCount(), but also considers inherited elements if this compound is a refinement of another compound.
      Returns:
      The number of contained elements
    • getInheritedElement

      public DecisionVariableDeclaration getInheritedElement(int index)
      Same behavior as getElement(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 - if index<0 || index>=getElementCount()
    • contains

      public boolean contains(DecisionVariableDeclaration var)
      Description copied from interface: IDecisionVariableContainer
      Returns whether this element contains var.
      Specified by:
      contains in interface IDecisionVariableContainer
      Parameters:
      var - the variable declaration to search for
      Returns:
      true if found, false else
    • getElement

      public DecisionVariableDeclaration getElement(String name)
      Description copied from interface: IResolutionScope
      Returns a contained model element specified by its name.
      Specified by:
      getElement in interface IDecisionVariableContainer
      Specified by:
      getElement in interface IResolutionScope
      Parameters:
      name - the qualified or unqualified name to search for
      Returns:
      the related element or null if no such element is known
    • addConstraint

      public void addConstraint(Constraint constraint, boolean internal)
      Description copied from interface: IDecisionVariableContainer
      Adds a constraint.
      Specified by:
      addConstraint in interface IDecisionVariableContainer
      Parameters:
      constraint - the constraint to be added
      internal - whether the constraint is internally created while building up the model (ignored)
    • getConstraintsCount

      public int getConstraintsCount()
      Description copied from interface: IDecisionVariableContainer
      Returns the number of contained constraints.
      Specified by:
      getConstraintsCount in interface IDecisionVariableContainer
      Returns:
      the number of constraints
    • getConstraint

      public Constraint getConstraint(int index)
      Description copied from interface: IDecisionVariableContainer
      Returns the specified contained constraint.
      Specified by:
      getConstraint in interface IDecisionVariableContainer
      Parameters:
      index - the index of the constraint to be returned
      Returns:
      the specified constraint
    • sortContainedElements

      public void sortContainedElements(Comparator<ContainableModelElement> comp)
      Description copied from interface: IContainableElementsSorter
      Sorts 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:
      sortContainedElements in interface IContainableElementsSorter
      Parameters:
      comp - a comparator which fulfills the requirements above
    • getModelElement

      public ContainableModelElement getModelElement(int index)
      Description copied from interface: IDecisionVariableContainer
      Returns a contained model element specified by index. 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:
      getModelElement in interface IDecisionVariableContainer
      Parameters:
      index - a 0-based index specifying the operation to be returned
      Returns:
      the contained element
    • getModelElementCount

      public int getModelElementCount()
      Description copied from interface: IDecisionVariableContainer
      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:
      getModelElementCount in interface IDecisionVariableContainer
      Returns:
      the number of contained elements
    • add

      public void add(Comment comment)
      Description copied from interface: IDecisionVariableContainer
      Adds a comment to the list of contained elements.
      Specified by:
      add in interface IDecisionVariableContainer
      Parameters:
      comment - the comment to be added
    • add

      public void add(AttributeAssignment assignment)
      Description copied from interface: IDecisionVariableContainer
      Adds a nested assignment.
      Specified by:
      add in interface IDecisionVariableContainer
      Parameters:
      assignment - the assignment which should be added
    • getAssignmentCount

      public int getAssignmentCount()
      Description copied from interface: IDecisionVariableContainer
      Returns the number of assignments.
      Specified by:
      getAssignmentCount in interface IDecisionVariableContainer
      Returns:
      the number of assignments
    • getAssignment

      public AttributeAssignment getAssignment(int index)
      Description copied from interface: IDecisionVariableContainer
      Returns the assignment specified by index.
      Specified by:
      getAssignment in interface IDecisionVariableContainer
      Parameters:
      index - a 0-based index specifying the element to be returned
      Returns:
      the assignment
    • propagateAttribute

      public boolean propagateAttribute(Attribute attribute)
      Description copied from interface: IModelElement
      Propagates an attribute application from the parent to this element or contained elements. This may imply the creation of clones of the given attribute.
      Specified by:
      propagateAttribute in interface IModelElement
      Overrides:
      propagateAttribute in class ModelElement
      Parameters:
      attribute - the attribute to be propagated
      Returns:
      true if the operation was successful, false if the element is about being attributed multiple times with the same attribute
    • getRealizingCount

      public int getRealizingCount()
      Description copied from interface: IDecisionVariableContainer
      Returns the number of realizing constraints. Please note that these constraints are derived and not originally specified in the input IVML model.
      Specified by:
      getRealizingCount in interface IDecisionVariableContainer
      Returns:
      the number of constraints
    • getRealizing

      public Constraint getRealizing(int index)
      Description copied from interface: IDecisionVariableContainer
      Returns the specified realizing constraint. Please note that these constraints are derived and not originally specified in the input IVML model.
      Specified by:
      getRealizing in interface IDecisionVariableContainer
      Parameters:
      index - the index of the constraint to be returned
      Returns:
      the specified constraint
    • getDeclarationCount

      public int getDeclarationCount()
      Description copied from interface: IDecisionVariableContainer
      Returns the number of all nested DecisionVariableDeclarations including nested DecisionVariableDeclarations of AttributeAssignments.
      Specified by:
      getDeclarationCount in interface IDecisionVariableContainer
      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: IDecisionVariableContainer
      Returns the specified DecisionVariableDeclaration.
      Specified by:
      getDeclaration in interface IDecisionVariableContainer
      Parameters:
      index - the index of the DecisionVariableDeclaration to be returned
      Returns:
      the specified DecisionVariableDeclaration
    • isAbstract

      public boolean isAbstract()
      Returns whether this compound is abstract, i.e., whether it can be instantiated.
      Returns:
      true if this compound is abstract, false else
    • addConstraint

      public void addConstraint(Constraint constraint)
      Description copied from interface: IConstraintHolder
      Adds a constraint.
      Specified by:
      addConstraint in interface IConstraintHolder
      Parameters:
      constraint - the constraint to be added
    • removeConstraint

      public boolean removeConstraint(ContainableModelElement element)
      Removes the specified model element from this compound (if it exists).
      Parameters:
      element - The Constraint, DecisionVariableDeclaration, or AttributeAssignment to remove. If null nothing will happen.
      Returns:
      true if the model element was part of this compound and was removed successfully.
    • add

      public void add(EvaluationBlock eval)
      Description copied from interface: IDecisionVariableContainer
      adds a nested evaluation block.
      Specified by:
      add in interface IDecisionVariableContainer
      Parameters:
      eval - the eval block
    • containsByName

      public boolean containsByName(String name)
      Description copied from interface: IDecisionVariableContainer
      Returns whether this project contains an element and its name.
      Specified by:
      containsByName in interface IDecisionVariableContainer
      Parameters:
      name - the name to search for
      Returns:
      true if this project contains the specified element, false else
    • forceUpdate

      public void forceUpdate()
      Description copied from interface: IDecisionVariableContainer
      Forces the IDecisionVariableContainer to update cached lists of nested DecisionVariableDeclarations. This is only necessary if multiple IDecisionVariableContainer are 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:
      forceUpdate in interface IDecisionVariableContainer
    • getRefinesDistanceTo

      public int getRefinesDistanceTo(Compound cmp)
      Determines the (absolute) refinement distance from this to cmp considering this or cmp as 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, 0 for the same, -1 for no common refinement hierarchy
    • getRefinesDistanceTo

      private int getRefinesDistanceTo(Compound cmp, boolean checkOpposite)
      Determines the (absolute) refinement distance from this to cmp optionally considering this or cmp as alternative bases to search the hierarchy for.
      Parameters:
      cmp - the compound to determine the distance to
      checkOpposite - if also the distance between cmp and this shall be considered as result (top-level non-recursive call)
      Returns:
      the (absolute) refines distance between this and cmp, 0 for the same, -1 for no common refinement hierarchy
    • findRefinesDistanceTo

      private int findRefinesDistanceTo(int res, Compound cmp)
      Iterates over getRefines(int) to identify the refines distance from this to cmp using res as initial result. No search is performed if res is not negative, i.e., already a distance was determined.
      Parameters:
      res - the initial result to start with
      cmp - the compound to search the refines hierarchy in a recursive manner
      Returns:
      the refines distance, 0 for the same, -1 for no common refinement hierarchy
    • allImplementing

      public Collection<Compound> allImplementing(IResolutionScope scope)
      Finds all implementing compound types for this compound searching within scope and transitive imports.
      Parameters:
      scope - the scope to search for
      Returns:
      the implementing compound types including this
      See Also:
    • implementingNonAbstract

      public Collection<Compound> implementingNonAbstract(IResolutionScope scope)
      Finds the implementing non-abstract types for this compound, i.e., the ones that may instantiate this compound. Searches within scope and transitive imports.
      Parameters:
      scope - the scope to search for
      Returns:
      the implementing non-abstract compound types considering this
      See Also:
    • pruneAbstract

      public static Collection<Compound> pruneAbstract(Collection<Compound> compounds)
      Prunes abstract compounds from compounds.
      Parameters:
      compounds - the compounds to consider (may be null, the the result is also null)
      Returns:
      compounds without abstract compounds (modifies compounds)
    • pruneNonAbstract

      public static Collection<Compound> pruneNonAbstract(Collection<Compound> compounds)
      Prunes non-abstract compounds from compounds.
      Parameters:
      compounds - the compounds to consider (may be null, the the result is also null)
      Returns:
      compounds without non-abstract compounds (modifies compounds)
    • prune

      private static Collection<Compound> prune(Collection<Compound> compounds, boolean pruneAbstract)
      Prunes from compounds.
      Parameters:
      compounds - the compounds to consider (may be null, the the result is also null)
      pruneAbstract - if true prune abstract compounds, if false prune non-abstract compounds
      Returns:
      compounds without those to be pruned (modifies compounds)
    • closestRefining

      public Collection<Compound> closestRefining(Collection<Compound> compounds)
      Returns the compounds from compounds that have minimum refines distance to this.
      Parameters:
      compounds - the compounds to analyze
      Returns:
      the selected compounds, may be empty
      See Also: