A parent/children data structure
Find a file
Paul Campbell 323fba13c4 Merge branch release/0.2.0 into master
Demo of full-path node name
insertInPath() uses setData()
Dynamic node names
New tests following mutation testing
Tidy the Node interface
Named nodes
Update code style
Drop lombok in production (still using it in test)
2016-05-25 11:44:51 +01:00
.idea .idea/checkstyle-idea.xml: added 2016-05-24 23:31:54 +01:00
src Merge pull request #9 from kemitix/demo-of-full-path-node-name 2016-05-24 23:03:11 +01:00
.gitignore .idea: add IntelliJ configuration 2016-03-14 14:35:57 +00:00
.travis.yml .travis.yml: added 2016-01-09 17:19:54 +00:00
CHANGELOG CHANGELOG 2016-05-25 11:44:50 +01:00
checkstyle.xml Initial commit 2016-01-09 17:08:52 +00:00
LICENSE Initial commit 2016-01-09 17:10:37 +00:00
node.iml .idea: upgrade findbugs and assertion verification 2016-05-24 23:30:46 +01:00
pom.xml pom.xml: version set to 0.2.0 2016-05-25 11:44:50 +01:00
README.md Add Gitter badge 2016-05-18 06:51:26 +00:00

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