A parent/children data structure
Find a file
Paul Campbell 04e0e83748
Upgrade dependencies (#59)
* [changelog] clean up

* Upgrade kemitix-maven-tiles from 1.3.1 to 2.4.1

Pin pitest-junit5-plugin at 0.9. From 0.10+ is breaks.

* Fix NodeItem.findInPath(List) uses integer for loops to iterate over a List

[ERROR] Method net.kemitix.node.NodeItem.findInPath(List) uses integer based for loops to iterate over a List [net.kemitix.node.NodeItem] At NodeItem.java:[line 269] LII_LIST_INDEXED_ITERATING

* Upgrade kemitix-checkstyle-ruleset from 4.0.1 to 5.4.0
2020-03-21 10:35:21 +00:00
.github Disable JDK 13 test builds (#58) 2020-03-21 10:31:58 +00:00
src Upgrade dependencies (#59) 2020-03-21 10:35:21 +00:00
.gitignore Switch to trunk-based-development (#34) 2018-10-09 22:08:43 +01:00
CHANGELOG.org Upgrade dependencies (#59) 2020-03-21 10:35:21 +00:00
LICENSE.txt Switch to trunk-based-development (#34) 2018-10-09 22:08:43 +01:00
pom.xml Upgrade dependencies (#59) 2020-03-21 10:35:21 +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")