Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Deleting elements efficiently
Deleting elements efficiently [message #912366] Thu, 13 September 2012 12:41 Go to next message
Tex Iano is currently offline Tex Iano
Messages: 99
Registered: February 2012
Member
Hi,

within my program I have to delete a UML package except some contained elements. I.e. something like:

delete(Package package, List<Element> excepts)

As I have not found a method that enables this I have created my own. Of course it is not simple as the parents of the exceptions are not allowed to be deleted etc. However: as result my method provides a list of all elements within the package that can be deleted:

List<Element> deleteElements;

Now I want to delete these elements:

for (Element e : deleteElements) {
  EcoreUtil.delete(e);
}


Is this the best way to do it? Because as the list contains all elements not only grouping parent packages etc. this takes really long. My system manages to delete about 5 elements per seconds. In a huge model I have a lot of elements.

Is there a more efficient way to delete elements? If not, I will have to improve my algorithm that it does only provide parent elements if possible and not all contained children that can be deleted.

Regards,

Tex
Re: Deleting elements efficiently [message #912496 is a reply to message #912366] Thu, 13 September 2012 16:57 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26050
Registered: July 2009
Senior Member
Tex,

If you look at what that does:

public static void delete(EObject eObject)
{
EObject rootEObject = getRootContainer(eObject);
Resource resource = rootEObject.eResource();

Collection<EStructuralFeature.Setting> usages;
if (resource == null)
{
usages = UsageCrossReferencer.find(eObject, rootEObject);
}
else
{
ResourceSet resourceSet = resource.getResourceSet();
if (resourceSet == null)
{
usages = UsageCrossReferencer.find(eObject, resource);
}
else
{
usages = UsageCrossReferencer.find(eObject, resourceSet);
}
}

for (EStructuralFeature.Setting setting : usages)
{
if (setting.getEStructuralFeature().isChangeable())
{
remove(setting, eObject);
}
}

remove(eObject);
}

You can imagine that doing a UsageCrossReferencer.findAll would visit
the whole model just once, looking for all the objects, rather than
visiting the whole model once per object. That ought to be a lot faster.


On 13/09/2012 2:41 PM, Tex Iano wrote:
> Hi,
>
> within my program I have to delete a UML package except some contained
> elements. I.e. something like:
>
> delete(Package package, List<Element> excepts)
>
> As I have not found a method that enables this I have created my own.
> Of course it is not simple as the parents of the exceptions are not
> allowed to be deleted etc. However: as result my method provides a
> list of all elements within the package that can be deleted:
>
> List<Element> deleteElements;
>
> Now I want to delete these elements:
>
>
> for (Element e : deleteElements) {
> EcoreUtil.delete(e);
> }
>
>
> Is this the best way to do it? Because as the list contains all
> elements not only grouping parent packages etc. this takes really
> long. My system manages to delete about 5 elements per seconds. In a
> huge model I have a lot of elements.
> Is there a more efficient way to delete elements? If not, I will have
> to improve my algorithm that it does only provide parent elements if
> possible and not all contained children that can be deleted.
>
> Regards,
>
> Tex
Previous Topic:Acceleo only works the first time
Next Topic:Strange behaviour with getAppliedStereoTypes(), getAppliedStereoType
Goto Forum:
  


Current Time: Fri Sep 19 07:52:00 GMT 2014

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

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