A parent/children data structure
Find a file
Paul Campbell f4d1d6e689 Merge branch release/0.4.0 into master
Upgrade kemitix-parent to 2.0.0
Add ImmutableTree implementation
Switch to static factory constructors
2016-09-13 07:39:05 +01:00
src NodeItem: remove support for dynamic names 2016-09-04 22:19:22 +01:00
.gitignore .gitignore: ignore intellij project files 2016-08-21 10:49:05 +01:00
.travis.yml Report code coverage to coveralls.io 2016-06-03 16:48:49 +01:00
CHANGELOG CHANGELOG 2016-09-13 07:39:05 +01:00
LICENSE Initial commit 2016-01-09 17:10:37 +00:00
pom.xml pom.xml: version set to 0.4.0 2016-09-13 07:39:05 +01:00
README.md Merge branch release/0.4.0 into master 2016-09-13 07:39:05 +01:00

Build Status Coverage Status

node

Join the chat at https://gitter.im/kemitix/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]"
|-> "child"
\-> "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")