opposite reference from Map$Entry to its container [message #989736] |
Fri, 07 December 2012 08:18  |
Eclipse User |
|
|
|
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?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.34053 seconds