Package com.nomagic.magicdraw.uml2
Class Elements
java.lang.Object
com.nomagic.magicdraw.uml2.Elements
Convenient static methods to work with Elements.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Collection<Class<? extends Element>>
Relationship like classes -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
dispose
(Collection<? extends Element> elements) Dispose all elements in the given collection.static <T extends Element>
TfindOwnerOfStrictType
(Element element, Class<T> ownerType) Finds owner of an element of a specific class type.static <T extends Element>
TfindOwnerOfStrictTypeIncludingItself
(Element element, Class<T> ownerType) Finds owner of an element of a specific class type.static <T extends Element>
TfindOwnerOfType
(Element element, Class<? extends T> ownerType) Searches for first direct or indirect owner of the given type among owners of the given element.static <T extends Element>
TfindOwnerOfTypeIncludingItself
(Element element, Class<? extends T> ownerType) Searches for first direct or indirect owner of the given type among owners of the given element.static Element
getClientElement
(Element relationship) Get client of the relationship.static String
getComment
(Element element) Returns documentation of given element.static Comment
getCommentElement
(Element element) Returns documentation Comment for this Element.static Comment
getCommentElement
(Element element, Collection<Comment> commentOfAnnotatedElement) static Comment
getCommentElementOrCreate
(Element element) Returns documentation Comment for this element.static List<NamedElement>
getDependentClients
(NamedElement element, Class<? extends Dependency> dependencyClass) Collects elements those are connected with Dependencies as clients with a given elementstatic List<NamedElement>
getDependentSuppliers
(NamedElement element, Class<? extends Dependency> dependencyClass) Collects elements those are connected with Dependencies as suppliers with a given elementstatic String
getMultiplicity
(MultiplicityElement element) Returns multiplicity string for specified multiplicity element.static String
getName
(BaseElement element) Return a name of given elementstatic Element
getOppositeEnd
(Element relationship, Element end) Return opposite relationship endstatic Element
getSupplierElement
(Element relationship) Get supplier of the relationship.static Element
getSupplierElement
(Element relationship, boolean takeUserFriendly) Get supplier of the relationship.static boolean
hasParentIn
(Collection<? extends BaseElement> possibleParents, BaseElement possibleChild) Checks if given object is child of any of the given parent objects.static boolean
isChildOf
(Collection<? extends Element> owners, Element child) Is given element is child of one of the given owners.static boolean
isDocumentationComment
(Comment comment) Checks if given comment used for storing element documentation.static boolean
isMultiplicityMany
(int value) Check if given value is 'many' -it is more than 1 or is unlimited (-1).static boolean
isParentOf
(BaseElement possibleParent, BaseElement possibleChild) Checks if given object is child of given parent object.static boolean
isParentOf
(Element possibleParent, Element possibleChild) Checks if given object is child of given parent object.static boolean
isRelationship
(Element element) Check if given element is a relationship.static boolean
isRelationship
(Class type) Check if given class is relationshipstatic boolean
isRelationshipAlwaysInClient
(Class relationshipClass) Check if relationship if given class type is always owned by a client elementstatic String[]
parseMultiplicityString
(String expression) Parses multiplicity of form 1..* and return array of 2 string [lower, upper] representing boundsstatic void
setClientElement
(Element relationship, Element client) Set client of the relationship.static void
setComment
(Element element, String documentation) Set comment (documentation) for element.static void
setCommentElement
(Element element, Comment comment) Set given Comment as documentation of given Element.static void
setMultiplicity
(int lower, int upper, MultiplicityElement element) Set multiplicity to elementstatic void
setMultiplicity
(String expression, MultiplicityElement element) Sets multiplicity for specified multiplicity element.static void
setSupplierElement
(Element relationship, Element supplier) Set supplier of the relationship.
-
Field Details
-
RELATIONSHIP_TYPES
Relationship like classes
-
-
Constructor Details
-
Elements
public Elements()
-
-
Method Details
-
hasParentIn
public static boolean hasParentIn(Collection<? extends BaseElement> possibleParents, BaseElement possibleChild) Checks if given object is child of any of the given parent objects.- Parameters:
possibleChild
- possible childpossibleParents
- possible parents- Returns:
- true if the given possibleChild is a child of any of given possibleParents
-
isParentOf
Checks if given object is child of given parent object.- Parameters:
possibleChild
- possible childpossibleParent
- possible parent- Returns:
- true if possibleChild is child of possibleParent.
-
isParentOf
Checks if given object is child of given parent object.- Parameters:
possibleChild
- possible childpossibleParent
- possible parent- Returns:
- true if possibleChild is child of possibleParent
-
isChildOf
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
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 documentationdocumentation
- documentation text
-
getComment
Returns documentation of given element.- Parameters:
element
- element to get documentation.- Returns:
- element documentation.
-
getCommentElementOrCreate
Returns documentation Comment for this element. If Comment is not set yet, new Comment is created.- Parameters:
element
- element- Returns:
- comment
-
getCommentElement
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, Collection<Comment> commentOfAnnotatedElement) -
isDocumentationComment
Checks if given comment used for storing element documentation.- Parameters:
comment
- comment- Returns:
- true if comment is used as documentation
-
setCommentElement
Set given Comment as documentation of given Element.- Parameters:
element
- elementcomment
- comment
-
findOwnerOfTypeIncludingItself
@CheckForNull public static <T extends Element> T findOwnerOfTypeIncludingItself(@CheckForNull Element element, 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
- elementownerType
- 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, 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, 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 foundownerType
- 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, 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 foundownerType
- class type of the owner- Returns:
- found owner or null if owner of a specific type was not found
-
setMultiplicity
Sets multiplicity for specified multiplicity element.- Parameters:
expression
- values that make sense: "0", "1", "*", "0..*", "1..*", "0..1". If null, multiplicity will become unspecifiedelement
- multiplicity element.
-
parseMultiplicityString
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
Set multiplicity to element- Parameters:
lower
- loverupper
- upperelement
- element
-
dispose
Dispose all elements in the given collection.- Parameters:
elements
- elements to dispose
-
isRelationship
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
Check if given class is relationship- Parameters:
type
- given class- Returns:
- true if relationship
-
isRelationshipAlwaysInClient
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
Get client of the relationship.- Parameters:
relationship
- relationship model element.- Returns:
- client of given relationship
-
getSupplierElement
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
Set client of the relationship.- Parameters:
relationship
- relationship model element.client
- client element that will be set to specified relationship model element.
-
setSupplierElement
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 List<NamedElement> getDependentClients(NamedElement element, Class<? extends Dependency> dependencyClass) Collects elements those are connected with Dependencies as clients with a given element- Parameters:
element
- the given elementdependencyClass
- dependency class to filter- Returns:
- list of dependent client elements
-
getDependentSuppliers
public static List<NamedElement> getDependentSuppliers(NamedElement element, Class<? extends Dependency> dependencyClass) Collects elements those are connected with Dependencies as suppliers with a given element- Parameters:
element
- the given elementdependencyClass
- dependency class to filter- Returns:
- list of dependent supplier elements
-
getMultiplicity
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
Return a name of given element- Parameters:
element
- name- Returns:
- name of give element
-
getOppositeEnd
Return opposite relationship end- Parameters:
relationship
- relationshipend
- end- Returns:
- opposite end
-