T - the node id typeA - the attachment biz object typepublic final class TreeNode<T extends Serializable & Comparable<? super T>,A extends Serializable> 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, siblingOrder, 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 |
forEach(Consumer<TreeNode<T,A>> action)
Traverses the tree
|
LinkedList<TreeNode<T,A>> |
getChildren() |
<E extends BaseNode<T,A>> |
mount(List<E> nodes) |
<E extends BaseNode<T,A>> |
mount(List<E> list,
boolean ignoreOrphan)
Mount a tree
|
static <T extends Serializable & Comparable<? super T>,A extends Serializable> |
of(BaseNode<T,A> node)
Returns a tree node
|
static <T extends Serializable & Comparable<? super T>,A extends Serializable> |
of(BaseNode<T,A> node,
Comparator<? super TreeNode<T,A>> siblingNodeSort) |
static <T extends Serializable & Comparable<? super T>,A extends Serializable> |
of(BaseNode<T,A> node,
Comparator<? super TreeNode<T,A>> siblingNodeSort,
boolean buildPath) |
String |
print(Function<TreeNode<T,A>,CharSequence> nodeLabel) |
String |
toString() |
clone, copy, getAttach, getChildrenCount, getDegree, getLeftLeafCount, getLevel, getNid, getPath, getPid, getSiblingOrder, getTreeDepth, getTreeLeafCount, getTreeMaxDegree, getTreeNodeCount, isAvailable, isEnabledpublic static <T extends Serializable & Comparable<? super T>,A extends Serializable> TreeNode<T,A> of(BaseNode<T,A> node)
node - the base nodepublic static <T extends Serializable & Comparable<? super T>,A extends Serializable> TreeNode<T,A> of(BaseNode<T,A> node, Comparator<? super TreeNode<T,A>> siblingNodeSort)
public static <T extends Serializable & Comparable<? super T>,A extends Serializable> TreeNode<T,A> of(BaseNode<T,A> node, Comparator<? super TreeNode<T,A>> siblingNodeSort, boolean buildPath)
public <E extends BaseNode<T,A>> TreeNode<T,A> mount(List<E> list, boolean ignoreOrphan)
list - 子节点列表ignoreOrphan - true忽略孤儿节点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 forEach(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 LinkedList<TreeNode<T,A>> getChildren()
public String print(Function<TreeNode<T,A>,CharSequence> nodeLabel) throws IOException
IOExceptionCopyright © 2022. All rights reserved.