Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Ecore Tools » Using EObject as Key in map structure(EMF Ecore Models - EObject as Key in Hashmap)
Using EObject as Key in map structure [message #1844780] Fri, 24 September 2021 17:27
Thomas Stifter is currently offline Thomas StifterFriend
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?

Previous Topic:Errors When Adding Second Xcore project
Next Topic:Serialize base class object
Goto Forum:
  


Current Time: Sat Nov 11 08:55:58 GMT 2023

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

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

Back to the top