Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » [EMF Compare] Inverse use of EMF Compare(Try to find nondifferencing elements)
[EMF Compare] Inverse use of EMF Compare [message #671231] 
Tue, 17 May 2011 08:28 

Hi,
I hope I got the right forum for an EMF Compare question. Otherwise please lead me to the right place, thanks.
I have two ecore models, where a lot of Elements are equal. Now I want to use EMF Compare to find these equal Elements. How can I do that? Certainly, I will find all differences, but how do I find "the rest"?
Thanks a lot,
Kai
[Updated on: Tue, 17 May 2011 08:29] Report message to a moderator


 
Re: [EMF Compare] Inverse use of EMF Compare [message #673635 is a reply to message #671884] 
Tue, 24 May 2011 09:57 

Hi Laurent,
thanks a lot, that is a really nice solution and nearly solved my troubles.
Unfortunately I stick on the last step. I get a list of MatchElements from the MatchModel (precisly: matchModelObject.eContents().get(0).getSubMatchElements()) and on the other Hand a list of DiffElements from diffModelObject.getDifferences(). You wrote that MatchElements with no corresponding DiffElement considered to be equal. That sounds like a good idea, but how can I find which elements correspond with each other?
I constructed a double forloop to compare every element from the first list with every element from the second one. The point where I compare them always return false by now, because I do not know how to compare a MatchModel object with a DiffModel object. Can you help me again?


 
Re: [EMF Compare] Inverse use of EMF Compare [message #675334 is a reply to message #675166] 
Tue, 31 May 2011 08:08 

Thanks a lot!
I had to make some minor changes to to code above, but now it works very well.
Kai
List<MatchElement> matchElements =
((MatchElement) matchModelObject.eContents().get(0)).getSubMatchElements();
List<DiffGroup> diffGroups = new ArrayList<DiffGroup>();
TreeIterator<EObject> iterator = diffObject.eAllContents();
while (iterator.hasNext())
{
EObject next = iterator.next();
if (next instanceof DiffGroup)
{
diffGroups.add((DiffGroup)next);
}
}
List<MatchElement> equalObjects = new ArrayList<MatchElement>(matchElements.size());
for (MatchElement match : matchElements)
{
DiffGroup correspondingGroup = null;
for (DiffGroup group : diffGroups)
{
if (((Match2Elements) match).getRightElement() == group.getRightParent())
{
// Note : not sure that instance equality is enough
correspondingGroup = group;
break;
}
}
if (correspondingGroup == null)
{
equalObjects.add(match);
}
else
{
diffGroups.remove(correspondingGroup);
}
}
[Updated on: Wed, 13 July 2011 11:12] Report message to a moderator


 
Goto Forum:
Current Time: Sun Aug 28 00:32:22 GMT 2016
Powered by FUDForum. Page generated in 0.02123 seconds
