Class CoreHelper

  • Direct Known Subclasses:
    ValueSpecificationHelper

    @OpenApiAll
    public class CoreHelper
    extends java.lang.Object
    Utility class for working with core UML elements
    • Constructor Detail

      • CoreHelper

        public CoreHelper()
    • 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
      • setComment

        public static void setComment​(Element element,
                                      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
      • setCommentElement

        public static void setCommentElement​(Element element,
                                             Comment comment)
        Set given Comment as documentation of given Element.
        Parameters:
        element - element
        comment - comment
      • 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
      • 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
      • dispose

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

        public static java.util.Collection<Element> getSupplierElements​(java.util.Collection<? extends Element> relationships)
        Collect suppliers of the given relationships
        Parameters:
        relationships - relationships
        Returns:
        suppliers of relationships
      • 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)
      • 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.
      • getClientElement

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

        public static java.util.Collection<Element> collectRelationships​(Element element,
                                                                         @CheckForNull
                                                                         java.util.function.Predicate<Element> predicate,
                                                                         boolean includeIndirect)
        Collects connected relations of specified element.
        Parameters:
        element - element
        predicate - filters collected relations
        includeIndirect - include indirect relations.
        Returns:
        relations that are connected to specified element.
      • collectRelationships

        public static java.util.Collection<Element> collectRelationships​(Element element)
        Collects connected relations of specified element.
        Parameters:
        element - element
        Returns:
        relations that are connected to specified element.
      • collectRelationshipsIncludeIndirect

        public static java.util.Collection<Element> collectRelationshipsIncludeIndirect​(Element element)
        Collects relations connected to specified element and some elements that are owned by that element. For example if element is action collects relations attached to it and it's input or output pins.
        Parameters:
        element - element
        Returns:
        relations that are connected to specified element and some elements that are owned by that element.
      • collectRelationshipsByType

        public static <T> java.util.Collection<T> collectRelationshipsByType​(Element element,
                                                                             java.lang.Class<T> relationType,
                                                                             boolean includeIndirect)
        Collects relations connected to specified element by relation class type.
        Parameters:
        element - element
        relationType - relation class type
        includeIndirect - should include indirect
        Returns:
        relations that are connected to specified element and some elements that are owned by that element.
      • 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.
      • getFirstMemberEnd

        public static Property getFirstMemberEnd​(Association assoc)
        Get first property member end of association.
        Parameters:
        assoc - association model element.
        Returns:
        first property member end of association.
      • getSecondMemberEnd

        public static Property getSecondMemberEnd​(Association assoc)
        Get second property member end of association.
        Parameters:
        assoc - association model element.
        Returns:
        second property member end of association.
      • areElementsEditable

        public static boolean areElementsEditable​(java.util.Collection<? extends Element> elements)
        Indicates if all elements in a collection are editable.
        Parameters:
        elements - a collection of elements to check
        Returns:
        true if all elements in a collection are editable, false otherwise
      • findAcceptableParentFor

        @CheckForNull
        public static Element findAcceptableParentFor​(Element element,
                                                      @CheckForNull
                                                      Element owner,
                                                      boolean checkPermissions)
        Goes up in the hierarchy of ownership until owner is found for a given element.
        Parameters:
        element - element
        owner - candidate for owner
        checkPermissions - check editing permissions
        Returns:
        found owner or null
      • findAcceptableParentInSameProjectPartOnly

        @CheckForNull
        private static Element findAcceptableParentInSameProjectPartOnly​(Element element,
                                                                         Element owner,
                                                                         boolean checkPermissions)
      • findAcceptableParentFor

        @CheckForNull
        public static Element findAcceptableParentFor​(Element element,
                                                      @CheckForNull
                                                      Element owner)
        Goes up in the hierarchy of ownership until owner is found for a given element. Checks owner editing permissions.
        Parameters:
        element - element
        owner - candidate for owner
        Returns:
        found owner or null
      • canMoveChildInto

        public static boolean canMoveChildInto​(Element parent,
                                               Element child)
        Returns true, if child can be moved to the parent. This can be done if parent can add such child and parent does not have other child with the same name for example.
      • canMoveChildInto

        public static boolean canMoveChildInto​(Element parent,
                                               Element child,
                                               boolean checkPermissions)
        Returns true, if child can be moved to the parent. This can be done if parent can add such child and parent does not have other child with the same name.
      • canAssignName

        public static boolean canAssignName​(java.lang.String name,
                                            NamedElement data,
                                            boolean symbol,
                                            boolean showError)
        Checks if given name can be assigned to the given Element.
        Parameters:
        name - a new name for Element
        data - a given Element
        symbol - true if changing symbol name
        showError - show error in UI in case of name conflict
        Returns:
        true if name can be changed
      • canAssignName

        public static boolean canAssignName​(java.lang.String name,
                                            NamedElement data,
                                            boolean symbol)
        Checks if given name can be assigned to the given ModelElement.
        Parameters:
        name - a new name for ModelElement.
        data - a given ModelElement.
        symbol - true if changing symbol name
        Returns:
        new name for ModelElement or null if given name can not be assigned to the ModelElement.
      • canAssignName

        public static boolean canAssignName​(java.lang.String name,
                                            NamedElement data,
                                            boolean symbol,
                                            boolean showError,
                                            boolean doNotCheckBehavioralFeature)
        Checks if given name can be assigned to the given ModelElement.
        Parameters:
        name - a new name for ModelElement.
        data - a given ModelElement.
        symbol - true if changing symbol name
        showError - show error in UI in case of name conflict
        Returns:
        new name for ModelElement or null if given name can not be assigned to the ModelElement.
      • 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
      • getOppositeEnd

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

        @CheckForNull
        public static Element findParent​(Element relationship,
                                         Element clientME,
                                         Element supplierME,
                                         @CheckForNull
                                         Element diagramParent)
        Looks for a possible parent for given relationship. Possible parent is calculated according client/supplier and relationship type.
        Parameters:
        relationship - relation for which possible parent should be found.
        clientME - relationship client element
        supplierME - relationship supplier element
        diagramParent - can be null if diagram is not important in context
        Returns:
        possible parent for a given relation if found, null otherwise.
      • findParent

        @CheckForNull
        public static Element findParent​(Element relationship,
                                         Element clientME,
                                         Element supplierME,
                                         @CheckForNull
                                         Element diagramParent,
                                         boolean checkPermissions)
        Looks for a possible parent for given relationship. Possible parent is calculated according client/supplier and relationship type.
        Parameters:
        relationship - relation for which possible parent should be found.
        clientME - relationship client element
        supplierME - relationship supplier element
        diagramParent - can be null if diagram is not important in context
        checkPermissions - indicates if permissions should be checked.
        Returns:
        possible parent for a given relation if found, null otherwise.
      • 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
      • isChildOf

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

        public static java.util.List<Element> getOwnedElementsIncludingAdditional​(Element element,
                                                                                  boolean includePureOwned)
        Return owned elements of the given Element including additional owned elements defined in DSL specification by additionalContentProperty.
        Parameters:
        includePureOwned - include element owned directly in ownedElement UML meta property
        Returns:
        owned elements of the given Element
      • getAdditionalElementsIterator

        public static java.util.Iterator<Element> getAdditionalElementsIterator​(Element element)
        Returns iterator of additional contained elements defined in DSL specification by additionalContentProperty.
        Returns:
        iterator of additional elements
      • getName

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

        public static boolean canAddChild​(BaseElement parent,
                                          BaseElement child)
        Checks if current element can add given element.
        Uses such rules: 1. current object is not the same as given object. 2. current object is not a child of given object. Current implementation returns false.
        Returns:
        true, if checking rules are true.
      • setConstraintText

        public static void setConstraintText​(Constraint constraint,
                                             java.lang.String text,
                                             boolean useName,
                                             boolean useExpression)
        Set text for constraint as name or as expression
        Parameters:
        constraint - constraint
        text - text
        useName - set text as name
        useExpression - set text as expression
      • setConstraintText

        public static void setConstraintText​(Constraint constraint,
                                             java.lang.String text,
                                             boolean useName,
                                             boolean useExpression,
                                             boolean showWarnings)
        Set text for constraint as name or as expression
        Parameters:
        constraint - constraint
        text - text
        useName - set text as name
        useExpression - set text as expression
        showWarnings - shows parsing warnings in UI if there were any
      • 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