Using EObject as Key in map structure [message #1844780] |
Fri, 24 September 2021 17:27 |
Thomas Stifter Messages: 2 Registered: September 2021 |
Junior Member |
|
|
Hello,
I am somewhat new to the EMF and facing the following situation: I want to store models (type "EObject") in a map using them as key value to achieve mapping of models to values.
In the API for EObject it is however stated "The framework also assumes that implementations will not specialize #equals(Object) (nor #hashCode()) so that "==" can be always used for equality testing; EcoreUtil.equals should be used for doing structural equality testing."
I tried using a wrapper class "MyEObject" that holds the actual "EObject" instance and then do a HashMap<MyEObject, Integer>. "MyEObject" implements hashCode() and equals() functions. In equals() I am using EcoreUtil.EqualityHelper's equals() function to test for strucutral equality. But it see,s that EcoreUtil.EqualityHelper equals() sometimes returns false even though two models are equal in structure/references and attributes.
How can this be done in a reasonable manner?
|
|
|
Powered by
FUDForum. Page generated in 0.02110 seconds