Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF Diff/Merge » How to get the common elements between two models
How to get the common elements between two models [message #1732659] Wed, 18 May 2016 13:22 Go to next message
Wesley Klewerton is currently offline Wesley KlewertonFriend
Messages: 11
Registered: March 2016
Junior Member
After the comparison of two models, how do I get the common elements (the similar parts between the models)?
Re: How to get the common elements between two models [message #1732697 is a reply to message #1732659] Thu, 19 May 2016 09:38 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 106
Registered: January 2012
Senior Member
  /**
   * Return the set of elements from the given side which have a match in the opposite side
   * according to the given comparison
   * @param comparison_p a non-null comparison
   * @param side_p TARGET or REFERENCE
   * @return a non-null collection containing no null value
   */
  public Collection<EObject> getCommonElements(IComparison comparison_p, Role side_p) {
    Collection<EObject> result = new HashSet<EObject>();
    for (IMatch match : comparison_p.getMapping().getContents()) {
      if (!match.isPartial())
        result.add(match.get(side_p));
    }
    return result;
  }
Re: How to get the common elements between two models [message #1732732 is a reply to message #1732697] Thu, 19 May 2016 17:08 Go to previous messageGo to next message
Wesley Klewerton is currently offline Wesley KlewertonFriend
Messages: 11
Registered: March 2016
Junior Member
Maybe I did not express myself clearly. Actually I need the common model between two models. The code above returns all elements, but when I try to put them into a resource to save a model the resulting model is not well formed.
Re: How to get the common elements between two models [message #1732812 is a reply to message #1732732] Fri, 20 May 2016 04:47 Go to previous message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 106
Registered: January 2012
Senior Member
I assume the reason why you cannot save the resource is because you have elements you want to include that have references to elements you want to exclude. It means you need to either delete these references (which may require further decisions in the case where you have [1] multiplicities) or transitively include the required elements. Or maybe store the referenced-but-not-included elements in a dedicated resource, according to your need.

If this is not the answer you expect, may I suggest that you formally define what you need by "model" since this notion does not exist per se in EMF (you only have sets of elements, or resources which are related to persistence concerns).
Previous Topic:How do I force the merge of all attributes in a UML file?
Next Topic:How to compare two UML Model Resources ignoring XMI ids.
Goto Forum:
  


Current Time: Fri Apr 26 23:45:22 GMT 2024

Powered by FUDForum. Page generated in 5.83991 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top