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");