Alphabetically sorts children under the specified parent.

@param parent Parent whose child nodes (Treenode) are to be sorted.
@param recurse If true, sorting is recursed through all children.
426986
public static void sort(BaseComponent parent, boolean recurse) {
        if (parent == null || parent.getChildren().size() < 2) {
            return;
        }

        int i = 1;
        int size = parent.getChildren().size();

        while (i < size) {
            Treenode item1 = (Treenode) parent.getChildren().get(i - 1);
            Treenode item2 = (Treenode) parent.getChildren().get(i);

            if (compare(item1, item2) > 0) {
                parent.swapChildren(i - 1, i);
                i = i == 1 ? 2 : i - 1;
            } else {
                i++;
            }
        }

        if (recurse) {
            for (BaseComponent child : parent.getChildren()) {
                sort(child, recurse);
            }
        }
    }
1116705
public static <T> boolean isDescendantOf(TreeDef.Parented<T> treeDef, T child, T parent) {
		T candidateParent = treeDef.parentOf(child);
		while (candidateParent != null) {
			if (candidateParent.equals(parent)) {
				return true;
			} else {
				candidateParent = treeDef.parentOf(candidateParent);
			}
		}
		return false;
	}
1038398
protected void clearTreeLevel(CmsUUID parentId) {

        // create a new list to avoid concurrent modifications
        Collection<?> children = m_treeContainer.getChildren(parentId);
        // may be null when monkey clicking
        if (children != null) {
            List<Object> childIds = new ArrayList<Object>(m_treeContainer.getChildren(parentId));
            for (Object childId : childIds) {
                m_treeContainer.removeItemRecursively(childId);
            }
        }
    }
761401
public RedwoodConfiguration handler(final LogRecordHandler parent, final LogRecordHandler child){
    tasks.add(new Runnable() { public void run() { Redwood.appendHandler(parent, child);} });
    return this;
  }
1277720
public void sortChildrenByContent(Comparator<? super T> comparator) {
		Comparator<TreeNode<T>> byContent = Comparator.comparing(TreeNode::getContent, comparator);
		sortChildrenByNode(byContent);
	}
1290406
public static void remove(Element elem, boolean recurse) {
		elem.removeAttributeNS(URI, SRC_ATTR);
		elem.removeAttributeNS(URI, LINE_ATTR);
		elem.removeAttributeNS(URI, COL_ATTR);
		if (recurse) {
			NodeList children = elem.getChildNodes();
			for (int i = 0; i < children.getLength(); i++) {
				Node child = children.item(i);
				if (child.getNodeType() == Node.ELEMENT_NODE) {
					remove((Element) child, recurse);
				}
			}
		}
	}
928791
public void setParent( IVarDef parent)
    {
    super.setParent( parent);

    // Reset ancestry for all descendants.
    if( members_ != null)
      {
      for( IVarDef member : members_)
        {
        member.setParent( this);
        }
      }
    }
1305072
func (t *treeGenerator) recurse(parent *node.Node, left *int, currentDepth, maxDepth int, trpls []*triple.Triple) ([]*triple.Triple, error) {
	if *left < 1 {
		return trpls, nil
	}
	for i, last := 0, *left <= t.branch; i < t.branch; i++ {
		offspring, err := t.newNode(i, parent.ID().String())
		if err != nil {
			return trpls, err
		}
		trpl, err := t.newTriple(parent, offspring)
		if err != nil {
			return trpls, err
		}
		trpls = append(trpls, trpl)
		(*left)--
		if *left < 1 {
			break
		}
		if currentDepth < maxDepth && !last {
			ntrpls, err := t.recurse(offspring, left, currentDepth+1, maxDepth, trpls)
			if err != nil {
				return ntrpls, err
			}
			trpls = ntrpls
		}
		if *left < 1 {
			break
		}
	}
	return trpls, nil
}
1073725
public DiffNode dispatch(final DiffNode parentNode,
							 final Instances parentInstances,
							 final Accessor accessor)
	{
		Assert.notNull(parentInstances, "parentInstances");
		Assert.notNull(accessor, "accessor");

		final DiffNode node = compare(parentNode, parentInstances, accessor);
		if (parentNode != null && isReturnableResolver.isReturnable(node))
		{
			parentNode.addChild(node);
		}
		if (node != null)
		{
			node.addCategories(categoryResolver.resolveCategories(node));
		}
		return node;
	}
