A parent/children data structure
Paul Campbell
f7e50b8091
* pom.xml: version set to 0.8.0-SNAPSHOT * jenkins: added * mvn: add wrapper 3.5.3 * Upgrade parent to 5.1.0 * lombok: upgraded to 1.16.20 * assertj: upgraded to 3.9.1 * coveralls: removed * kemitix-maven-tiles: added * kemitix-checkstyle: tile added * Compile with java 1.8 * Reduce code coverage requirements * LICENSE: update * checkstyle: suppress outstanding npath complexity issues, etc * Bump kemitix-parent from 5.1.0 to 5.1.1 Bumps [kemitix-parent](https://github.com/kemitix/kemitix-parent) from 5.1.0 to 5.1.1. - [Release notes](https://github.com/kemitix/kemitix-parent/releases) - [Changelog](https://github.com/kemitix/kemitix-parent/blob/master/CHANGELOG) - [Commits](https://github.com/kemitix/kemitix-parent/compare/v5.1.0...v5.1.1) Signed-off-by: dependabot[bot] <support@dependabot.com> * Bump tiles-maven-plugin from 2.10 to 2.12 Bumps [tiles-maven-plugin](https://github.com/repaint-io/maven-tiles) from 2.10 to 2.12. - [Release notes](https://github.com/repaint-io/maven-tiles/releases) - [Changelog](https://github.com/repaint-io/maven-tiles/blob/master/CHANGELOG.adoc) - [Commits](https://github.com/repaint-io/maven-tiles/compare/tiles-maven-plugin-2.10...tiles-maven-plugin-2.12) Signed-off-by: dependabot[bot] <support@dependabot.com> * Bump assertj-core from 3.9.1 to 3.11.0 Bumps [assertj-core](https://github.com/joel-costigliola/assertj-core) from 3.9.1 to 3.11.0. - [Release notes](https://github.com/joel-costigliola/assertj-core/releases) - [Commits](https://github.com/joel-costigliola/assertj-core/compare/assertj-core-3.9.1...assertj-core-3.11.0) Signed-off-by: dependabot[bot] <support@dependabot.com> * Bump lombok from 1.16.20 to 1.18.2 Bumps [lombok](https://github.com/rzwitserloot/lombok) from 1.16.20 to 1.18.2. - [Release notes](https://github.com/rzwitserloot/lombok/releases) - [Changelog](https://github.com/rzwitserloot/lombok/blob/master/doc/changelog.markdown) - [Commits](https://github.com/rzwitserloot/lombok/compare/v1.16.20...v1.18.2) Signed-off-by: dependabot[bot] <support@dependabot.com> * Bump assertj-core from 3.11.0 to 3.11.1 Bumps [assertj-core](https://github.com/joel-costigliola/assertj-core) from 3.11.0 to 3.11.1. - [Release notes](https://github.com/joel-costigliola/assertj-core/releases) - [Commits](https://github.com/joel-costigliola/assertj-core/compare/assertj-core-3.11.0...assertj-core-3.11.1) Signed-off-by: dependabot[bot] <support@dependabot.com> * Bump kemitix-parent from 5.1.1 to 5.2.0 Bumps [kemitix-parent](https://gitlab.com/kemitix/kemitix-parent) from 5.1.1 to 5.2.0. - [Release notes](https://gitlab.com/kemitix/kemitix-parent/tags) - [Commits](https://gitlab.com/kemitix/kemitix-parent/commits/master) Signed-off-by: dependabot[bot] <support@dependabot.com> * Update CHANGELOG * Update Jenkinsfile * Remove maven wrapper * Remove travis config * Simplify .gitignore * [readme] convert to org-mode format * lombok scope is provided * version set to DEV-SNAPSHOT * rename property kemitix-tiles as kemitix-maven-tiles * Bump kemitix-maven-tiles from 0.8.1 to 1.3.0 * Bump kemitix-maven-tiles from 1.3.0 to 1.3.1 * NoteItem remove @ToString * Narrow scope of forceParent to package-private * [coverage] set required instructions covered to 97% * Fix badges |
||
---|---|---|
src | ||
.gitignore | ||
CHANGELOG | ||
Jenkinsfile.groovy | ||
LICENSE.txt | ||
pom.xml | ||
README.org |
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]" \-> "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")