* Node [[https://oss.sonatype.org/content/repositories/releases/net/kemitix/node][file:https://img.shields.io/nexus/r/https/oss.sonatype.org/net.kemitix/node.svg?style=for-the-badge]] [[https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22net.kemitix%22%20AND%20a%3A%22node%22][file:https://img.shields.io/maven-central/v/net.kemitix/node.svg?style=for-the-badge]] [[http://i.jpeek.org/net.kemitix/node/index.html][file:http://i.jpeek.org/net.kemitix/node/badge.svg]] * A parent/children data structure * Usage Add as a dependency in your =pom.xml=: #+BEGIN_SRC xml net.kemitix node ${node.version} #+END_SRC The library consits of an interface =Node= and an implementation =NodeItem=. ** Create a root node #+BEGIN_SRC java Node root = new NodeItem<>("[root]"); #+END_SRC ** Get the contents of the node #+BEGIN_SRC java String rootData = root.getData(); // returns "[root]" #+END_SRC ** Add a child node #+BEGIN_SRC java Node child = root.createChild("child"); #+END_SRC Which is shorthand for: #+BEGIN_SRC java Node child = new NodeItem<>("child"); root.addChild(child); #+END_SRC The tree now looks like: #+BEGIN_EXAMPLE "[root]" \-> "child" #+END_EXAMPLE ** Get the child node #+BEGIN_SRC java Node childNode = root.getChild("child"); #+END_SRC ** Create a chain of nodes #+BEGIN_SRC java root.createDescendantLine(Arrays.asList("alpha", "beta", "gamma")); #+END_SRC #+BEGIN_EXAMPLE "[root]" \-> "alpha" \-> "beta" \-> "gamma" #+END_EXAMPLE ** Walk the tree to find a node #+BEGIN_SRC java Optional> foundNode = root.walkTree(Arrays.asList("alpha", "beta", "gamma")); if (foundNode.isPresent()) { String betaData = foundNode.get().getParent().getData(); // returns "beta" } #+END_SRC ** Get all children of a node #+BEGIN_SRC java Set> children = root.getChildren(); children.size(); // returns 2 ("child" and "alpha") #+END_SRC