T - the node id typeA - the attachment biz object typepublic final class TreeNode<T extends Serializable & Comparable<? super T>,A> extends BaseNode<T,A>
Tree node structure ┌───────────────────────────┐ │ 0 │ │ ┌─────┴─────┐ │ │ 1 2 │ │ ┌───┴───┐ ┌───┴───┐ │ │ 3 4 5 6 │ │ ┌─┴─┐ ┌─┘ │ │ 7 8 9 │ └───────────────────────────┘ 上面这棵二叉树中的遍历方式: DFS前序遍历:0137849256 DFS中序遍历:7381940526 DFS后序遍历:7839415620 BFS广度优先:0123456789 CFS孩子优先:0123478956 (备注:教科书上没有CFS一说,是我为方便说明描述而取名的)
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DEFAULT_ROOT_ID |
attach, available, childrenCount, degree, enabled, leftLeafCount, level, nid, path, pid, siblingOrdinal, treeDepth, treeLeafCount, treeMaxDegree, treeNodeCount| 限定符和类型 | 方法和说明 |
|---|---|
<E extends TreeTrait<T,A,E>> |
convert(Function<TreeNode<T,A>,E> convert) |
<E extends TreeTrait<T,A,E>> |
convert(Function<TreeNode<T,A>,E> convert,
boolean containsUnavailable) |
List<FlatNode<T,A>> |
flatBFS()
广度优先遍历BFS(Breath-First Search)
|
List<FlatNode<T,A>> |
flatCFS()
按层级方式展开节点:兄弟节点相邻
子节点优先搜索CFS(Children-First Search)
Should be invoking after
mount(List)
Note:为了构建复杂表头,保证左侧的叶子节点必须排在右侧叶子节点前面,此处不能用广度优先搜索策略 |
List<FlatNode<T,A>> |
flatDFS()
深度优先搜索DFS(Depth-First Search):使用前序遍历
Should be invoking after
mount(List) |
void |
forEachChild(Consumer<TreeNode<T,A>> childProcessor) |
LinkedList<TreeNode<T,A>> |
getChildren() |
void |
ifChildrenPresent(Consumer<LinkedList<TreeNode<T,A>>> childrenProcessor) |
<E extends BaseNode<T,A>> |
mount(List<E> nodes) |
<E extends BaseNode<T,A>> |
mount(List<E> list,
boolean ignoreOrphan)
Mount a tree
|
String |
print(Function<TreeNode<T,A>,CharSequence> nodeLabel) |
String |
toString() |
void |
traverse(Consumer<TreeNode<T,A>> action)
Traverses the tree
|
clone, getAttach, getChildrenCount, getDegree, getLeftLeafCount, getLevel, getNid, getPath, getPid, getSiblingOrdinal, getTreeDepth, getTreeLeafCount, getTreeMaxDegree, getTreeNodeCount, isAvailable, isEnabledpublic <E extends BaseNode<T,A>> TreeNode<T,A> mount(List<E> list, boolean ignoreOrphan)
list - 子节点列表ignoreOrphan - true忽略孤儿节点,false如果有孤儿节点则会抛异常public List<FlatNode<T,A>> flatDFS()
Should be invoking after mount(List)
public List<FlatNode<T,A>> flatCFS()
子节点优先搜索CFS(Children-First Search)
Should be invoking after mount(List)
Note:为了构建复杂表头,保证左侧的叶子节点必须排在右侧叶子节点前面,此处不能用广度优先搜索策略
public List<FlatNode<T,A>> flatBFS()
public void ifChildrenPresent(Consumer<LinkedList<TreeNode<T,A>>> childrenProcessor)
public void traverse(Consumer<TreeNode<T,A>> action)
action - the action functionpublic <E extends TreeTrait<T,A,E>> E convert(Function<TreeNode<T,A>,E> convert, boolean containsUnavailable)
public String print(Function<TreeNode<T,A>,CharSequence> nodeLabel) throws IOException
IOExceptionpublic LinkedList<TreeNode<T,A>> getChildren()
Copyright © 2023. All rights reserved.