0

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 Answers1

0

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.

Cédric
  • 334
  • 2
  • 8