From 2226d61b46d77f3d4ba755dbf83f3d1d1b26aa59 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 20 Sep 2016 23:35:27 +0100 Subject: [PATCH] Nodes::asImmutableChild: use null parent if none found --- src/main/java/net/kemitix/node/Nodes.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/kemitix/node/Nodes.java b/src/main/java/net/kemitix/node/Nodes.java index 0a6fa96..ffa8f74 100644 --- a/src/main/java/net/kemitix/node/Nodes.java +++ b/src/main/java/net/kemitix/node/Nodes.java @@ -25,7 +25,6 @@ SOFTWARE. package net.kemitix.node; import java.util.HashSet; -import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -121,15 +120,11 @@ public final class Nodes { private static Node asImmutableChild( final Node source ) { - final Optional> sourceParent = source.getParent(); - if (sourceParent.isPresent()) { - return ImmutableNodeItem.newChild(source.getData() - .orElse(null), source.getName(), sourceParent.get(), - getImmutableChildren(source) - ); - } else { - throw new IllegalArgumentException("source must not be the root node"); - } + return ImmutableNodeItem.newChild(source.getData() + .orElse(null), source.getName(), source.getParent() + .orElse(null), + getImmutableChildren(source) + ); } }