Class Relationships
java.lang.Object
com.dassault_systemes.modeler.kerml.model.Relationships
Utility class to work with
Relationship-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <R extends Relationship>
voidaddOwnedNotImpliedRelationships(Element element, Class<R> clazz, List<? extends Element> targets) Appends new non‑implied relationships of the given type for the provided targets.static <R extends Relationship>
voideditNotImpliedOwnedRelationships(Element element, Class<R> clazz, List<? extends Element> targets, boolean set) Edits not implied owned relationships and their targets.static <R extends Relationship>
voideditOwnedRelationships(Element element, Class<R> clazz, List<? extends Element> targets, boolean set, boolean notImplied) Edits not implied owned relationships and their targets.static ElementfindOwnerFor(Relationship relationship, Element source, Element target, Element diagramOwner, boolean checkPermissions) Looks for a possible owner for a given Relationship.static ElementgetFirstOwnedRelatedElement(Relationship relationship) Returns the first owned related element of the given relationship.static <T extends Element>
TgetFirstOwnedRelatedElement(Relationship relationship, Class<T> clazz) Returns the first owned related element of the given relationship if it is an instance of the specified class.static Collection<Relationship> getIncoming(Element element) Returns all incoming relationships of the element.static <T extends Relationship>
Collection<T> getIncoming(Element element, Class<T> ofType) Returns all incoming relationships of the given type.static Collection<Relationship> getOutgoing(Element element) Returns all outgoing relationships of the element.static org.eclipse.emf.ecore.EClassgetOwningMembershipEClass(org.eclipse.emf.ecore.EClass childEClass, Namespace owner) Determines the appropriate owning membership EClass for a child element.static <T extends Relationship>
FeaturegetRelationshipSourceFeature(T relationship, Function<T, List<Feature>> endFeatureProvider) Returns the source feature of a relationship when exactly two features exist.static <T extends Relationship>
List<Feature> getRelationshipTargetFeature(T relationship, Function<T, List<Feature>> endFeatureProvider) Returns the target feature(s) of a relationship.static ElementgetSource(Relationship relationship) Returns the first source element of the relationship.static ElementgetTarget(Relationship relationship) Returns the first target element of the relationship.static booleanisAssociationOrConnector(Element element) Checks whether the element is an association or connector.static booleanisAssociationOrConnector(org.eclipse.emf.ecore.EClass eClass) Checks whether the EClass represents an association or connector.static booleanisMemberRelationship(Element element) Checks whether the element is a member relationship.static booleanisMemberRelationship(org.eclipse.emf.ecore.EClass eClass) Checks whether the EClass represents a member relationship.static booleanisNonMemberRelationship(Element element) Checks whether the element is a non‑member relationship.static booleanisNonMemberRelationship(org.eclipse.emf.ecore.EClass eClass) Checks whether the EClass represents a non‑member relationship.static <R extends Relationship>
voidsetOwnedNotImpliedRelationships(Element element, Class<R> clazz, List<? extends Element> targets) Replaces existing non‑implied relationships with new ones referencing the given targets.static voidsetSingleOwnedRelatedElement(Relationship relationship, Element ownedRelatedElement) Sets the single owned related element of the relationship.static booleansetSource(Relationship relationship, Element source) Sets the source of the relationship.static booleansetTarget(Relationship relationship, Element target) Sets the target of the relationship.static <T extends Relationship>
Stream<T> streamOfOwnedNotImpliedRelationship(Element element, Class<T> clazz, boolean isInstance) Returns a stream of owned, non‑implied relationships of the given type.static <T extends Relationship>
Stream<T> streamOfOwnedRelationship(Element element, Class<T> clazz, boolean isInstance) Retrieve matching owned relationships.
-
Constructor Details
-
Relationships
public Relationships()
-
-
Method Details
-
getFirstOwnedRelatedElement
Returns the first owned related element of the given relationship.- Parameters:
relationship- the relationship to inspect- Returns:
- the first owned related element, or null if none exist
-
getFirstOwnedRelatedElement
@CheckForNull public static <T extends Element> T getFirstOwnedRelatedElement(Relationship relationship, Class<T> clazz) Returns the first owned related element of the given relationship if it is an instance of the specified class.- Type Parameters:
T- element type- Parameters:
relationship- the relationship to inspectclazz- the expected element type- Returns:
- the first matching element, or null if none match
-
setSingleOwnedRelatedElement
public static void setSingleOwnedRelatedElement(Relationship relationship, @CheckForNull Element ownedRelatedElement) Sets the single owned related element of the relationship. Clears existing related elements before setting the new one.- Parameters:
relationship- the relationship to modifyownedRelatedElement- the element to set, or null to clear
-
streamOfOwnedRelationship
public static <T extends Relationship> Stream<T> streamOfOwnedRelationship(Element element, Class<T> clazz, boolean isInstance) Retrieve matching owned relationships.- Parameters:
element- elementclazz- relationship instance classisInstance- check "instanceOf" if true or strict equals if false- Returns:
- owned relationships matching given clazz
-
streamOfOwnedNotImpliedRelationship
public static <T extends Relationship> Stream<T> streamOfOwnedNotImpliedRelationship(Element element, Class<T> clazz, boolean isInstance) Returns a stream of owned, non‑implied relationships of the given type.- Type Parameters:
T- relationship type- Parameters:
element- the element whose relationships are inspectedclazz- the relationship classisInstance- whether to use instanceof or exact class match- Returns:
- stream of non‑implied relationships
-
addOwnedNotImpliedRelationships
public static <R extends Relationship> void addOwnedNotImpliedRelationships(Element element, Class<R> clazz, List<? extends Element> targets) Appends new non‑implied relationships of the given type for the provided targets.- Type Parameters:
R- relationship type- Parameters:
element- the element to modifyclazz- relationship classtargets- target elements
-
setOwnedNotImpliedRelationships
public static <R extends Relationship> void setOwnedNotImpliedRelationships(Element element, Class<R> clazz, List<? extends Element> targets) Replaces existing non‑implied relationships with new ones referencing the given targets.- Type Parameters:
R- relationship type- Parameters:
element- the element to modifyclazz- relationship classtargets- target elements
-
editNotImpliedOwnedRelationships
public static <R extends Relationship> void editNotImpliedOwnedRelationships(Element element, Class<R> clazz, List<? extends Element> targets, boolean set) Edits not implied owned relationships and their targets. If 'set' is true, then makes all not implied owned relationships to reference passed targets. Ensures that element has the same number of relationships of given class as there are targets. If there is a lack of relationships, they are created. Any excess relationships are disposed. If 'set' is false, passed targets are appended to the currently referenced. If some target is already referenced, it is skipped.- Type Parameters:
R- relationship class- Parameters:
element- whose owned relationships shall be edited?clazz- relationship classtargets- targetsset- should set pass targets as referenced elements or append them to the currently referenced elements
-
editOwnedRelationships
public static <R extends Relationship> void editOwnedRelationships(Element element, Class<R> clazz, List<? extends Element> targets, boolean set, boolean notImplied) Edits not implied owned relationships and their targets. If 'set' is true, then makes all not implied owned relationships to reference passed targets. Ensures that element has the same number of relationships of given class as there are targets. If there is a lack of relationships, they are created. Any excess relationships are disposed. If 'set' is false, passed targets are appended to the currently referenced. If some target is already referenced, it is skipped.- Type Parameters:
R- relationship class- Parameters:
element- whose owned relationships shall be edited?clazz- relationship classtargets- targetsset- should set pass targets as referenced elements or append them to the currently referenced elementsnotImplied- take into account only not implied relationships
-
getSource
Returns the first source element of the relationship.- Parameters:
relationship- the relationship to inspect- Returns:
- the source element, or null if none exist
-
getTarget
Returns the first target element of the relationship.- Parameters:
relationship- the relationship to inspect- Returns:
- the target element, or null if none exist
-
getIncoming
Returns all incoming relationships of the element.- Parameters:
element- the element to inspect- Returns:
- collection of incoming relationships
-
getIncoming
Returns all incoming relationships of the given type.- Type Parameters:
T- relationship type- Parameters:
element- the element to inspectofType- relationship class- Returns:
- collection of incoming relationships
-
getOutgoing
Returns all outgoing relationships of the element.- Parameters:
element- the element to inspect- Returns:
- collection of outgoing relationships
-
setSource
Sets the source of the relationship.- Parameters:
relationship- the relationship to modifysource- the new source element- Returns:
- true if the source was set successfully
-
setTarget
Sets the target of the relationship.- Parameters:
relationship- the relationship to modifytarget- the new target element- Returns:
- true if the target was set successfully
-
isAssociationOrConnector
Checks whether the element is an association or connector.- Parameters:
element- the element to check- Returns:
- true if it is an association or connector
-
isAssociationOrConnector
public static boolean isAssociationOrConnector(org.eclipse.emf.ecore.EClass eClass) Checks whether the EClass represents an association or connector.- Parameters:
eClass- the class to check- Returns:
- true if it represents an association or connector
-
isNonMemberRelationship
Checks whether the element is a non‑member relationship.- Parameters:
element- the element to check- Returns:
- true if it is a non‑member relationship
-
isNonMemberRelationship
public static boolean isNonMemberRelationship(org.eclipse.emf.ecore.EClass eClass) Checks whether the EClass represents a non‑member relationship.- Parameters:
eClass- the class to check- Returns:
- true if it represents a non‑member relationship
-
isMemberRelationship
Checks whether the element is a member relationship.- Parameters:
element- the element to check- Returns:
- true if it is a member relationship
-
isMemberRelationship
public static boolean isMemberRelationship(org.eclipse.emf.ecore.EClass eClass) Checks whether the EClass represents a member relationship.- Parameters:
eClass- the class to check- Returns:
- true if it represents a member relationship
-
getOwningMembershipEClass
@CheckForNull public static org.eclipse.emf.ecore.EClass getOwningMembershipEClass(org.eclipse.emf.ecore.EClass childEClass, Namespace owner) Determines the appropriate owning membership EClass for a child element.- Parameters:
childEClass- the child element classowner- the owning namespace- Returns:
- the owning membership EClass, or null if none applies
-
getRelationshipSourceFeature
@CheckForNull public static <T extends Relationship> Feature getRelationshipSourceFeature(T relationship, Function<T, List<Feature>> endFeatureProvider) Returns the source feature of a relationship when exactly two features exist.- Type Parameters:
T- relationship type- Parameters:
relationship- the relationship to inspectendFeatureProvider- provider returning the relationship ends- Returns:
- the source feature, or null if not applicable
-
getRelationshipTargetFeature
public static <T extends Relationship> List<Feature> getRelationshipTargetFeature(T relationship, Function<T, List<Feature>> endFeatureProvider) Returns the target feature(s) of a relationship.- Type Parameters:
T- relationship type- Parameters:
relationship- the relationship to inspectendFeatureProvider- provider returning the relationship ends- Returns:
- list of target features
-
findOwnerFor
@CheckForNull public static Element findOwnerFor(Relationship relationship, Element source, Element target, @CheckForNull Element diagramOwner, boolean checkPermissions) Looks for a possible owner for a given Relationship. Possible owner is calculated according to source/target and diagram owner. 'Non-member' relationships are always owned in that source.- Parameters:
relationship- relation for which possible owner should be foundsource- relationship's source elementtarget- relationship's target elementdiagramOwner- diagram owner if anycheckPermissions- indicates if permissions should be checked- Returns:
- possible owner
- See Also:
-