子供たちだけでなく、の子孫(サブツリーのノード)をすべて取得しようとしている可能性があります。子供を簡単に取得するにはgetChildren()で十分でしょう。専門用語についてはhttps://en.wikipedia.org/wiki/Tree_(data_structure)#Terminologyをご覧ください。
同じパラメータを使用して同じメソッドを再帰的に呼び出すことが問題です。あなたが意味することは、おそらく次のようである:
public Collection<?> recursiveTreeSearch(Object objectItemID, Collection<?> siblings){
if (evoltWebUI.getPrimaryTreeView().hasChildren(objectItemID)==true){
// here you had an issue as well, as your line in fact did nothing visible to the caller
siblings.addAll(evoltWebUI.getPrimaryTreeView().getChildren(objectItemID));
for (int i = 0; i < evoltWebUI.getPrimaryTreeView().getChildren(objectItemID).size(); i++) {
// here was your bug:
recursiveTreeSearch(evoltWebUI.getPrimaryTreeView().getChildren(objectItemID).get(i), siblings);
}
}
return siblings;
};
これは無限ループを生成し、望ましい結果を返すべきではありません。このように使用します。recursiveTreeSearch(itemId、new ArrayList())。メソッドを作るために
は見た目が良く、わずかに、より効率的なあなたは、子どもたちがローカル変数にオブジェクトを抽出し、foreachループを使用し、より良い方法やパラメータに名前を付ける必要があります。
public Collection<?> getDescendants(final Object itemId) {
return getDescendantsRec(itemId, new ArrayList<Object>());
}
private Collection<?> getDescendantsRec(final Object itemId, final Collection<Object> siblings) {
Collection<?> childrenIds = evoltWebUI.getPrimaryTreeView().getChildren(itemId);
if (childrenIds.size() > 0){
siblings.addAll(childrenIds);
for (Object childItemId : childrenIds) {
getDescendantsRec(childItemId, siblings);
}
}
return siblings;
};
・ホープ、このことができます。
私はあなたのツリーの兄弟の量を減らすことはないので、テストしないと思います....したがって、あなたのメソッドは同じパラメータで常に呼び出され、決して終了できません – endkugelfang
私はevoltWebUIが変更/最終的にオブジェクトを何度も再帰します。それが子供を持っている場合、それは常に再発するでしょう。それは前に述べたようにしなければならないテストです – efekctive
evoltWebUIをparamにします。現在の子に子があるかどうかをテストしてから再帰する – efekctive