From e9c6300ad41b7670987dc6329121da651ab1a421 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 24 May 2016 14:10:46 +0100 Subject: [PATCH 1/6] Node: remove pointless final in parameters in interface --- src/main/java/net/kemitix/node/Node.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/kemitix/node/Node.java b/src/main/java/net/kemitix/node/Node.java index a8dccdf..9c432dc 100644 --- a/src/main/java/net/kemitix/node/Node.java +++ b/src/main/java/net/kemitix/node/Node.java @@ -56,7 +56,7 @@ public interface Node { * * @param parent the new parent node */ - void setParent(final Node parent); + void setParent(Node parent); /** * Fetches the child nodes. @@ -70,7 +70,7 @@ public interface Node { * * @param child the node to add */ - void addChild(final Node child); + void addChild(Node child); /** * Creates a new node and adds it as a child of the current node. @@ -79,7 +79,7 @@ public interface Node { * * @return the new child node */ - Node createChild(final T child); + Node createChild(T child); /** * Populates the tree with the path of nodes, each being a child of the @@ -87,7 +87,7 @@ public interface Node { * * @param descendants the line of descendants from the current node */ - void createDescendantLine(final List descendants); + void createDescendantLine(List descendants); /** * Looks for a child node and returns it, creating a new child node if one @@ -97,7 +97,7 @@ public interface Node { * * @return the found or created child node */ - Node findOrCreateChild(final T child); + Node findOrCreateChild(T child); /** * Fetches the node for the child if present. @@ -106,7 +106,7 @@ public interface Node { * * @return an {@link Optional} containing the child node if found */ - Optional> getChild(final T child); + Optional> getChild(T child); /** * Checks if the node is an ancestor. @@ -115,7 +115,7 @@ public interface Node { * * @return true if the node is an ancestor */ - boolean isChildOf(final Node node); + boolean isChildOf(Node node); /** * Walks the node tree using the path to select each child. @@ -124,7 +124,7 @@ public interface Node { * * @return the child or null */ - Optional> walkTree(final List path); + Optional> walkTree(List path); /** * Places the node in the tree under by the path. Intervening empty From 2ed0024bc0e7ab7d01f3ed11f165f9decb709d73 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 24 May 2016 14:25:55 +0100 Subject: [PATCH 2/6] Node: clean up method names Deprecate: * findOrCreateChild() Rename: * getChild() => findChild() * isChildOf() => isDescendantOf() * walkTree() => findInPath() * placeNodeIn() => insertInPath() * findChildNamed() => findChildByName() * getChildNamed() => getChildByName() --- src/main/java/net/kemitix/node/Node.java | 16 ++--- src/main/java/net/kemitix/node/NodeItem.java | 34 +++++----- .../java/net/kemitix/node/NodeItemTest.java | 62 +++++++++---------- 3 files changed, 57 insertions(+), 55 deletions(-) diff --git a/src/main/java/net/kemitix/node/Node.java b/src/main/java/net/kemitix/node/Node.java index 9c432dc..8094888 100644 --- a/src/main/java/net/kemitix/node/Node.java +++ b/src/main/java/net/kemitix/node/Node.java @@ -73,7 +73,7 @@ public interface Node { void addChild(Node child); /** - * Creates a new node and adds it as a child of the current node. + * Creates a new unnamed node and adds it as a child of the current node. * * @param child the child node's data * @@ -97,6 +97,7 @@ public interface Node { * * @return the found or created child node */ + @Deprecated Node findOrCreateChild(T child); /** @@ -106,7 +107,8 @@ public interface Node { * * @return an {@link Optional} containing the child node if found */ - Optional> getChild(T child); + Optional> findChild(T child); + /** * Checks if the node is an ancestor. @@ -115,7 +117,7 @@ public interface Node { * * @return true if the node is an ancestor */ - boolean isChildOf(Node node); + boolean isDescendantOf(Node node); /** * Walks the node tree using the path to select each child. @@ -124,7 +126,7 @@ public interface Node { * * @return the child or null */ - Optional> walkTree(List path); + Optional> findInPath(List path); /** * Places the node in the tree under by the path. Intervening empty @@ -133,7 +135,7 @@ public interface Node { * @param node the node to place * @param path the path to contain the new node */ - void placeNodeIn(Node node, String... path); + void insertInPath(Node node, String... path); /** * Searches for a child with the name given. @@ -142,7 +144,7 @@ public interface Node { * * @return an Optional containing the child found or empty */ - Optional> findChildNamed(String name); + Optional> findChildByName(String name); /** * Returns the child with the given name. If one can't be found a @@ -152,7 +154,7 @@ public interface Node { * * @return the node */ - Node getChildNamed(String name); + Node getChildByName(String name); /** * Draw a representation of the tree. diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index 1ef3bf6..9175667 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -152,11 +152,11 @@ public class NodeItem implements Node { if (child == null) { throw new NullPointerException("child"); } - if (this.equals(child) || isChildOf(child)) { + if (this.equals(child) || isDescendantOf(child)) { throw new NodeException("Child is an ancestor"); } if (child.isNamed()) { - final Optional> existingChild = findChildNamed( + final Optional> existingChild = findChildByName( child.getName()); if (existingChild.isPresent() && existingChild.get() != child) { throw new NodeException( @@ -214,7 +214,7 @@ public class NodeItem implements Node { if (child == null) { throw new NullPointerException("child"); } - return getChild(child).orElseGet(() -> createChild(child)); + return findChild(child).orElseGet(() -> createChild(child)); } /** @@ -225,7 +225,7 @@ public class NodeItem implements Node { * @return an {@link Optional} containing the child node if found */ @Override - public Optional> getChild(final T child) { + public Optional> findChild(final T child) { if (child == null) { throw new NullPointerException("child"); } @@ -242,8 +242,8 @@ public class NodeItem implements Node { * @return true if the node is an ancestor */ @Override - public boolean isChildOf(final Node node) { - return parent != null && (node.equals(parent) || parent.isChildOf( + public boolean isDescendantOf(final Node node) { + return parent != null && (node.equals(parent) || parent.isDescendantOf( node)); } @@ -257,7 +257,7 @@ public class NodeItem implements Node { if (parent == null) { throw new NullPointerException("parent"); } - if (this.equals(parent) || parent.isChildOf(this)) { + if (this.equals(parent) || parent.isDescendantOf(this)) { throw new NodeException("Parent is a descendant"); } if (this.parent != null) { @@ -275,15 +275,15 @@ public class NodeItem implements Node { * @return the child or null */ @Override - public Optional> walkTree(final List path) { + public Optional> findInPath(final List path) { if (path == null) { throw new NullPointerException("path"); } if (path.size() > 0) { - Optional> found = getChild(path.get(0)); + Optional> found = findChild(path.get(0)); if (found.isPresent()) { if (path.size() > 1) { - return found.get().walkTree(path.subList(1, path.size())); + return found.get().findInPath(path.subList(1, path.size())); } return found; } @@ -292,13 +292,13 @@ public class NodeItem implements Node { } @Override - public void placeNodeIn(final Node nodeItem, final String... path) { + public void insertInPath(final Node nodeItem, final String... path) { if (path.length == 0) { if (!nodeItem.isNamed()) { // nothing to conflict with addChild(nodeItem); return; } - final Optional> childNamed = findChildNamed( + final Optional> childNamed = findChildByName( nodeItem.getName()); if (!childNamed.isPresent()) { // nothing with the same name exists addChild(nodeItem); @@ -317,18 +317,18 @@ public class NodeItem implements Node { return; } String item = path[0]; - final Optional> childNamed = findChildNamed(item); + final Optional> childNamed = findChildByName(item); Node child; if (!childNamed.isPresent()) { child = new NodeItem<>(null, item, this); } else { child = childNamed.get(); } - child.placeNodeIn(nodeItem, Arrays.copyOfRange(path, 1, path.length)); + child.insertInPath(nodeItem, Arrays.copyOfRange(path, 1, path.length)); } @Override - public Optional> findChildNamed(final String named) { + public Optional> findChildByName(final String named) { if (named == null) { throw new NullPointerException("name"); } @@ -338,8 +338,8 @@ public class NodeItem implements Node { } @Override - public Node getChildNamed(final String named) { - final Optional> optional = findChildNamed(named); + public Node getChildByName(final String named) { + final Optional> optional = findChildByName(named); if (optional.isPresent()) { return optional.get(); } diff --git a/src/test/java/net/kemitix/node/NodeItemTest.java b/src/test/java/net/kemitix/node/NodeItemTest.java index 200321f..771c207 100644 --- a/src/test/java/net/kemitix/node/NodeItemTest.java +++ b/src/test/java/net/kemitix/node/NodeItemTest.java @@ -186,7 +186,7 @@ public class NodeItemTest { assertThat(child.getParent()).as( "when a node is assigned a new parent, the old parent is " + "replaced").isSameAs(newParent); - assertThat(node.getChild("child").isPresent()).as( + assertThat(node.findChild("child").isPresent()).as( "when a node is assigned a new parent, the old parent no " + "longer has the node among it's children").isFalse(); } @@ -208,7 +208,7 @@ public class NodeItemTest { "when a node with an existing parent is added as a child " + "to another node, then the old parent is replaced") .isSameAs(newParent); - assertThat(node.getChild("child").isPresent()).as( + assertThat(node.findChild("child").isPresent()).as( "when a node with an existing parent is added as a child to " + "another node, then the old parent no longer has " + "the node among it's children").isFalse(); @@ -330,7 +330,7 @@ public class NodeItemTest { val subject = "subject"; node = new NodeItem<>(subject, parentNode); //when - val result = grandParentNode.walkTree(Arrays.asList(parent, subject)); + val result = grandParentNode.findInPath(Arrays.asList(parent, subject)); //then assertThat(result.isPresent()).as( "when we walk the tree to a node it is found").isTrue(); @@ -353,7 +353,7 @@ public class NodeItemTest { val subject = "subject"; node = new NodeItem<>(subject, parentNode); //when - val result = parentNode.walkTree(Arrays.asList(subject, "no child")); + val result = parentNode.findInPath(Arrays.asList(subject, "no child")); //then assertThat(result.isPresent()).as( "when we walk the tree to a node that doesn't exists, nothing" @@ -370,7 +370,7 @@ public class NodeItemTest { exception.expect(NullPointerException.class); exception.expectMessage("path"); //when - node.walkTree(null); + node.findInPath(null); } /** @@ -382,7 +382,7 @@ public class NodeItemTest { //given node = new NodeItem<>("subject", Node::getData); //when - val result = node.walkTree(Collections.emptyList()); + val result = node.findInPath(Collections.emptyList()); //then assertThat(result).isEmpty(); } @@ -401,7 +401,7 @@ public class NodeItemTest { node.createDescendantLine( Arrays.asList(alphaData, betaData, gammaData)); //then - val alphaOptional = node.getChild(alphaData); + val alphaOptional = node.findChild(alphaData); assertThat(alphaOptional.isPresent()).as( "when creating a descendant line, the first element is found") .isTrue(); @@ -410,7 +410,7 @@ public class NodeItemTest { assertThat(alpha.getParent()).as( "when creating a descendant line, the first element has " + "the current node as its parent").isSameAs(node); - val betaOptional = alpha.getChild(betaData); + val betaOptional = alpha.findChild(betaData); assertThat(betaOptional.isPresent()).as( "when creating a descendant line, the second element is " + "found").isTrue(); @@ -420,7 +420,7 @@ public class NodeItemTest { "when creating a descendant line, the second element " + "has the first as its parent") .isSameAs(alpha); - val gammaOptional = beta.getChild(gammaData); + val gammaOptional = beta.findChild(gammaData); assertThat(gammaOptional.isPresent()).as( "when creating a descendant line, the third element " + "is found").isTrue(); @@ -521,7 +521,7 @@ public class NodeItemTest { val child = new NodeItem(childData, Node::getData); node.addChild(child); //when - val found = node.getChild(childData); + val found = node.findChild(childData); //then assertThat(found.isPresent()).as( "when retrieving a child by its data, it is found").isTrue(); @@ -542,7 +542,7 @@ public class NodeItemTest { exception.expect(NullPointerException.class); exception.expectMessage("child"); //when - node.getChild(null); + node.findChild(null); } /** @@ -560,7 +560,7 @@ public class NodeItemTest { assertThat(child.getParent()).as( "when creating a child node, the child has the current node " + "as its parent").isSameAs(node); - val foundChild = node.getChild(childData); + val foundChild = node.findChild(childData); assertThat(foundChild.isPresent()).as( "when creating a child node, the child can be found by its " + "data").isTrue(); @@ -651,7 +651,7 @@ public class NodeItemTest { node.addChild(alpha); node.addChild(beta); //when - val result = node.getChildNamed("alpha"); + val result = node.getChildByName("alpha"); //then assertThat(result).isSameAs(alpha); } @@ -667,7 +667,7 @@ public class NodeItemTest { exception.expect(NodeException.class); exception.expectMessage("Named child not found"); //when - node.getChildNamed("gamma"); + node.getChildByName("gamma"); } @Test @@ -689,7 +689,7 @@ public class NodeItemTest { node = new NodeItem<>(null, "root"); // create a root val four = new NodeItem("data", "four"); //when - node.placeNodeIn(four, "one", "two", "three"); + node.insertInPath(four, "one", "two", "three"); //then val three = four.getParent(); assertThat(four.getParent()).as("add node to a tree").isNotNull(); @@ -699,10 +699,10 @@ public class NodeItemTest { val one = two.getParent(); assertThat(one.getName()).isEqualTo("one"); assertThat(one.getParent()).isSameAs(node); - assertThat(node.getChildNamed("one") - .getChildNamed("two") - .getChildNamed("three") - .getChildNamed("four")).isSameAs(four); + assertThat(node.getChildByName("one") + .getChildByName("two") + .getChildByName("three") + .getChildByName("four")).isSameAs(four); } @Test @@ -713,11 +713,11 @@ public class NodeItemTest { val child = new NodeItem("child data", "child"); val grandchild = new NodeItem("grandchild data", "grandchild"); //when - node.placeNodeIn(child); // as root/child - node.placeNodeIn(grandchild, "child"); // as root/child/grandchild + node.insertInPath(child); // as root/child + node.insertInPath(grandchild, "child"); // as root/child/grandchild //then - assertThat(node.getChildNamed("child")).as("child").isSameAs(child); - assertThat(node.getChildNamed("child").getChildNamed("grandchild")).as( + assertThat(node.getChildByName("child")).as("child").isSameAs(child); + assertThat(node.getChildByName("child").getChildByName("grandchild")).as( "grandchild").isSameAs(grandchild); } @@ -729,11 +729,11 @@ public class NodeItemTest { val child = new NodeItem("child data", "child"); val grandchild = new NodeItem("grandchild data", "grandchild"); //when - node.placeNodeIn(grandchild, "child"); - node.placeNodeIn(child); + node.insertInPath(grandchild, "child"); + node.insertInPath(child); //then - assertThat(node.getChildNamed("child")).as("child").isSameAs(child); - assertThat(node.getChildNamed("child").getChildNamed("grandchild")).as( + assertThat(node.getChildByName("child")).as("child").isSameAs(child); + assertThat(node.getChildByName("child").getChildByName("grandchild")).as( "grandchild").isSameAs(grandchild); } @@ -758,7 +758,7 @@ public class NodeItemTest { // only grandchild has data //when // attempt to add another node called 'grandchild' to 'child' - node.placeNodeIn(new NodeItem<>("cuckoo", "grandchild"), "child"); + node.insertInPath(new NodeItem<>("cuckoo", "grandchild"), "child"); } @Test @@ -768,7 +768,7 @@ public class NodeItemTest { node = new NodeItem<>(null); final Node newNode = new NodeItem<>(null); //when - node.placeNodeIn(newNode); + node.insertInPath(newNode); //then assertThat(node.getChildren()).containsOnly(newNode); } @@ -786,7 +786,7 @@ public class NodeItemTest { assertThat(addMe.getParent()).isNull(); //when // addMe should replace target as the sole descendant of child - node.placeNodeIn(addMe, "child"); + node.insertInPath(addMe, "child"); //then assertThat(child.getChildren()).as("child only contains new node") .containsOnly(addMe); @@ -801,7 +801,7 @@ public class NodeItemTest { exception.expectMessage("name"); node = new NodeItem<>(null); //when - node.findChildNamed(null); + node.findChildByName(null); } @Test From fc55bacb049bb298ff765bd15835d62b22afd62f Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 24 May 2016 14:30:00 +0100 Subject: [PATCH 3/6] Node.setData(): add ability to change node's data after instantiation --- src/main/java/net/kemitix/node/Node.java | 7 +++++++ src/main/java/net/kemitix/node/NodeItem.java | 7 ++++++- src/test/java/net/kemitix/node/NodeItemTest.java | 10 ++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kemitix/node/Node.java b/src/main/java/net/kemitix/node/Node.java index 8094888..a01efa7 100644 --- a/src/main/java/net/kemitix/node/Node.java +++ b/src/main/java/net/kemitix/node/Node.java @@ -34,6 +34,13 @@ public interface Node { */ T getData(); + /** + * Set the data held within the node. + * + * @param data the node's data + */ + void setData(T data); + /** * Returns true if the node is empty (has no data). * diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index 9175667..5938e71 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -16,7 +16,7 @@ import java.util.function.Function; */ public class NodeItem implements Node { - private final T data; + private T data; private final Set> children = new HashSet<>(); @@ -127,6 +127,11 @@ public class NodeItem implements Node { return data; } + @Override + public void setData(final T data) { + this.data = data; + } + @Override public boolean isEmpty() { return data == null; diff --git a/src/test/java/net/kemitix/node/NodeItemTest.java b/src/test/java/net/kemitix/node/NodeItemTest.java index 771c207..8cd5ca4 100644 --- a/src/test/java/net/kemitix/node/NodeItemTest.java +++ b/src/test/java/net/kemitix/node/NodeItemTest.java @@ -878,4 +878,14 @@ public class NodeItemTest { "[ lucy]"); assertThat(lines).containsSubsequence("[root]", "[ bob]"); } + + @Test + public void canChangeNodeData() { + //given + node = new NodeItem<>("initial"); + //when + node.setData("updated"); + //then + assertThat(node.getData()).isEqualTo("updated"); + } } From 04599861c0dc5da89b6981794857ca30d0c73ab6 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 24 May 2016 14:43:36 +0100 Subject: [PATCH 4/6] Node.createChild(data, name): can create named child nodes # Conflicts: # src/test/java/net/kemitix/node/NodeItemTest.java --- src/main/java/net/kemitix/node/Node.java | 9 +++++++++ src/main/java/net/kemitix/node/NodeItem.java | 7 +++++++ src/test/java/net/kemitix/node/NodeItemTest.java | 13 +++++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/main/java/net/kemitix/node/Node.java b/src/main/java/net/kemitix/node/Node.java index a01efa7..04bec0e 100644 --- a/src/main/java/net/kemitix/node/Node.java +++ b/src/main/java/net/kemitix/node/Node.java @@ -88,6 +88,15 @@ public interface Node { */ Node createChild(T child); + /** + * Creates a new named node and adds it as a child of the current node. + * + * @param child the child node's data + * + * @return the new child node + */ + Node createChild(T child, String name); + /** * Populates the tree with the path of nodes, each being a child of the * previous node in the path. diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index 5938e71..c9d70f8 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -189,6 +189,13 @@ public class NodeItem implements Node { return new NodeItem<>(child, this); } + @Override + public Node createChild(final T child, final String name) { + Node node = createChild(child); + node.setName(name); + return node; + } + /** * Populates the tree with the path of nodes, each being a child of the * previous node in the path. diff --git a/src/test/java/net/kemitix/node/NodeItemTest.java b/src/test/java/net/kemitix/node/NodeItemTest.java index 8cd5ca4..53b0c07 100644 --- a/src/test/java/net/kemitix/node/NodeItemTest.java +++ b/src/test/java/net/kemitix/node/NodeItemTest.java @@ -888,4 +888,17 @@ public class NodeItemTest { //then assertThat(node.getData()).isEqualTo("updated"); } + + @Test + @SuppressWarnings("unchecked") + public void canCreateNamedChild() { + //given + node = new NodeItem<>(null); + //when + Node child = node.createChild("child data", "child name"); + //then + assertThat(child.getName()).isEqualTo("child name"); + assertThat(child.getParent()).isSameAs(node); + assertThat(node.getChildren()).containsExactly(child); + } } From f95029d3485c66ab79e6ad1133b6ea5ddc7c11bf Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 24 May 2016 14:39:23 +0100 Subject: [PATCH 5/6] Node.getChild(): method to get a child or throw an exception if not found --- src/main/java/net/kemitix/node/Node.java | 10 +++++++++ src/main/java/net/kemitix/node/NodeItem.java | 8 +++++++ .../java/net/kemitix/node/NodeItemTest.java | 21 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/main/java/net/kemitix/node/Node.java b/src/main/java/net/kemitix/node/Node.java index 04bec0e..e2f074f 100644 --- a/src/main/java/net/kemitix/node/Node.java +++ b/src/main/java/net/kemitix/node/Node.java @@ -125,6 +125,16 @@ public interface Node { */ Optional> findChild(T child); + /** + * Fetches the node for the child if present. + * + * @param child the child's data to search for + * + * @return the child node if found + * + * @throws NodeException if the node is not found + */ + Node getChild(T child); /** * Checks if the node is an ancestor. diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index c9d70f8..acd883d 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -246,6 +246,14 @@ public class NodeItem implements Node { .findAny(); } + @Override + public Node getChild(final T child) { + Optional> optional = findChild(child); + if (optional.isPresent()) + return optional.get(); + throw new NodeException("Child not found"); + } + /** * Checks if the node is an ancestor. * diff --git a/src/test/java/net/kemitix/node/NodeItemTest.java b/src/test/java/net/kemitix/node/NodeItemTest.java index 53b0c07..251d690 100644 --- a/src/test/java/net/kemitix/node/NodeItemTest.java +++ b/src/test/java/net/kemitix/node/NodeItemTest.java @@ -901,4 +901,25 @@ public class NodeItemTest { assertThat(child.getParent()).isSameAs(node); assertThat(node.getChildren()).containsExactly(child); } + + @Test + public void canGetChildWhenFound() { + //given + node = new NodeItem<>("data"); + Node child = new NodeItem<>("child data", "child name", node); + //when + Node found = node.getChild("child data"); + //then + assertThat(found).isSameAs(child); + } + + @Test + public void canGetChildWhenNotFound() { + //given + exception.expect(NodeException.class); + exception.expectMessage("Child not found"); + node = new NodeItem<>("data"); + //when + node.getChild("child data"); + } } From a31c4501ac73d2401879f0b5fe2012c668293d8c Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 24 May 2016 15:05:53 +0100 Subject: [PATCH 6/6] Fix typos --- src/main/java/net/kemitix/node/Node.java | 1 + src/main/java/net/kemitix/node/NodeItem.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kemitix/node/Node.java b/src/main/java/net/kemitix/node/Node.java index e2f074f..19cc60a 100644 --- a/src/main/java/net/kemitix/node/Node.java +++ b/src/main/java/net/kemitix/node/Node.java @@ -92,6 +92,7 @@ public interface Node { * Creates a new named node and adds it as a child of the current node. * * @param child the child node's data + * @param name the name * * @return the new child node */ diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index acd883d..ddb402a 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -190,6 +190,7 @@ public class NodeItem implements Node { } @Override + @SuppressWarnings("hiddenfield") public Node createChild(final T child, final String name) { Node node = createChild(child); node.setName(name); @@ -249,8 +250,9 @@ public class NodeItem implements Node { @Override public Node getChild(final T child) { Optional> optional = findChild(child); - if (optional.isPresent()) + if (optional.isPresent()) { return optional.get(); + } throw new NodeException("Child not found"); }