From 271679e00647f0f806623d44f03099ce2813bd7e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 9 Jan 2016 17:51:36 +0000 Subject: [PATCH] README.md: add usage and examples Signed-off-by: Paul Campbell --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/README.md b/README.md index c6297e0..e5b9073 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,59 @@ # node A parent/children data structure + +# Usage + +Add as a dependency in your `pom.xml`: + + + net.kemitix + node + ${node.version} + + +The library consits of an interface `Node` and an implementation `NodeItem`. + +## Create a root node + + Node root = new NodeItem<>("[root]"); + +## Get the contents of the node + + String rootData = root.getData(); // returns "[root]" + +## Add a child node + + root.addChild("child"); + +The tree now looks like: + + "[root]" + \-> "child" + +## Get the child node + + Node 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> 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> children = root.getChildren(); + children.size(); // returns 2 ("child" and "alpha")