Esempio n. 1
0
    private TreeNode<?> traverse(Enumeration children) {
      if (children.hasMoreElements()) {
        TreeNode<?> node = (TreeNode<?>) children.nextElement();
        nodes.push(node);

        Enumeration newChildren = Collections.enumeration(node.getChildren());
        childrenEnums.push(newChildren);

        return traverse(newChildren);
      } else {
        childrenEnums.pop();
        TreeNode<?> next = nodes.peek();
        nodes.pop();
        return next;
      }
    }
Esempio n. 2
0
    private TreeNode<?> traverse(Enumeration children) {
      // If more children are available step down.
      if (children.hasMoreElements()) {
        TreeNode<?> child = (TreeNode<?>) children.nextElement();
        childrenEnums.push(Collections.enumeration(child.getChildren()));

        return child;
      }

      // If no children are left, we return to a higher level.
      childrenEnums.pop();

      // If there are no more levels left, there is no next
      // element to return.
      if (childrenEnums.isEmpty()) return null;
      else {
        return traverse((Enumeration) childrenEnums.peek());
      }
    }
Esempio n. 3
0
 PostOrderEnumeration(TreeNode<?> node) {
   nodes.push(node);
   childrenEnums.push(Collections.enumeration(node.getChildren()));
 }
Esempio n. 4
0
 PreOrderEnumeration(TreeNode<?> node) {
   next = node;
   childrenEnums.push(Collections.enumeration(node.getChildren()));
 }