Nodes::asImmutableChild: use null parent if none found
This commit is contained in:
parent
e61f6db9cf
commit
2226d61b46
1 changed files with 5 additions and 10 deletions
|
@ -25,7 +25,6 @@ SOFTWARE.
|
||||||
package net.kemitix.node;
|
package net.kemitix.node;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -121,15 +120,11 @@ public final class Nodes {
|
||||||
private static <T> Node<T> asImmutableChild(
|
private static <T> Node<T> asImmutableChild(
|
||||||
final Node<T> source
|
final Node<T> source
|
||||||
) {
|
) {
|
||||||
final Optional<Node<T>> sourceParent = source.getParent();
|
return ImmutableNodeItem.newChild(source.getData()
|
||||||
if (sourceParent.isPresent()) {
|
.orElse(null), source.getName(), source.getParent()
|
||||||
return ImmutableNodeItem.newChild(source.getData()
|
.orElse(null),
|
||||||
.orElse(null), source.getName(), sourceParent.get(),
|
getImmutableChildren(source)
|
||||||
getImmutableChildren(source)
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("source must not be the root node");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue