Set equality helper [message #1181133] |
Mon, 11 November 2013 06:47  |
Eclipse User |
|
|
|
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 #1196098 is a reply to message #1194221] |
Tue, 19 November 2013 03:43  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04011 seconds