package org.simantics.g3d.scenegraph.base;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import org.simantics.utils.datastructures.MapList;
private MapList<String, T> children = new MapList<String, T>();
public synchronized void addNode(String relName, T child) {
- if (child.getParent() != null)
+ if (child == null)
+ throw new NullPointerException("Cannot add null child");
+ if (child.getParent() != null) {
+ if (child.getParent() == this)
+ throw new IllegalArgumentException("Given node is already a child");
child.getParent().deattachNode(child.getParentRel(), child);
+ }
child.setParent(this, relName);
children.add(relName, (T) child);
public synchronized final boolean removeNode(String relName, INode child) {
if (children.remove(relName, (T) child)) {
fireNodeRemoved(child, relName);
- child.remove();
+ child.remove();
child.setParent(null, null);
return true;
}
for (T child : nodes) {
if (children.remove(relName, (T) child)) {
fireNodeRemoved(child, relName);
- child.remove();
+ child.remove();
child.setParent(null, null);
}