How can I delete all attributes owned by a classifier in modelio?

26 Views Asked by At

How to remove attribute from owner in modelio?

Here is my code;

EList<Attribute> attributeList = classifier.getOwnedAttribute();
attributeList.removeAll(attributeList);

And I got an error like this

1

There are 1 best solutions below

0
Cédric On

Hello, Your code only detach the attributes from their owner, it does not delete them.

To delete one of them, use:

classifier.getOwnedAttribute().get(0).delete();

If you want to delete all of them, use :

List<Attribute> attributeList = classifier.getOwnedAttribute();
while (! attributeList.isEmpty()) {
    attributeList.get(0).delete();
}

Do not write:

for (Attribute a : classifier.getOwnedAttribute()) {
    a.delete(); // <== ConcurrentModificationException on second execution
}

You may write instead:

for (Attribute a : new ArrayList<>(classifier.getOwnedAttribute())) {
    a.delete(); // works
}

but it is less efficient than the first solution.