<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Comparing EMF Models</title>
	<atom:link href="http://jorgemanrubia.net/2008/07/06/comparing-emf-models/feed/" rel="self" type="application/rss+xml" />
	<link>http://jorgemanrubia.net/2008/07/06/comparing-emf-models/</link>
	<description>Personal Page</description>
	<lastBuildDate>Wed, 26 Oct 2011 09:24:02 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Jorge Manrubia</title>
		<link>http://jorgemanrubia.net/2008/07/06/comparing-emf-models/comment-page-1/#comment-556</link>
		<dc:creator>Jorge Manrubia</dc:creator>
		<pubDate>Sun, 07 Aug 2011 11:20:47 +0000</pubDate>
		<guid isPermaLink="false">http://jorgemanrubia.net/blog/?p=30#comment-556</guid>
		<description>&lt;p&gt;Thank you Fabian. Your approach seems much better. Thanks for sharing it!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thank you Fabian. Your approach seems much better. Thanks for sharing it!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Fabian</title>
		<link>http://jorgemanrubia.net/2008/07/06/comparing-emf-models/comment-page-1/#comment-555</link>
		<dc:creator>Fabian</dc:creator>
		<pubDate>Thu, 04 Aug 2011 08:50:49 +0000</pubDate>
		<guid isPermaLink="false">http://jorgemanrubia.net/blog/?p=30#comment-555</guid>
		<description>&lt;p&gt;Hi, the sorting didn’t worked for my EObjects, i think its sometimes not enough to take the Standard toString Method to sort by. So I have written my own EqualityHelper that really compares the two Lists without a care of order if the Ordered Attribute of the Reference is false. It works finde :)&lt;/p&gt;

&lt;p&gt;
[cc lang=&quot;java&quot;]
import java.util.*;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.EcoreUtil.EqualityHelper;