112410
private void recurse(final Block root, final boolean listMode)
    {
        Block block, list;
        Line line = root.lines;

        if (listMode)
        {
            root.removeListIndent(this.config);
            if (this.useExtensions && root.lines != null && root.lines.getLineType(this.config) != LineType.CODE)
            {
                root.id = root.lines.stripID();
            }
        }

        while (line != null && line.isEmpty)
        {
            line = line.next;
        }
        if (line == null)
        {
            return;
        }

        while (line != null)
        {
            final LineType type = line.getLineType(this.config);
            switch (type)
            {
            case OTHER:
            {
                final boolean wasEmpty = line.prevEmpty;
                while (line != null && !line.isEmpty)
                {
                    final LineType t = line.getLineType(this.config);
                    if ((listMode || this.useExtensions) && (t == LineType.OLIST || t == LineType.ULIST))
                    {
                        break;
                    }
                    if (this.useExtensions && (t == LineType.CODE || t == LineType.FENCED_CODE))
                    {
                        break;
                    }
                    if (t == LineType.HEADLINE || t == LineType.HEADLINE1 || t == LineType.HEADLINE2
                            || t == LineType.HR
                            || t == LineType.BQUOTE || t == LineType.XML)
                    {
                        break;
                    }
                    line = line.next;
                }
                final BlockType bt;
                if (line != null && !line.isEmpty)
                {
                    bt = (listMode && !wasEmpty) ? BlockType.NONE : BlockType.PARAGRAPH;
                    root.split(line.previous).type = bt;
                    root.removeLeadingEmptyLines();
                }
                else
                {
                    bt = (listMode && (line == null || !line.isEmpty) && !wasEmpty) ? BlockType.NONE
                            : BlockType.PARAGRAPH;
                    root.split(line == null ? root.lineTail : line).type = bt;
                    root.removeLeadingEmptyLines();
                }
                line = root.lines;
                break;
            }
            case CODE:
                while (line != null && (line.isEmpty || line.leading > 3))
                {
                    line = line.next;
                }
                block = root.split(line != null ? line.previous : root.lineTail);
                block.type = BlockType.CODE;
                block.removeSurroundingEmptyLines();
                break;
            case XML:
                if (line.previous != null)
                {
                    // FIXME ... this looks wrong
                    root.split(line.previous);
                }
                root.split(line.xmlEndLine).type = BlockType.XML;
                root.removeLeadingEmptyLines();
                line = root.lines;
                break;
            case BQUOTE:
                while (line != null)
                {
                    if (!line.isEmpty
                            && (line.prevEmpty && line.leading == 0 && line.getLineType(this.config) != LineType.BQUOTE))
                    {
                        break;
                    }
                    line = line.next;
                }
                block = root.split(line != null ? line.previous : root.lineTail);
                block.type = BlockType.BLOCKQUOTE;
                block.removeSurroundingEmptyLines();
                block.removeBlockQuotePrefix();
                this.recurse(block, false);
                line = root.lines;
                break;
            case HR:
                if (line.previous != null)
                {
                    // FIXME ... this looks wrong
                    root.split(line.previous);
                }
                root.split(line).type = BlockType.RULER;
                root.removeLeadingEmptyLines();
                line = root.lines;
                break;
            case FENCED_CODE:
                line = line.next;
                while (line != null)
                {
                    if (line.getLineType(this.config) == LineType.FENCED_CODE)
                    {
                        break;
                    }
                    // TODO ... is this really necessary? Maybe add a special
                    // flag?
                    line = line.next;
                }
                if (line != null)
                {
                    line = line.next;
                }
                block = root.split(line != null ? line.previous : root.lineTail);
                block.type = BlockType.FENCED_CODE;
                block.meta = Utils.getMetaFromFence(block.lines.value);
                block.lines.setEmpty();
                if (block.lineTail.getLineType(this.config) == LineType.FENCED_CODE)
                {
                    block.lineTail.setEmpty();
                }
                block.removeSurroundingEmptyLines();
                break;
            case HEADLINE:
            case HEADLINE1:
            case HEADLINE2:
                if (line.previous != null)
                {
                    root.split(line.previous);
                }
                if (type != LineType.HEADLINE)
                {
                    line.next.setEmpty();
                }
                block = root.split(line);
                block.type = BlockType.HEADLINE;
                if (type != LineType.HEADLINE)
                {
                    block.hlDepth = type == LineType.HEADLINE1 ? 1 : 2;
                }
                if (this.useExtensions)
                {
                    block.id = block.lines.stripID();
                }
                block.transfromHeadline();
                root.removeLeadingEmptyLines();
                line = root.lines;
                break;
            case OLIST:
            case ULIST:
                while (line != null)
                {
                    final LineType t = line.getLineType(this.config);
                    if (!line.isEmpty
                            && (line.prevEmpty && line.leading == 0 && !(t == LineType.OLIST || t == LineType.ULIST)))
                    {
                        break;
                    }
                    line = line.next;
                }
                list = root.split(line != null ? line.previous : root.lineTail);
                list.type = type == LineType.OLIST ? BlockType.ORDERED_LIST : BlockType.UNORDERED_LIST;
                list.lines.prevEmpty = false;
                list.lineTail.nextEmpty = false;
                list.removeSurroundingEmptyLines();
                list.lines.prevEmpty = list.lineTail.nextEmpty = false;
                this.initListBlock(list);
                block = list.blocks;
                while (block != null)
                {
                    this.recurse(block, true);
                    block = block.next;
                }
                list.expandListParagraphs();
                break;
            default:
                line = line.next;
                break;
            }
        }
    }
