Class Elements


  • public class Elements
    extends java.lang.Object
    Convenient static methods to work with Elements.
    • Field Detail

      • RELATIONSHIP_TYPES

        public static final java.util.Collection<java.lang.Class<? extends Element>> RELATIONSHIP_TYPES
        Relationship like classes
    • Constructor Detail

      • Elements

        public Elements()
    • Method Detail

      • hasParentIn

        public static boolean hasParentIn​(java.util.Collection<? extends BaseElement> possibleParents,
                                          BaseElement possibleChild)
        Checks if given object is child of any of the given parent objects.
        Parameters:
        possibleChild - possible child
        possibleParents - possible parents
        Returns:
        true if the given possibleChild is a child of any of given possibleParents
      • isParentOf

        public static boolean isParentOf​(BaseElement possibleParent,
                                         BaseElement possibleChild)
        Checks if given object is child of given parent object.
        Parameters:
        possibleChild - possible child
        possibleParent - possible parent
        Returns:
        true if possibleChild is child of possibleParent.
      • isParentOf

        public static boolean isParentOf​(Element possibleParent,
                                         Element possibleChild)
        Checks if given object is child of given parent object.
        Parameters:
        possibleChild - possible child
        possibleParent - possible parent
        Returns:
        true if possibleChild is child of possibleParent
      • isChildOf

        public static boolean isChildOf​(java.util.Collection<? extends Element> owners,
                                        Element child)
        Is given element is child of one of the given owners.
        Parameters:
        owners - the owners to check.
        child - the child element to check owners for
        Returns:
        true if given child is child of some given owner.
      • setComment

        public static void setComment​(Element element,
                                      @CheckForNull
                                      java.lang.String documentation)
        Set comment (documentation) for element. Comment is set on the first element in owned comments collection. If documentation is null or empty string, removed the comment.
        Parameters:
        element - element to set documentation
        documentation - documentation text
      • getComment

        public static java.lang.String getComment​(Element element)
        Returns documentation of given element.
        Parameters:
        element - element to get documentation.
        Returns:
        element documentation.
      • getCommentElementOrCreate

        public static Comment getCommentElementOrCreate​(Element element)
        Returns documentation Comment for this element. If Comment is not set yet, new Comment is created.
        Parameters:
        element - element
        Returns:
        comment
      • getCommentElement

        @CheckForNull
        public static Comment getCommentElement​(Element element)
        Returns documentation Comment for this Element. If Comment is not set, returns null.
        Parameters:
        element - element
        Returns:
        comment
      • getCommentElement

        @CheckForNull
        public static Comment getCommentElement​(Element element,
                                                java.util.Collection<Comment> commentOfAnnotatedElement)
      • isDocumentationComment

        public static boolean isDocumentationComment​(Comment comment)
        Checks if given comment used for storing element documentation.
        Parameters:
        comment - comment
        Returns:
        true if comment is used as documentation
      • setCommentElement

        public static void setCommentElement​(Element element,
                                             Comment comment)
        Set given Comment as documentation of given Element.
        Parameters:
        element - element
        comment - comment
      • findOwnerOfTypeIncludingItself

        @CheckForNull
        public static <T extends Element> T findOwnerOfTypeIncludingItself​(@CheckForNull
                                                                           Element element,
                                                                           java.lang.Class<? extends T> ownerType)
        Searches for first direct or indirect owner of the given type among owners of the given element. Checks if the element itself is an instance of given ownerType. If yes, returns it, if no, looks for owner of given instance in all element's ownership hierarchy. If such owner does not exist, returns null.
        Parameters:
        element - element
        ownerType - the meta class of owner to find. Found owner must be instance of this class
        Returns:
        found owner or null
      • findOwnerOfType

        @CheckForNull
        public static <T extends Element> T findOwnerOfType​(@CheckForNull
                                                            Element element,
                                                            java.lang.Class<? extends T> ownerType)
        Searches for first direct or indirect owner of the given type among owners of the given element. Look for owner of given instance in all element's ownership hierarchy. If such owner does not exist, returns null.
        Parameters:
        element - element.
        ownerType - the meta class of owner to find. Found owner must be instance of this class.
        Returns:
        found owner or null.
      • findOwnerOfStrictTypeIncludingItself

        @CheckForNull
        public static <T extends Element> T findOwnerOfStrictTypeIncludingItself​(@CheckForNull
                                                                                 Element element,
                                                                                 java.lang.Class<T> ownerType)
        Finds owner of an element of a specific class type.
        Parameters:
        element - element for which owner of a specific type should be found
        ownerType - class type of the owner
        Returns:
        found owner or null if owner of a specific type was not found
      • findOwnerOfStrictType

        @CheckForNull
        public static <T extends Element> T findOwnerOfStrictType​(Element element,
                                                                  java.lang.Class<T> ownerType)
        Finds owner of an element of a specific class type.
        Parameters:
        element - element for which parent of a specific type should be found
        ownerType - class type of the owner
        Returns:
        found owner or null if owner of a specific type was not found
      • setMultiplicity

        public static void setMultiplicity​(@CheckForNull
                                           java.lang.String expression,
                                           MultiplicityElement element)
        Sets multiplicity for specified multiplicity element.
        Parameters:
        expression - values that make sense: "0", "1", "*", "0..*", "1..*", "0..1". If null, multiplicity will become unspecified
        element - multiplicity element.
      • parseMultiplicityString

        public static java.lang.String[] parseMultiplicityString​(java.lang.String expression)
        Parses multiplicity of form 1..* and return array of 2 string [lower, upper] representing bounds
        Parameters:
        expression - expression
      • isMultiplicityMany

        public static boolean isMultiplicityMany​(int value)
        Check if given value is 'many' -it is more than 1 or is unlimited (-1).
        Parameters:
        value - value
        Returns:
        true if value is many
      • setMultiplicity

        public static void setMultiplicity​(int lower,
                                           int upper,
                                           MultiplicityElement element)
        Set multiplicity to element
        Parameters:
        lower - lover
        upper - upper
        element - element
      • dispose

        public static void dispose​(java.util.Collection<? extends Element> elements)
        Dispose all elements in the given collection.
        Parameters:
        elements - elements to dispose
      • isRelationship

        public static boolean isRelationship​(@CheckForNull
                                             Element element)
        Check if given element is a relationship. MD treats Transition, ActivityEdge and InstanceSpecifications used as Links as relationships.
        Parameters:
        element - element
        Returns:
        true if element is relationship
      • isRelationship

        public static boolean isRelationship​(java.lang.Class type)
        Check if given class is relationship
        Parameters:
        type - given class
        Returns:
        true if relationship
      • isRelationshipAlwaysInClient

        public static boolean isRelationshipAlwaysInClient​(java.lang.Class relationshipClass)
        Check if relationship if given class type is always owned by a client element
        Parameters:
        relationshipClass - relationship class type
        Returns:
        return true if given relationship is always owned by client element
      • getClientElement

        @CheckForNull
        public static Element getClientElement​(Element relationship)
        Get client of the relationship.
        Parameters:
        relationship - relationship model element.
        Returns:
        client of given relationship
      • getSupplierElement

        @CheckForNull
        public static Element getSupplierElement​(Element relationship)
        Get supplier of the relationship.
        Parameters:
        relationship - relationship model element.
      • getSupplierElement

        @CheckForNull
        public static Element getSupplierElement​(Element relationship,
                                                 boolean takeUserFriendly)
        Get supplier of the relationship.
        Parameters:
        relationship - relationship model element.
        takeUserFriendly - take user friendly element in some cases (for example owning classifier instead of template signature)
      • setClientElement

        public static void setClientElement​(Element relationship,
                                            Element client)
        Set client of the relationship.
        Parameters:
        relationship - relationship model element.
        client - client element that will be set to specified relationship model element.
      • setSupplierElement

        public static void setSupplierElement​(Element relationship,
                                              Element supplier)
        Set supplier of the relationship.
        Parameters:
        relationship - relationship model element.
        supplier - supplier element that will be set to specified relationship model element.
      • getDependentClients

        public static java.util.List<NamedElement> getDependentClients​(NamedElement element,
                                                                       java.lang.Class<? extends Dependency> dependencyClass)
        Collects elements those are connected with Dependencies as clients with a given element
        Parameters:
        element - the given element
        dependencyClass - dependency class to filter
        Returns:
        list of dependent client elements
      • getDependentSuppliers

        public static java.util.List<NamedElement> getDependentSuppliers​(NamedElement element,
                                                                         java.lang.Class<? extends Dependency> dependencyClass)
        Collects elements those are connected with Dependencies as suppliers with a given element
        Parameters:
        element - the given element
        dependencyClass - dependency class to filter
        Returns:
        list of dependent supplier elements
      • getMultiplicity

        public static java.lang.String getMultiplicity​(MultiplicityElement element)
        Returns multiplicity string for specified multiplicity element.
        Parameters:
        element - multiplicity element.
        Returns:
        multiplicity expression : "0", "1", "*", "0..*", "1..*", "0..1". "" is returned if no multiplicity is set.
      • getName

        public static java.lang.String getName​(BaseElement element)
        Return a name of given element
        Parameters:
        element - name
        Returns:
        name of give element
      • getOppositeEnd

        @CheckForNull
        public static Element getOppositeEnd​(Element relationship,
                                             Element end)
        Return opposite relationship end
        Parameters:
        relationship - relationship
        end - end
        Returns:
        opposite end