Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [XCORE] How to define equality?
[XCORE] How to define equality? [message #1261451] Sun, 02 March 2014 16:27 Go to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
I would like to know how to define equality with xcore and EMF ? The EMF book says that two object are equal if for all there features isSet states are the same. But if thats true how can I tool like EMfCompare identify if an object has changed ?

How can I define my own equality function ?

Regards
Roger
Re: [XCORE] How to define equality? [message #1263849 is a reply to message #1261451] Tue, 04 March 2014 20:45 Go to previous messageGo to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
Still have no clue how to does this. I now know how to add an id. But so far haven't found a way that this id is used for equality and hashcode. I know that I can write my own operation to supply the desired behaviour, but I think that there is probably some built in support for this.

[Updated on: Tue, 04 March 2014 20:49]

Report message to a moderator

Re: [XCORE] How to define equality? [message #1263862 is a reply to message #1263849] Tue, 04 March 2014 20:58 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Roger,

Much of the EMF run-time assumes (read: requires) that implementations
of the EObject interface do not override equals() and hashCode(). That
is, it is required that they inherit equality-is-identity semantics
from java.lang.Object. The EMF run-time generally tests == instead of
equals(), but perhaps not consistently, and makes extensive use of
maps, so you can expect stuff not to work in surprising ways.

If you need to test EObjects for structural equality, it is best to use
EcoreUtil.equals(...) externally, not overriding Object::equals().

Cheers,

Christian


On 2014-03-04 20:45:19 +0000, Roger Gilliar said:

> The following does work:
>
> op boolean equals(Object object) {
> if (object instanceof EObject) {
> EcoreUtil.equals(this, object)
> } else {
> false
> }
> }
Re: [XCORE] How to define equality? [message #1264322 is a reply to message #1263862] Wed, 05 March 2014 06:09 Go to previous message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
Hi Christian,

thanks for the explanation. Id din't know that EMF tests == instead of equals.

Regards
Roger
Previous Topic:Ignoring elements from XML
Next Topic:What are the significant performance improvements in 2.9
Goto Forum:
  


Current Time: Tue Apr 16 16:02:10 GMT 2024

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

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

Back to the top