The node list gets generated correctly now using breadth first algorithm
authorn.hoffmann <n.hoffmann@localhost>
Tue, 19 Apr 2011 10:53:39 +0000 (10:53 +0000)
committern.hoffmann <n.hoffmann@localhost>
Tue, 19 Apr 2011 10:53:39 +0000 (10:53 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListContentProvider.java

index 45b14a240a83ff55339641828811931a6bec2192..a17c56a0a503afd56d350188b8ed65d5c4179f51 100644 (file)
@@ -57,27 +57,24 @@ public class PolytomousKeyListContentProvider implements
        @Override
        public Object[] getElements(Object inputElement) {
                if (inputElement instanceof PolytomousKey) {
-                       List result = new ArrayList();
+                       List<PolytomousKeyNode> result = new ArrayList<PolytomousKeyNode>();
 
                        PolytomousKeyNode root = ((PolytomousKey) inputElement).getRoot();
 
-                       // result.add(root);
-                       // result.addAll(root.getChildren());
-                       getChildren(result, root);
+                       getChildrenBreadthFirst(result, root);
                        return result.toArray();
                }
-               // else if (inputElement instanceof PolytomousKeyNode) {
-               // return ((PolytomousKeyNode) inputElement).getChildren().toArray();
-               // }
 
                return null;
        }
 
-       private void getChildren(List result, PolytomousKeyNode node) {
-               result.add(node);
-
-               for (PolytomousKeyNode internalNode : node.getChildren()) {
-                       getChildren(result, internalNode);
+       private void getChildrenBreadthFirst(List<PolytomousKeyNode> result,
+                       PolytomousKeyNode node) {
+               if (!node.getChildren().isEmpty()) {
+                       result.addAll(node.getChildren());
+                       for (PolytomousKeyNode internalNode : node.getChildren()) {
+                               getChildrenBreadthFirst(result, internalNode);
+                       }
                }
        }
 }