A parent/children data structure
Find a file
dependabot-preview[bot] d9a31a998b
Bump assertj-core from 3.13.2 to 3.15.0 (#54)
Bumps [assertj-core](https://github.com/joel-costigliola/assertj-core) from 3.13.2 to 3.15.0.
- [Release notes](https://github.com/joel-costigliola/assertj-core/releases)
- [Commits](https://github.com/joel-costigliola/assertj-core/compare/assertj-core-3.13.2...assertj-core-3.15.0)

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

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Paul Campbell <pcampbell@kemitix.net>
2020-03-20 12:39:09 +00:00
.github Replace Jenkins with GitHub Actions (#57) 2020-03-20 12:19:08 +00:00
src Switch to trunk-based-development (#34) 2018-10-09 22:08:43 +01:00
.gitignore Switch to trunk-based-development (#34) 2018-10-09 22:08:43 +01:00
CHANGELOG.org Replace Jenkins with GitHub Actions (#57) 2020-03-20 12:19:08 +00:00
LICENSE.txt Switch to trunk-based-development (#34) 2018-10-09 22:08:43 +01:00
pom.xml Bump assertj-core from 3.13.2 to 3.15.0 (#54) 2020-03-20 12:39:09 +00: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")