/** Recursively sorts all children using the given comparator of TreeNode. */ public void sortChildrenByNode(Comparator<TreeNode<T>> comparator) { requireNonNull(comparator); Collections.sort(children, comparator); for (TreeNode<T> child : children) { child.sortChildrenByNode(comparator); } }
/** Recursively sorts all children using the given comparator of their content. */ public void sortChildrenByContent(Comparator<? super T> comparator) { requireNonNull(comparator); Comparator<TreeNode<T>> byContent = Comparator.comparing(TreeNode::getContent, comparator); sortChildrenByNode(byContent); }