Package com.nomagic.magicdraw.uml2
Class Elements
java.lang.Object
com.nomagic.magicdraw.uml2.Elements
Convenient static methods to work with Elements.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Collection<Class<? extends Element>>Relationship like classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddispose(Collection<? extends Element> elements) Dispose all elements in the given collection.static <T extends Element>
TfindOwnerOfStrictType(Element element, Class<T> ownerType) Finds an owner of an element of a specific class type.static <T extends Element>
TfindOwnerOfStrictTypeIncludingItself(Element element, Class<T> ownerType) Finds an owner of an element of a specific class type.static <T extends Element>
TfindOwnerOfType(Element element, Class<? extends T> ownerType) Searches for the 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 the first direct or indirect owner of the given type among owners of the given element.static ElementgetClientElement(Element relationship) Get a client of the relationship.static StringgetComment(Element element) Returns documentation of given element.static CommentgetCommentElement(Element element) Returns documentation Comment for this Element.static CommentgetCommentElement(Element element, Collection<Comment> commentOfAnnotatedElement) static CommentgetCommentElementOrCreate(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 StringgetMultiplicity(MultiplicityElement element) Returns multiplicity string for a specified multiplicity element.static StringgetName(BaseElement element) Return a name of given elementstatic ElementgetOppositeEnd(Element relationship, Element end) Return the opposite relationship endstatic ElementgetSupplierElement(Element relationship) Get supplier of the relationship.static ElementgetSupplierElement(Element relationship, boolean takeUserFriendly) Get supplier of the relationship.static booleanhasParentIn(Collection<? extends BaseElement> possibleParents, BaseElement possibleChild) Checks if given object is child of any of the given parent objects.static booleanisChildOf(Collection<? extends Element> owners, Element child) Is given element is child of one of the given owners.static booleanisDocumentationComment(Comment comment) Checks if given comment used for storing element documentation.static booleanisMultiplicityMany(int value) Check if given value is 'many' - it is more than 1 or is unlimited (-1).static booleanisParentOf(BaseElement possibleParent, BaseElement possibleChild) Checks if the given element is child of a given parent.static booleanisParentOf(Element possibleParent, Element possibleChild) Checks if the given element is child of a given parent.static booleanisRelationship(Element element) Check if a given element is a relationship.static booleanisRelationship(Class type) Check if given class is relationshipstatic booleanisRelationshipAlwaysInClient(Class relationshipClass) Check if the Relationship of the 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 voidsetClientElement(Element relationship, Element client) Set client of the relationship.static voidsetComment(Element element, String documentation) Set comment (documentation) for an element.static voidsetCommentElement(Element element, Comment comment) Set given Comment as documentation of given Element.static voidsetMultiplicity(int lower, int upper, MultiplicityElement element) Set multiplicity to an element.static voidsetMultiplicity(String expression, MultiplicityElement element) Sets multiplicity for a specified multiplicity element.static voidsetSupplierElement(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 the given element is child of a given parent.- Parameters:
possibleChild- possible childpossibleParent- possible parent- Returns:
- true if possibleChild is a child of possibleParent
-
isParentOf
Checks if the given element is child of a given parent.- Parameters:
possibleChild- possible childpossibleParent- possible parent- Returns:
- true if possibleChild is a 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 an element. Comment is set on the first element in an owned comments collection. If documentation is null or empty string, remove 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 the 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 an owner of given instance in all element's ownership hierarchy. If such an owner does not exist, returns null.- Parameters:
element- elementownerType- the metaclass of owner to find. Found owner must be an 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 the 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 an owner does not exist, returns null.- Parameters:
element- element.ownerType- the metaclass of owner to find. Found owner must be an 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 an 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 the owner of a specific type was not found
-
findOwnerOfStrictType
@CheckForNull public static <T extends Element> T findOwnerOfStrictType(Element element, Class<T> ownerType) Finds an 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 an owner of a specific type was not found
-
setMultiplicity
Sets multiplicity for a 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 an element.- Parameters:
lower- loverupper- upperelement- element
-
dispose
Dispose all elements in the given collection.- Parameters:
elements- elements to dispose
-
isRelationship
Check if a given element is a relationship. MD treats Transition, ActivityEdge and InstanceSpecifications used as Links as relationships.- Parameters:
element- element- Returns:
- true if an element is relationship
-
isRelationship
Check if given class is relationship- Parameters:
type- given class- Returns:
- true if relationship
-
isRelationshipAlwaysInClient
Check if the Relationship of the 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 a 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 a user-friendly element in some cases (for example, owning classifier instead of template signature)
-
setClientElement
Set client of the relationship.- Parameters:
relationship- relationship model elementclient- client element that will be set to a specified relationship model element
-
setSupplierElement
Set supplier of the relationship.- Parameters:
relationship- relationship model element.supplier- supplier element that will be set to a 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 a 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 an element
-
getOppositeEnd
Return the opposite relationship end- Parameters:
relationship- relationshipend- end- Returns:
- opposite end
-