A parent/children data structure
Go to file
dependabot[bot] f41ce4429a
Bump junit-jupiter from 5.7.1 to 5.7.2 (#87)
Bumps [junit-jupiter](https://github.com/junit-team/junit5) from 5.7.1 to 5.7.2.
- [Release notes](https://github.com/junit-team/junit5/releases)
- [Commits](https://github.com/junit-team/junit5/compare/r5.7.1...r5.7.2)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-17 08:56:18 +01:00
.github Upgrade to GitHub-native Dependabot (#85) 2021-04-30 11:34:56 +01:00
src Use list-head-tail (#64) 2020-04-03 09:14:57 +01:00
.gitignore Switch to trunk-based-development (#34) 2018-10-09 22:08:43 +01:00
CHANGELOG.org Test build on JDK 13 (#62) 2020-03-22 21:59:56 +00:00
LICENSE.txt Switch to trunk-based-development (#34) 2018-10-09 22:08:43 +01:00
pom.xml Bump junit-jupiter from 5.7.1 to 5.7.2 (#87) 2021-05-17 08:56:18 +01:00
README.org Clean up changelog and readme, and remove external build dependencies (#38) 2018-12-24 08:51:18 +00:00

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")