548108
private void buildGroupedRoot(Map<?,?> groupedItems, RecursiveTreeItem parent, int groupIndex) {
        boolean setRoot = false;
        if (parent == null) {
            parent = new RecursiveTreeItem<>(new RecursiveTreeObject(), RecursiveTreeObject::getChildren);
            setRoot = true;
        }

        for (Map.Entry<?, ?> entry : groupedItems.entrySet()) {
            Object key = entry.getKey();
            RecursiveTreeObject groupItem = new RecursiveTreeObject<>();
            groupItem.setGroupedValue(key);
            groupItem.setGroupedColumn(groupOrder.get(groupIndex));

            RecursiveTreeItem node = new RecursiveTreeItem<>(groupItem, RecursiveTreeObject::getChildren);
            // TODO: need to be removed once the selection issue is fixed
            node.expandedProperty().addListener((o, oldVal, newVal) -> {
                getSelectionModel().clearSelection();
            });

            parent.originalItems.add(node);
            parent.getChildren().add(node);

            Object children = entry.getValue();
            if (children instanceof List) {
                node.originalItems.addAll((List) children);
                node.getChildren().addAll((List) children);
            } else if (children instanceof Map) {
                buildGroupedRoot((Map) children, node, groupIndex + 1);
            }
        }

        // update ui
        if (setRoot) {
            final RecursiveTreeItem<S> newParent = parent;
            JFXUtilities.runInFX(() -> {
                ArrayList<TreeTableColumn<S, ?>> sortOrder = new ArrayList<>();
                sortOrder.addAll(getSortOrder());
                internalSetRoot = true;
                setRoot(newParent);
                internalSetRoot = false;
                getSortOrder().addAll(sortOrder);
                getSelectionModel().select(0);
            });
        }
    }
540707
private void addTasks(MpxjTreeNode parentNode, ChildTaskContainer parent)
   {
      for (Task task : parent.getChildTasks())
      {
         final Task t = task;
         MpxjTreeNode childNode = new MpxjTreeNode(task, TASK_EXCLUDED_METHODS)
         {
            @Override public String toString()
            {
               return t.getName();
            }
         };
         parentNode.add(childNode);
         addTasks(childNode, task);
      }
   }
1306983
public static void sortNode(TreeNode node, Comparator comparator) {
        TreeNodeList children = (TreeNodeList) node.getChildren();

        if (children != null && !children.isEmpty()) {
            Object[] childrenArray = children.toArray();
            Arrays.sort(childrenArray, comparator);
            for (int i = 0; i < childrenArray.length; i++) {
                children.setSibling(i, (TreeNode) childrenArray[i]);
            }

            for (int i = 0; i < children.size(); i++) {
                sortNode(children.get(i), comparator);
            }
        }
    }
254028
protected final void setParentNode(final DiffNode parentNode)
	{
		if (this.parentNode != null && this.parentNode != parentNode)
		{
			throw new IllegalStateException("The parent of a node cannot be changed, once it's set.");
		}
		this.parentNode = parentNode;
	}
387941
private List<Entry> getChildNodes(DirectoryEntry parent)
   {
      List<Entry> result = new ArrayList<Entry>();
      Iterator<Entry> entries = parent.getEntries();
      while (entries.hasNext())
      {
         result.add(entries.next());
      }
      return result;
   }
1050687
private static void expandChildren(BaseComponent parent, int depth) {
        if (parent == null || depth <= 0) {
            return;
        }

        depth--;

        for (Object object : parent.getChildren()) {
            Treenode item = (Treenode) object;
            item.setCollapsed(depth <= 0);
            expandChildren(item, depth);
        }
    }
403241
public static void removeRecursive(ResultHierarchy hierarchy, Result child) {
    for(It<Result> iter = hierarchy.iterParents(child); iter.valid(); iter.advance()) {
      hierarchy.remove(iter.get(), child);
    }
    for(It<Result> iter = hierarchy.iterChildren(child); iter.valid(); iter.advance()) {
      removeRecursive(hierarchy, iter.get());
    }
  }