public class CustomEqualityHelper extends EcoreUtil.EqualityHelper {

private static final long serialVersionUID = 1L;

public CustomEqualityHelper() {
    super();
}

private CustomEqualityHelper(CustomEqualityHelper emfComparator) {
    this.putAll(emfComparator);
}

@SuppressWarnings(&quot;unchecked&quot;)
@Override
protected boolean haveEqualReference(EObject eObject1, EObject eObject2, EReference reference)
{
  Object value1 = eObject1.eGet(reference);
  Object value2 = eObject2.eGet(reference);

  if(reference.isMany())
  {
      // *** important change for Unordered Lists here:
      if(reference.isOrdered())
          return equals((List&lt;EObject&gt;)value1, (List&lt;EObject&gt;)value2);
      else
          return equalsUnOrdered((List&lt;EObject&gt;)value1, (List&lt;EObject&gt;)value2);
  }
  else
  {
      return equals((EObject)value1, (EObject)value2);
  }

}

public boolean equalsUnOrdered(List&lt;EObject&gt; list1, List&lt;EObject&gt; list2)
{
    // if the Lists haven&#039;t the same size they can&#039;t be equal
    if(list1.size()!=list2.size()) return false;

    // save the Equal pairs: list1 Elements as Key and list2 Elements as Value
Map&lt;EObject,EObject&gt; equalFound = new HashMap&lt;EObject,EObject&gt;();

    for(EObject list1El:list1)
{
    // try to find an equal Element for list1El in list2
    for(EObject list2El:list2)
    {
        // skip Elements of list2 that already have an equal Element in list1
        if(!equalFound.containsValue(list2El)) 
            // if list list1El is equal to list2El save it the Map
            // create a copy of the CustomEqualityHelper because it&#039;s made only for one recursive Compare
            if(new CustomEqualityHelper(this).equals(list1El, list2El)) 
            {
                equalFound.put(list1El, list2El);
                break;
            }
    }

    // if no equal Element for listEl1 was found in list2, they couldn&#039;t be equal
    if(!equalFound.containsKey(list1El)) return false; 

    }

// For all Elements of list1 an own equal Element in list2 was found.
return true;
[/cc]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi, the sorting didn’t worked for my EObjects, i think its sometimes not enough to take the Standard toString Method to sort by. So I have written my own EqualityHelper that really compares the two Lists without a care of order if the Ordered Attribute of the Reference is false. It works finde <img src='http://jorgemanrubia.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<p>

<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.emf.ecore.EObject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.emf.ecore.EReference</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.emf.ecore.EStructuralFeature</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.emf.ecore.util.EcoreUtil</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.emf.ecore.util.EcoreUtil.EqualityHelper</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CustomEqualityHelper <span style="color: #000000; font-weight: bold;">extends</span> EcoreUtil.<span style="color: #006633;">EqualityHelper</span> <span style="color: #009900;">&#123;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> CustomEqualityHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">private</span> CustomEqualityHelper<span style="color: #009900;">&#40;</span>CustomEqualityHelper emfComparator<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">putAll</span><span style="color: #009900;">&#40;</span>emfComparator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span><br />
@Override<br />
<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">boolean</span> haveEqualReference<span style="color: #009900;">&#40;</span>EObject eObject1, EObject eObject2, EReference reference<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> value1 <span style="color: #339933;">=</span> eObject1.<span style="color: #006633;">eGet</span><span style="color: #009900;">&#40;</span>reference<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> value2 <span style="color: #339933;">=</span> eObject2.<span style="color: #006633;">eGet</span><span style="color: #009900;">&#40;</span>reference<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>reference.<span style="color: #006633;">isMany</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// *** important change for Unordered Lists here:</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>reference.<span style="color: #006633;">isOrdered</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> equals<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>EObject<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span>value1, <span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>EObject<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span>value2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> equalsUnOrdered<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>EObject<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span>value1, <span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>EObject<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span>value2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> equals<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>EObject<span style="color: #009900;">&#41;</span>value1, <span style="color: #009900;">&#40;</span>EObject<span style="color: #009900;">&#41;</span>value2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> equalsUnOrdered<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>EObject<span style="color: #339933;">&gt;</span> list1, List<span style="color: #339933;">&lt;</span>EObject<span style="color: #339933;">&gt;</span> list2<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// if the Lists haven't the same size they can't be equal</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>list1.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span>list2.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// save the Equal pairs: list1 Elements as Key and list2 Elements as Value</span><br />
Map<span style="color: #339933;">&lt;</span>EObject,EObject<span style="color: #339933;">&gt;</span> equalFound <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>EObject,EObject<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>EObject list1El<span style="color: #339933;">:</span>list1<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// try to find an equal Element for list1El in list2</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>EObject list2El<span style="color: #339933;">:</span>list2<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// skip Elements of list2 that already have an equal Element in list1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>equalFound.<span style="color: #006633;">containsValue</span><span style="color: #009900;">&#40;</span>list2El<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// if list list1El is equal to list2El save it the Map</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// create a copy of the CustomEqualityHelper because it's made only for one recursive Compare</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CustomEqualityHelper<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>list1El, list2El<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; equalFound.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>list1El, list2El<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// if no equal Element for listEl1 was found in list2, they couldn't be equal</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>equalFound.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span>list1El<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> <br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// For all Elements of list1 an own equal Element in list2 was found.</span><br />
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span></div></div>

</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen</title>
		<link>http://jorgemanrubia.net/2008/07/06/comparing-emf-models/comment-page-1/#comment-459</link>
		<dc:creator>Stephen</dc:creator>
		<pubDate>Wed, 03 Nov 2010 00:02:36 +0000</pubDate>
		<guid isPermaLink="false">http://jorgemanrubia.net/blog/?p=30#comment-459</guid>
		<description>&lt;p&gt;Jorge, I used your code as a base for my own comparator. Thanks.&lt;/p&gt;

&lt;p&gt;EqualityHelper flags two operations as mismatched if the same parameter has a superclass on one side, but not on the other (or a different superclass). In other words, they have different eTypes. I would consider the pramaters&#039; classes to be mismatched, but not their operations.&lt;/p&gt;

&lt;p&gt;The funny thing is that the parameters themselves do not get flagged as not matching, only the operations. Which is rather misleading.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Jorge, I used your code as a base for my own comparator. Thanks.</p>

<p>EqualityHelper flags two operations as mismatched if the same parameter has a superclass on one side, but not on the other (or a different superclass). In other words, they have different eTypes. I would consider the pramaters&#8217; classes to be mismatched, but not their operations.</p>

<p>The funny thing is that the parameters themselves do not get flagged as not matching, only the operations. Which is rather misleading.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Errors in my post on Comparing EMF Models - Jorge Manrubia</title>
		<link>http://jorgemanrubia.net/2008/07/06/comparing-emf-models/comment-page-1/#comment-2</link>
		<dc:creator>Errors in my post on Comparing EMF Models - Jorge Manrubia</dc:creator>
		<pubDate>Sun, 08 Feb 2009 01:06:16 +0000</pubDate>
		<guid isPermaLink="false">http://jorgemanrubia.net/blog/?p=30#comment-2</guid>
		<description>&lt;p&gt;[...] was an error in the code originally posted in my article on Comparing EMF models. Thank you so much to Jim Showalter for warning me. The post has been updated with the right code. [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] was an error in the code originally posted in my article on Comparing EMF models. Thank you so much to Jim Showalter for warning me. The post has been updated with the right code. [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Code Reviewer</title>
		<link>http://jorgemanrubia.net/2008/07/06/comparing-emf-models/comment-page-1/#comment-3</link>
		<dc:creator>Code Reviewer</dc:creator>
		<pubDate>Wed, 19 Nov 2008 01:09:17 +0000</pubDate>
		<guid isPermaLink="false">http://jorgemanrubia.net/blog/?p=30#comment-3</guid>
		<description>&lt;p&gt;This code doesn&#039;t actually work. If you look at the chain of calls, you&#039;re basically doing: replace o1.toString().hashCode() in o1.toString(), but o1.toString() contains the hashCode of o1, not of o1&#039;s toString(). Also, there&#039;s no reason to replace the class name, and even if there was you&#039;re replacing o1.toString().getClass().getName(), which will always return java.lang.String, when what you want is to replace o1.getClass().getName(). And even if you get both replaces working, ordering will fail when comparing two models generated from the same diagram but with different seeds for the IDs, because the IDs won&#039;t match, so the sorts won&#039;t match.&quot;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>This code doesn&#8217;t actually work. If you look at the chain of calls, you&#8217;re basically doing: replace o1.toString().hashCode() in o1.toString(), but o1.toString() contains the hashCode of o1, not of o1&#8242;s toString(). Also, there&#8217;s no reason to replace the class name, and even if there was you&#8217;re replacing o1.toString().getClass().getName(), which will always return java.lang.String, when what you want is to replace o1.getClass().getName(). And even if you get both replaces working, ordering will fail when comparing two models generated from the same diagram but with different seeds for the IDs, because the IDs won&#8217;t match, so the sorts won&#8217;t match.&#8221;</p>]]></content:encoded>
	</item>
</channel>
</rss>

