A parent/children data structure
386cb72c0c
* Bump tiles-maven-plugin from 2.17 to 2.18 Bumps [tiles-maven-plugin](https://github.com/repaint-io/maven-tiles) from 2.17 to 2.18. - [Release notes](https://github.com/repaint-io/maven-tiles/releases) - [Changelog](https://github.com/repaint-io/maven-tiles/blob/master/CHANGELOG.adoc) - [Commits](https://github.com/repaint-io/maven-tiles/compare/tiles-maven-plugin-2.17...tiles-maven-plugin-2.18) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * Test build with JDK 15 Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Paul Campbell <pcampbell@kemitix.net> |
||
---|---|---|
.github | ||
src | ||
.gitignore | ||
CHANGELOG.org | ||
LICENSE.txt | ||
pom.xml | ||
README.org |
Node
A parent/children data structure
Usage
Add as a dependency in your pom.xml
:
<dependency>
<groupId>net.kemitix</groupId>
<artifactId>node</artifactId>
<version>${node.version}</version>
</dependency>
The library consits of an interface Node
and an implementation NodeItem
.
Create a root node
Node<String> root = new NodeItem<>("[root]");
Get the contents of the node
String rootData = root.getData(); // returns "[root]"
Add a child node
Node<String> child = root.createChild("child");
Which is shorthand for:
Node<String> child = new NodeItem<>("child");
root.addChild(child);
The tree now looks like:
"[root]" \-> "child"
Get the child node
Node<String> childNode = root.getChild("child");
Create a chain of nodes
root.createDescendantLine(Arrays.asList("alpha", "beta", "gamma"));
"[root]" \-> "alpha" \-> "beta" \-> "gamma"
Walk the tree to find a node
Optional<Node<String>> foundNode = root.walkTree(Arrays.asList("alpha", "beta", "gamma"));
if (foundNode.isPresent()) {
String betaData = foundNode.get().getParent().getData();
// returns "beta"
}
Get all children of a node
Set<Node<String>> children = root.getChildren();
children.size();
// returns 2 ("child" and "alpha")