Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How does EcoreUtil.delete() handles objects that are keys in a EMap?
How does EcoreUtil.delete() handles objects that are keys in a EMap? [message #1384969] Tue, 03 June 2014 11:07 Go to next message
Silvestre Martins is currently offline Silvestre MartinsFriend
Messages: 43
Registered: July 2009
Member

The implementation of a EMap is used using a special class that represents the entry in the map, which has 2 attributes: the key and the value.

My question is: does the EcoreUtil.delete() handles the automatic removal of the entry in the map when an object that that represents the entry key gets deleted, as it happens with the regular EList?

From what I could observe, it seems not - while the key is set to null, the entry and the value remains untouched, which causes the data to not be disposed.
Moreover, this also violates the usage of keys in the Maps, since the key should be immutable, otherwise it would not be possible to access that entry anymore if the key changes, since hashCode() and equals() won't return the same anymore.

Am I right about this analysis?
Re: How does EcoreUtil.delete() handles objects that are keys in a EMap? [message #1384971 is a reply to message #1384969] Tue, 03 June 2014 11:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26223
Registered: July 2009
Senior Member
Silvestre,

Comments below.

On 03/06/2014 1:07 PM, Silvestre Martins wrote:
>
> The implementation of a EMap is used using a special class that
> represents the entry in the map, which has 2 attributes: the key and
> the value.
>
> My question is: does the EcoreUtil.delete() handles the automatic
> removal of the entry in the map when an object that that represents
> the entry key gets deleted, as it happens with the regular EList?
No. In fact any changes to the map's keys are problematic at best. The
key could even be multi-valued so delete could remove one of the
EObjects in the list; that wouldn't play nicely either.
>
> From what I could observe, it seems not - while the key is set to
> null, the entry and the value remains untouched, which causes the data
> to not be disposed.
Yes.
> Moreover, this also violates the usage of keys in the Maps, since the
> key should be immutable,
Yes, another problem is if the object should ever be converted to a
proxy and needs to be resolved again; that would also change the key and
hence corrupt the hash indexing.
> otherwise it would not be possible to access that entry anymore if the
> key changes, since hashCode() and equals() won't return the same anymore.
Indeed.
>
> Am I right about this analysis?
Yes, it's problematic. It would also be problematic to simply remove
the entry, because the value could be a containment reference as well,
and then all that stuff would need to be deleted. And it's possible
(though unlikely) for there to be references to the map entry itself...
Re: How does EcoreUtil.delete() handles objects that are keys in a EMap? [message #1384974 is a reply to message #1384971] Tue, 03 June 2014 12:25 Go to previous messageGo to next message
Silvestre Martins is currently offline Silvestre MartinsFriend
Messages: 43
Registered: July 2009
Member
So I suppose the guideline is: ensure entries are removed within the application code (e.g., business logic algorithms), right?
Re: How does EcoreUtil.delete() handles objects that are keys in a EMap? [message #1384976 is a reply to message #1384974] Tue, 03 June 2014 12:30 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26223
Registered: July 2009
Senior Member
Silvestre,

Yes, there don't seem to be obvious bullet proof solutions to such a
general map problem.

On 03/06/2014 2:25 PM, Silvestre Martins wrote:
> So I suppose the guideline is: ensure entries are removed within the
> application code (e.g., business logic algorithms), right?
Previous Topic:PackageNotFoundException opening XMI file without xsi:schemaLocation in EMF Editor
Next Topic:StackOverflowError with EContentAdapter
Goto Forum:
  


Current Time: Wed Nov 26 07:45:19 GMT 2014

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

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