Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Making a copy of a FeatureMap(How do I make a duplicate?)
Making a copy of a FeatureMap [message #646199] Wed, 22 December 2010 16:17 Go to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi, It is most probably a very stupid question and I'm missing something really simple.

What is the recommended way of doing a (deep) copy of a FeatureMap?

I notice that for an EObject I can use:

EcoreUtil.copy(EObject)

Is there some way of doing a copy of a FeatureMap?

Thanks

Rob

Re: Making a copy of a FeatureMap [message #646205 is a reply to message #646199] Wed, 22 December 2010 16:20 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Hi Rob,

IIRC. a feature map is just an ordered list of FeatureMap.Entries. Copy it with:

List copy = new XYZList();
copy.addAll(featureMap);

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Am 22.12.2010 17:17, schrieb Rob:
> Hi, It is most probably a very stupid question and I'm missing something really simple.
>
> What is the recommended way of doing a (deep) copy of a FeatureMap?
>
> I notice that for an EObject I can use:
>
> EcoreUtil.copy(EObject)
>
> Is there some way of doing a copy of a FeatureMap?
>
> Thanks
>
> Rob
>
>


Re: Making a copy of a FeatureMap [message #646208 is a reply to message #646199] Wed, 22 December 2010 16:50 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Eike,

Thanks for taking the time to reply, unfortunately, if I do the following:

FeatureMap origFeatureMap = ((PersonType)tt).getAny();
ArrayList<Entry> copyList = new ArrayList<Entry>();
copyList.addAll(origFeatureMap);
anyFeatureMap.addAll(copyList);


Then it will result in all the references in the origFeatureMap being removed when the anyFeatureMap.addAll() is performed.

Is there a deep copy I can do?

Thanks

Rob
Re: Making a copy of a FeatureMap [message #646210 is a reply to message #646205] Wed, 22 December 2010 16:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Eike,

No, copyAll wants to copy EObjects. There isn't currently a simple way
to deep copy just a feature map. Looking at how EcoreUtil.Copier
handles feature maps you can see that it's necessary to deep copy the
objects that are held by feature map entries that are containment
references and then a bunch more work in done in copyReferences to
actually copy the feature map's contents.


Eike Stepper wrote:
> Hi Rob,
>
> IIRC. a feature map is just an ordered list of FeatureMap.Entries.
> Copy it with:
>
> List copy = new XYZList();
> copy.addAll(featureMap);
>
> Cheers
> /Eike
>
> ----
> http://www.esc-net.de
> http://thegordian.blogspot.com
> http://twitter.com/eikestepper
>
>
> Am 22.12.2010 17:17, schrieb Rob:
>> Hi, It is most probably a very stupid question and I'm missing
>> something really simple.
>>
>> What is the recommended way of doing a (deep) copy of a FeatureMap?
>>
>> I notice that for an EObject I can use:
>>
>> EcoreUtil.copy(EObject)
>>
>> Is there some way of doing a copy of a FeatureMap?
>>
>> Thanks
>>
>> Rob
>>
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Making a copy of a FeatureMap [message #646211 is a reply to message #646208] Wed, 22 December 2010 17:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Rob,

A simple approach would be to copy tt and use that copy's feature map.


Rob wrote:
> Hi Eike,
>
> Thanks for taking the time to reply, unfortunately, if I do the
> following:
>
> FeatureMap origFeatureMap = ((PersonType)tt).getAny();
> ArrayList<Entry> copyList = new ArrayList<Entry>();
> copyList.addAll(origFeatureMap);
> anyFeatureMap.addAll(copyList);
>
> Then it will result in all the references in the origFeatureMap being
> removed when the anyFeatureMap.addAll() is performed.
>
> Is there a deep copy I can do?
>
> Thanks
>
> Rob
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Making a copy of a FeatureMap [message #646212 is a reply to message #646199] Wed, 22 December 2010 17:08 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Thanks Eike, Ed for your replies.

Unfortunately where I need to do this operation I don't have access to the EObject (tt in the example), I just have it in my testing code at the moment.

Thanks

Rob
Re: Making a copy of a FeatureMap [message #646220 is a reply to message #646210] Wed, 22 December 2010 17:20 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 22.12.2010 17:58, schrieb Ed Merks:
> Eike,
>
> No, copyAll wants to copy EObjects. There isn't currently a simple way to deep copy just a feature map. Looking at how EcoreUtil.Copier handles feature maps you can see that it's necessary to deep copy the objects that are held by feature map entries that are containment references and then a bunch more work in done in copyReferences to actually copy the feature map's contents.
Oh, sorry for the wrong hint ;-(

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


>
> Eike Stepper wrote:
>> Hi Rob,
>>
>> IIRC. a feature map is just an ordered list of FeatureMap.Entries. Copy it with:
>>
>> List copy = new XYZList();
>> copy.addAll(featureMap);
>>
>> Cheers
>> /Eike
>>
>> ----
>> http://www.esc-net.de
>> http://thegordian.blogspot.com
>> http://twitter.com/eikestepper
>>
>>
>> Am 22.12.2010 17:17, schrieb Rob:
>>> Hi, It is most probably a very stupid question and I'm missing something really simple.
>>>
>>> What is the recommended way of doing a (deep) copy of a FeatureMap?
>>>
>>> I notice that for an EObject I can use:
>>>
>>> EcoreUtil.copy(EObject)
>>>
>>> Is there some way of doing a copy of a FeatureMap?
>>>
>>> Thanks
>>>
>>> Rob
>>>
>>>


Re: Making a copy of a FeatureMap [message #646221 is a reply to message #646212] Wed, 22 December 2010 17:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Rob,

You can cast it to EStructuralFeature.Setting and call getEObject to get it.


Rob wrote:
> Thanks Eike, Ed for your replies.
>
> Unfortunately where I need to do this operation I don't have access to
> the EObject (tt in the example), I just have it in my testing code at
> the moment.
>
> Thanks
>
> Rob
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Making a copy of a FeatureMap [message #646391 is a reply to message #646199] Thu, 23 December 2010 16:44 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Thank you both for your suggestions.

I have managed to get the use of EStructuralFeature.Setting working well - saves me a whole world of trouble!

Thanks, Rob
Re: Making a copy of a FeatureMap [message #649014 is a reply to message #646199] Mon, 17 January 2011 09:39 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi,

As you were so much help in making a copy of a FeatureMap (saved me a real headache), would you happen to have any suggestion on how I can duplicate an:

FeatureMap.Entry

Thanks

Rob
Re: Making a copy of a FeatureMap [message #649096 is a reply to message #649014] Mon, 17 January 2011 16:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Rob,

Try FeatureMapUtil.createEntry. Note that entries themselves are
immutable so you don't need to copy them.


Rob wrote:
> Hi,
>
> As you were so much help in making a copy of a FeatureMap (saved me a
> real headache), would you happen to have any suggestion on how I can
> duplicate an:
>
> FeatureMap.Entry
>
> Thanks
>
> Rob
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Making a copy of a FeatureMap [message #649101 is a reply to message #646199] Mon, 17 January 2011 16:40 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Thanks for the tip Ed.

The problem I am having is that I am copying an "Entry" from one featureMap to another, and as I copy it between the featureMaps, it removes it from the original map. Any idea on how to stop that?

Thanks

Rob
Re: Making a copy of a FeatureMap [message #649103 is a reply to message #649101] Mon, 17 January 2011 16:47 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Rob,

Keep in mind that the entry may be for a containment reference so even
if you create a copy of the entry, you'll still see the other one being
removed because the object that's wrapped by the feature map entry can't
be contained in more than on containment relationship.


Rob wrote:
> Thanks for the tip Ed.
>
> The problem I am having is that I am copying an "Entry" from one
> featureMap to another, and as I copy it between the featureMaps, it
> removes it from the original map. Any idea on how to stop that?
>
> Thanks
>
> Rob
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Preventing use of Java primitive types in XSD-derived Ecore
Next Topic:Teneo, Hibernate and the collection cache
Goto Forum:
  


Current Time: Fri Apr 19 20:22:41 GMT 2024

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

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

Back to the top