Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Enforcing Uniqueness
Enforcing Uniqueness [message #1140864] Wed, 16 October 2013 17:14 Go to next message
Jack Mising name is currently offline Jack Mising nameFriend
Messages: 18
Registered: August 2010
Junior Member
I am trying to control the content of a container. The contained objects are relatively simple. These objects are created from different sources and objects containing identical data can be created independently. Such different objects with identical data should be considered as identical and I need only one of them to exist in the collection even though several may be passed to add().

Is there an 'obvious' way of achieving this that I am missing? I was expecting to find some mechanism like the Comparable interface where so that the object can determine it's uniqueness, but overriding equals() doesn't do the job.

Another approach would be to maybe subclass EList in the containing object to enforce constraints within add().

Which is the correct approach?

TIA

Jack
Re: Enforcing Uniqueness [message #1141667 is a reply to message #1140864] Thu, 17 October 2013 05:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Jack,

Comments below.

On 16/10/2013 7:14 PM, Jack Mising name wrote:
> I am trying to control the content of a container. The contained
> objects are relatively simple. These objects are created from
> different sources and objects containing identical data can be created
> independently. Such different objects with identical data should be
> considered as identical and I need only one of them to exist in the
> collection even though several may be passed to add().
>
> Is there an 'obvious' way of achieving this that I am missing? I was
> expecting to find some mechanism like the Comparable interface where
> so that the object can determine it's uniqueness, but overriding
> equals() doesn't do the job.
And overriding equals is forbidden.
>
> Another approach would be to maybe subclass EList in the containing
> object to enforce constraints within add().
No, none of that is a good idea.
>
> Which is the correct approach?
I don't think there is a correct approach. If you model something with
an EClass you should expect the instances to be EObject that behave as
EObjects do. In particular they have identity so each one you create is
a different one. It may well be structurally equal to some other one,
but it's not identical. In addition, an EObject's state can change so
while it might be structurally equal to some other object at one point
in time, at a later point in time, that might not longer be the case.
So even if you "enforced uniqueness" you'd have to deal with enforcing
it remain unique in the face of arbitrary state changes to the instances.

So if you need all this enforcement, you probably should not be modeling
this with an EClass but rather as an EDataType, and then you can
implement equality as you see fit, and most likely should treat the data
values as immutable so that you don't have to deal with state changes
breaking your enforced uniqueness.
>
> TIA
>
> Jack


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Enforcing Uniqueness [message #1146946 is a reply to message #1141667] Sun, 20 October 2013 14:23 Go to previous message
Jack Mising name is currently offline Jack Mising nameFriend
Messages: 18
Registered: August 2010
Junior Member
Thanks for the response. Not exactly what I was hoping to hear, but it makes sense.

TBH, I wasn't thinking about what happens when existing members are modified, I'm just trying to be lazy while doing data import/merging.
Previous Topic:ReplaceCommand for root objects
Next Topic:Creating instance if only the EObject interface is known
Goto Forum:
  


Current Time: Wed Sep 25 07:17:37 GMT 2024

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

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

Back to the top