From eb4acbaf893e1bc53a070d4b40d304ef20e9b96e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 16 Feb 2017 21:09:09 +0000 Subject: [PATCH] NodeItem: inline verifyChildWithSameNameDoesNotAlreadyExis --- src/main/java/net/kemitix/node/NodeItem.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index e4d605a..3c11887 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -143,7 +143,13 @@ class NodeItem implements Node { @Override public void addChild(@NonNull final Node child) { verifyChildIsNotAnAncestor(child); - verifyChildWithSameNameDoesNotAlreadyExist(child); + //verifyChildWithSameNameDoesNotAlreadyExist + if (child.isNamed()) { + findChildByName(child.getName()).filter(existingChild -> existingChild != child) + .ifPresent(existingChild -> { + throw new NodeException("Node with that name already exists here"); + }); + } children.add(child); // update the child's parent if they don't have one or it is not this val childParent = child.getParent(); @@ -153,17 +159,6 @@ class NodeItem implements Node { } } - private void verifyChildWithSameNameDoesNotAlreadyExist( - final @NonNull Node child - ) { - if (child.isNamed()) { - findChildByName(child.getName()).filter(existingChild -> existingChild != child) - .ifPresent(existingChild -> { - throw new NodeException("Node with that name already exists here"); - }); - } - } - private void verifyChildIsNotAnAncestor(final @NonNull Node child) { if (this.equals(child) || isDescendantOf(child)) { throw new NodeException("Child is an ancestor");