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.

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