No dependencies. One top-level class. Depth-first and breadth-first node streaming, visiting, and searching. Prune off sections of the tree using predicate filters. ToString of a tree returns an ascii representation of the tree. Two nodes with the same data are equal. Two trees with the same structure and ordering of nodes with the same data are equal.
Tree<Integer> tree = node(1,
node(2,
node(5), node(5)),
node(6,
node(4), node(4)),
node(2,
node(3), node(3))).asTree();
Optional<Integer> firstIntegerGreaterThan4DepthFirst = tree.depthFirstSearch(val -> val > 4);
Optional<Integer> firstIntegerGreaterThan4BreadthFirst = tree.breadthFirstSearch(val -> val > 4);
assertTrue(firstIntegerGreaterThan4DepthFirst.isPresent());
assertTrue(firstIntegerGreaterThan4BreadthFirst.isPresent());
assertEquals((Integer) 5, firstIntegerGreaterThan4DepthFirst.get());
assertEquals((Integer) 6, firstIntegerGreaterThan4BreadthFirst.get());
System.out.println(tree);
1 -
|
|- 2
| |
| |- 5
| |
| |- 5
|
|- 6
| |
| |- 4
| |
| |- 4
|
|- 2
|
|- 3
|
|- 3
<dependencies>
<dependency>
<groupId>com.github.rutledgepaulv</groupId>
<artifactId>prune</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
This project is licensed under MIT license.