Builds a tree recursively
adding the children as necessary
@param node the node to build the tree based on
@return the compiled tree with all of its children
and childrens' children recursively
@throws Exception
358646
public static Tree buildTree(TreebankNode node) throws Exception {
        if (node.getLeaf())
            return toTree(node);
        else {
            List<TreebankNode> preChildren = children(node);
            List<Tree> children = new ArrayList<>();
            Tree t = toTree(node);
            for (int i = 0; i < preChildren.size(); i++) {
                children.add(buildTree(preChildren.get(i)));
            }

            t.connect(children);
            return t;

        }



    }
635453
private static function addTreeNode(array &$tree, $parent, $node, $prepend = false)
    {
        if ($parent === null) {
            if (array_key_exists($node, $tree)) {
                throw new \Exception('Node already exists');
            }
            if ($prepend) {
                $tree = array_merge([$node => []], $tree);
            } else {
                $tree[$node] = [];
            }

            return true;
        }
        foreach ($tree as $key => &$value) {
            if ($key === $parent) {
                return self::addTreeNode($value, null, $node, $prepend);
            } else {
                if (self::addTreeNode($value, $parent, $node, $prepend)) {
                    return true;
                }
            }
        }

        return false;
    }
79010
public static Optional<Node> getContainingNode(final Node node) {
        try {
            if (node.getDepth() == 0) {
                return empty();
            }

            // check ancestors recursively only either of the following two cases applies:
            // 1. the PARENT is a FEDORA_PAIRTREE
            // 2. the PARENT is FEDORA_NON_RDF_SOURCE_DESCRIPTION
            final Node parent = node.getParent();
            if (parent.isNodeType(FEDORA_PAIRTREE) || parent.isNodeType(FEDORA_NON_RDF_SOURCE_DESCRIPTION)) {
                return getContainingNode(parent);
            }
            return Optional.of(parent);
        } catch (final RepositoryException ex) {
            throw new RepositoryRuntimeException(ex);
        }
    }
293468
public void add(XmlReader node)
    {
        Check.notNull(node);

        final Element element = node.getElement();
        document.adoptNode(element);
        root.appendChild(element);
    }
357276
public Tree<T> build() {
        Tree<T> result = base;
        if (null == base && treeStack.size() == 1) {
            result = treeStack.get(0);
        } else if (treeStack.size() > 0) {
            result = new TreeStack<T>(treeStack, base);
        }else if(null==base) {
            throw new IllegalArgumentException("base tree was not set");
        }

        return result;
    }
184330
public Node build() {
        ContainerNode ret = null;

        if (nodeType == NodeType.Component) {
            ret = new Component();
            ((Component) ret).setComponentType(componentType);
        } else if (nodeType == NodeType.Consumer) {
            ret = new Consumer();
            ((Consumer) ret).setEndpointType(endpointType);
        } else if (nodeType == NodeType.Producer) {
            ret = new Producer();
            ((Producer) ret).setEndpointType(endpointType);
        }
        ret.setCorrelationIds(correlationIds);
        ret.setOperation(operation);
        ret.setProperties(properties);
        ret.setUri(uri);
        ret.setDuration(duration);
        ret.setTimestamp(timestamp);

        for (int i = 0; i < nodes.size(); i++) {
            ret.getNodes().add(nodes.get(i).build());
        }

        // Check if template has been supplied for URI
        NodeUtil.rewriteURI(ret);

        return ret;
    }
1341311
protected List<R> visitChildren(ParentNode<? extends N> node) {
    List<R> results = new ArrayList<>(node.numChildren());
    for (N child : node.getChildren()) {
      results.add(visit(child));
    }
    return results;
  }
71667
public Node<T> addChild(Node<T> child) {
        if (children == null) {
            children = new ArrayList<Node<T>>();
        }
        child.parent = this;
        children.add(child);

        return child;
    }
