Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » opposite reference from Map$Entry to its container
opposite reference from Map$Entry to its container [message #989736] Fri, 07 December 2012 13:18 Go to next message
Istvan Ballok is currently offline Istvan BallokFriend
Messages: 2
Registered: July 2009
Junior Member
Using xcore, it is very easy to model a map data structure:

class Library {
	contains ISBNToBookEntry [] ISBNToBookEntries  
}

class ISBNToBookEntry wraps Map$Entry {
	String key
	contains Book value
}

class Book {}


It is also straightforward to use a bidirectional reference between the book and the entry.

class Library {
	contains ISBNToBookEntry [] ISBNToBookEntries  
}

class ISBNToBookEntry wraps Map$Entry {
	String key
	contains Book value opposite entry
}

class Book {
	refers ISBNToBookEntry entry opposite value
}


However it is not so clear, how a bidirectional reference between the entry and the container should be modeled.

class Library {
	contains ISBNToBookEntry [] ISBNToBookEntries opposite library  
}

class ISBNToBookEntry wraps Map$Entry {
	String key
	contains Book value opposite entry
	refers Library library opposite ISBNToBookEntries
}

class Book {
	refers ISBNToBookEntry entry opposite value
}


This solution is not perfect, because the "Instance Type Name" property on the ISBNToBookEntry class is set to java.util.Map$Entry, and hence EMF does not generate an interface for this type.

To access the library feature in the ISBNToBookEntry we would need to cast the Entry to ISBNToBookEntryImpl.

Can you suggest a better way to achieve a typesafe bidirectional reference between the entry and its container and still profit from the hash based access to the Books in the map in the Library?
Re: opposite reference from Map$Entry to its container [message #989830 is a reply to message #989736] Sat, 08 December 2012 05:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Istvan,

It seems more convenient to add a helper operation to Book than for API
clients to work directly with entry instances.

op Library getLibrary()
{
val library = eContainer?.eContainer
if (library instanceof Library)
{
library as Library
}
}

Note that there's no need to model the opposite relationship in the
entry with this approach.

On 07/12/2012 3:10 PM, Istvan Ballok wrote:
> Using xcore, it is very easy to model a map data structure:
>
>
> class Library {
> contains ISBNToBookEntry [] ISBNToBookEntries }
>
> class ISBNToBookEntry wraps Map$Entry {
> String key
> contains Book value
> }
>
> class Book {}
>
>
> It is also straightforward to use a bidirectional reference between
> the book and the entry.
>
>
> class Library {
> contains ISBNToBookEntry [] ISBNToBookEntries }
>
> class ISBNToBookEntry wraps Map$Entry {
> String key
> contains Book value opposite entry
> }
>
> class Book {
> refers ISBNToBookEntry entry opposite value
> }
>
>
> However it is not so clear, how a bidirectional reference between the
> entry and the container should be modeled.
>
>
> class Library {
> contains ISBNToBookEntry [] ISBNToBookEntries opposite library }
>
> class ISBNToBookEntry wraps Map$Entry {
> String key
> contains Book value opposite entry
> refers Library library opposite ISBNToBookEntries
> }
>
> class Book {
> refers ISBNToBookEntry entry opposite value
> }
>
>
> This solution is not perfect, because the "Instance Type Name"
> property on the ISBNToBookEntry class is set to java.util.Map$Entry,
> and hence EMF does not generate an interface for this type.
>
> To access the library feature in the ISBNToBookEntry we would need to
> cast the Entry to ISBNToBookEntryImpl.
>
> Can you suggest a better way to achieve a typesafe bidirectional
> reference between the entry and its container and still profit from
> the hash based access to the Books in the map in the Library?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: opposite reference from Map$Entry to its container [message #989876 is a reply to message #989736] Sun, 09 December 2012 08:05 Go to previous message
Istvan Ballok is currently offline Istvan BallokFriend
Messages: 2
Registered: July 2009
Junior Member
Ed,

Thank you for the prompt and clear answer.

Istvan
Previous Topic:EContentAdapter vs Listening to commands
Next Topic:Getting FreeMarker to Wrap EMap as SimpleHash instead of SimpleSequence?
Goto Forum:
  


Current Time: Fri Apr 19 21:11:15 GMT 2024

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

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

Back to the top