Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Compare » Set equality helper
Set equality helper [message #1181133] Mon, 11 November 2013 11:47 Go to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
I have this case:

EObject leftChild = left.getChild();
EObject rightChild = right.getChild();

Both left and right have the same EClass and are EObjects at different times, i.e. left.getTimestamp() < right.getTimestamp().

leftChild should be the same as rightChild as their URI is the same, but they are different Java object instances, so are marked as ReferenceChange diffs when doing the comparison.

How do I tell EMF Compare to compare the URI instead of using equals (as is normal for EObjects)? I guess this is done by an IEqualityHelper, but where do I set it?

Thanks!
Re: Set equality helper [message #1185709 is a reply to message #1181133] Thu, 14 November 2013 08:02 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

We have an example of how to alter the equality helper in the 'Custom data types' FAQ entry.

Please let us know if this does not help Smile.

Laurent Goubet
Obeo
Re: Set equality helper [message #1194221 is a reply to message #1185709] Mon, 18 November 2013 11:54 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Laurent,
I should have mentioned that I am using sources from Git head.
There is no Builder.setMatchEngine().

Laurent Goubet wrote on Thu, 14 November 2013 09:02
Hi,

We have an example of how to alter the equality helper in the 'Custom data types' FAQ entry.

Please let us know if this does not help Smile.

Laurent Goubet
Obeo

Re: Set equality helper [message #1196098 is a reply to message #1194221] Tue, 19 November 2013 08:43 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Indeed, we forgot to update this example when we changed that API. The means are still the same : you need to change the equality helper. However changing the equality helper should now be done through a factory. We'll update the FAQ example, for now you should be able to build from this other example; what you need to alter in this one is the "DefaultEqualityHelperFactory" : you'll need your own sub-class of that.

Basically, something of the sort:

IComparisonFactory comparisonFactory = new DefaultComparisonFactory(new DefaultEqualityHelperFactory() {
    public IEqualityHelper createEqualityHelper() {
        return new MyEqualityHelper();
    }
});
IEObjectMatcher matcher = DefaultMatchEngine.createDefaultEObjectMatcher(UseIdentifiers.WHEN_AVAILABLE);
IMatchEngine customMatchEngine = new DefaultMatchEngine(matcher, comparisonFactory);

IMatchEngine.Factory engineFactory = new MatchEngineFactoryImpl() {
  public IMatchEngine getMatchEngine() {
    return customMatchEngine;
  }
};
engineFactory.setRanking(20); // default engine ranking is 10, must be higher to override.
registry.add(engineFactory);
EMFCompare.builder().setMatchEngineFactoryRegistry(registry).build().compare(scope);


Laurent Goubet
Obeo
Previous Topic:Single-Side Match and location of ADD Diff
Next Topic:How to open a compare editor with a comparison object
Goto Forum:
  


Current Time: Sat Apr 20 01:36:48 GMT 2024

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

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

Back to the top