953483
public void buildMemberSummary(XMLNode node, Content classContentTree) throws Exception {
        Content memberSummaryTree = writer.getMemberTreeHeader();
        configuration.getBuilderFactory().
                getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree);
        classContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree));
    }
1234361
public synchronized Node addNode(@NonNull Node node) {
        version++;

        if (buildMode == MeshBuildMode.MESH) {
            // :)
            val candidate = fillQueue.poll();

            // adding node to the candidate
            candidate.addDownstreamNode(node);

            // adding this node for future connections
            for (int e = 0; e < MAX_DOWNSTREAMS; e++)
                fillQueue.add(node);

            sortedNodes.add(node);
            Collections.sort(sortedNodes);
        } else {
            rootNode.addDownstreamNode(node);
        }

        // after all we add this node to the flattened map, for future access
        nodeMap.put(node.getId(), node);

        return node;
    }
84426
public void buildFieldDetails(XMLNode node,
            Content memberDetailsTree) throws Exception {
        configuration.getBuilderFactory().
                getFieldBuilder(writer).buildChildren(node, memberDetailsTree);
    }
848302
public function addNode(&$node)
    {
        //Nodes must be an instance graph Node;
        if (!$this->isNode($node)) {
            throw new \Exception("Node must be an instance of Graph\Node", PLATFORM_ERROR);
        }
        $nodedId = $node->getId();
        if (!empty($nodedId) && !isset($this->nodeSet[$node->getId()])) {
            $this->nodeSet[$node->getId()] = &$node;
        }
        return $this;
    }
1123863
private void buildNode(MessageMLParser context, org.w3c.dom.Node node) throws InvalidInputException, ProcessingException {
    switch (node.getNodeType()) {
      case org.w3c.dom.Node.TEXT_NODE:
        buildText((Text) node);
        break;

      case org.w3c.dom.Node.ELEMENT_NODE:
        buildElement(context, (org.w3c.dom.Element) node);
        break;

      default:
        throw new InvalidInputException("Invalid element \"" + node.getNodeName() + "\"");

    }
  }
229124
private static Stream<Node> streamChildNodes(Node node) {
        int children = node.getChildNodes().getLength();
        Node firstChild = node.getFirstChild();
        if (firstChild == null) return Stream.empty();
        return Stream.iterate(firstChild, prev -> prev != null ? prev.getNextSibling() : null)
            .limit(children)
            .filter(n -> n != null);
    }
1122448
private void build() {
    this.startNodes = new ArrayList<>();
    this.endNodes = new ArrayList<>();
    this.parentChildMap = new HashMap<>();
    for (DagNode node : this.nodes) {
      //If a Node has no parent Node, add it to the list of start Nodes
      if (node.getParentNodes() == null) {
        this.startNodes.add(node);
      } else {
        List<DagNode> parentNodeList = node.getParentNodes();
        for (DagNode parentNode : parentNodeList) {
          if (parentChildMap.containsKey(parentNode)) {
            parentChildMap.get(parentNode).add(node);
          } else {
            parentChildMap.put(parentNode, Lists.newArrayList(node));
          }
        }
      }
    }
    //Iterate over all the Nodes and add a Node to the list of endNodes if it is not present in the parentChildMap
    for (DagNode node : this.nodes) {
      if (!parentChildMap.containsKey(node)) {
        this.endNodes.add(node);
      }
    }
  }
338499
public static Node getNtResourceRecursively(Node node) throws ItemNotFoundException, RepositoryException
   {

      if (node.isNodeType("nt:resource"))
         return node;

      Item pi = node.getPrimaryItem();
      if (pi.isNode())
      {
         return getNtResourceRecursively((Node)pi);
      }
      throw new ItemNotFoundException("No nt:resource node found for " + node.getPath());
   }
289810
def _build_tree(self):
        

        groups = self._groups or self.get_children_paths(self.root_path)
        for group in groups:
            node = Node(name=group, parent=self.root)
            self.root.children.append(node)
            self._init_sub_groups(node)