Class Relationships

java.lang.Object
com.dassault_systemes.modeler.kerml.model.Relationships

@OpenApiAll public class Relationships extends Object
Utility class to work with Relationship
  • Constructor Details

    • Relationships

      public Relationships()
  • Method Details

    • getFirstOwnedRelatedElement

      @CheckForNull public static Element getFirstOwnedRelatedElement(Relationship relationship)
      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 inspect
      clazz - 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 modify
      ownedRelatedElement - 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 - element
      clazz - relationship instance class
      isInstance - 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 inspected
      clazz - the relationship class
      isInstance - 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 modify
      clazz - relationship class
      targets - 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 modify
      clazz - relationship class
      targets - 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 class
      targets - targets
      set - 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 class
      targets - targets
      set - should set pass targets as referenced elements or append them to the currently referenced elements
      notImplied - take into account only not implied relationships
    • getSource

      @CheckForNull public static Element getSource(Relationship relationship)
      Returns the first source element of the relationship.
      Parameters:
      relationship - the relationship to inspect
      Returns:
      the source element, or null if none exist
    • getTarget

      @CheckForNull public static Element getTarget(Relationship relationship)
      Returns the first target element of the relationship.
      Parameters:
      relationship - the relationship to inspect
      Returns:
      the target element, or null if none exist
    • getIncoming

      public static Collection<Relationship> getIncoming(Element element)
      Returns all incoming relationships of the element.
      Parameters:
      element - the element to inspect
      Returns:
      collection of incoming relationships
    • getIncoming

      public static <T extends Relationship> Collection<T> getIncoming(Element element, Class<T> ofType)
      Returns all incoming relationships of the given type.
      Type Parameters:
      T - relationship type
      Parameters:
      element - the element to inspect
      ofType - relationship class
      Returns:
      collection of incoming relationships
    • getOutgoing

      public static Collection<Relationship> getOutgoing(Element element)
      Returns all outgoing relationships of the element.
      Parameters:
      element - the element to inspect
      Returns:
      collection of outgoing relationships
    • setSource

      public static boolean setSource(Relationship relationship, @CheckForNull Element source)
      Sets the source of the relationship.
      Parameters:
      relationship - the relationship to modify
      source - the new source element
      Returns:
      true if the source was set successfully
    • setTarget

      public static boolean setTarget(Relationship relationship, @CheckForNull Element target)
      Sets the target of the relationship.
      Parameters:
      relationship - the relationship to modify
      target - the new target element
      Returns:
      true if the target was set successfully
    • isAssociationOrConnector

      public static boolean isAssociationOrConnector(@CheckForNull Element element)
      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

      public static boolean isNonMemberRelationship(@CheckForNull Element element)
      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

      public static boolean isMemberRelationship(@CheckForNull Element element)
      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 class
      owner - 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 inspect
      endFeatureProvider - 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 inspect
      endFeatureProvider - 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 found
      source - relationship's source element
      target - relationship's target element
      diagramOwner - diagram owner if any
      checkPermissions - indicates if permissions should be checked
      Returns:
      possible owner
      See Also: