Skip navigation links

com.diffplug.durian:durian-collect:1.2.0 by DiffPlug

@ParametersAreNonnullByDefault

Package com.diffplug.common.tree

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.

See: Description

Package com.diffplug.common.tree Description

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:

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();
Skip navigation links

com.diffplug.durian:durian-collect:1.2.0 by DiffPlug