@ParametersAreNonnullByDefault
See: Description
Interface | Description |
---|---|
TreeDef<T> |
A function which defines a tree structure.
|
TreeDef.Parented<T> |
A pair of functions which define a doubly-linked tree, where nodes know about both their parent and their children.
|
Class | Description |
---|---|
TreeComparison<E,A> |
A mechanism for comparing trees.
|
TreeComparison.SameType<T> |
An API for comparing trees which have been mapped to the same type.
|
TreeIterable |
Creates
Iterable s that iterate across a tree defined by a TreeDef in various orders. |
TreeNode<T> |
Class for manually constructing a tree, or for copying an existing tree.
|
TreeQuery |
Queries against
TreeDef trees, such as lowest common ancestor, list of parents, etc. |
TreeStream |
Creates
Stream s that iterate across a tree defined by a TreeDef in various orders. |
This package contains generic interfaces for defining a tree structure on existing data, as well as utilties for traversing, querying, copying, and comparing these trees.
TreeDef
defines a “singly-linked” tree, where nodes know their children but not their parents. TreeDef.Parented
defines a “double-linked” tree, where children also know who their parents are.
Once you have defined a TreeDef
, you can use TreeIterable
to iterate over it, or TreeStream
to iterate over it as a Java 8 Stream
.
TreeQuery
helps with queries such as:
isDescendantOf
lowestCommonAncestor
path
findByPath
copyLeavesIn
and copyRootOut
Generally, in a TreeDef<T>
, the T
type contains both the tree’s data and its tree structure. For example, in a TreeDef<File>
, the File
contains both its name and its child folders and files. Sometimes you’d like to copy the tree’s data independently of its tree structure, or to stuff data without innate tree structure into a newly created tree structure. TreeNode
is a general-purpose doubly-linked tree with mechanisms for:
If you need to compare trees, TreeComparison
has you covered, and can even compare trees of different types. If the nodes in your tree have a good toString()
implementation, then you can combine TreeNode.createTestData
to create easy-to-read tests with helpful error messages:
TreeNode<String> expected = TreeNode.createTestData(
"root",
" middle",
" child",
" middle",
" child");
TreeComparison.of(expected, MyTreeType.treeDef(), myTree)
.mapToSame(TreeNode::getContent, MyTreeType::toString)
.assertEqual();