ツリーデータ構造を剪定する次の関数があります。
public static void pruneTree(final ConditionTreeNode treeNode) {
final List<ConditionTreeNode> subTrees = treeNode.getSubTrees();
for (ConditionTreeNode current : subTrees) {
pruneTree(current);
}
if(subTrees.isEmpty()) {
final ConditionTreeNode parent = treeNode.getParent();
parent.removeConditionTreeNode(treeNode);
}
if (treeNode.isLeaf()) {
//this is the base case
if (treeNode.isPrunable()) {
final ConditionTreeNode parent = treeNode.getParent();
parent.removeConditionTreeNode(treeNode);
}
return;
}
}
これを剪定する最善の方法を知りたいです。私は現在 ConcurrentModificationExceptions を取得しています。コレクションをコピーしてオリジナルを削除するか、イテレータから削除できることを読みました。この方法が機能するために何をする必要があるかを誰かが理解するのを手伝ってくれますか?