Hello. I am trying to iterate over the Nodes
belonging to my Diagram
object.
I do so in the following way:
var itr = ticketMasterDiagram.nodes;
while (itr.next()) {
//perform my node-by-node task
}
I call a routine that iterates over Diagram.nodes
in the above way immediately after calling removeNodeData
on the model
belonging to my Diagram on one of the nodes. It is important that this change is reflected in the collection returned by nodes
that I iterate over subsequently.
When I do it this way, I get the following error:
Error: Collection was modified during iteration: Set(Node)#234
Perhaps you should iterate over a copy of the collection,
or you could collect items to be removed from the collection after the iteration.
How can I make a copy of the nodes
set which has the node which I delete removed from it, and doesn’t raise an error?
For example, if I make use the copy()
method from the Set
class here:
it makes a shallow copy of each Node. But presumbaly, as I advance the iterator with next
I will run into trouble when next
points to the Node that has been deleted? I suppose perhaps not if I make the copy after the Node deletion?
Thank you!