setParent is used by Add and AddAt. It verifies that the node is not being added to itself and sets the parent pointer of the specified node. If the specified node had a parent, the specified node is removed from the original parent's list of children. It does not add the specified node to the list
(parent INode, child INode)
| 342 | // If the specified node had a parent, the specified node is removed from the original parent's list of children. |
| 343 | // It does not add the specified node to the list of children. |
| 344 | func setParent(parent INode, child INode) { |
| 345 | |
| 346 | if parent.GetNode() == child.GetNode() { |
| 347 | panic("Node.{Add,AddAt}: object can't be added as a child of itself") |
| 348 | } |
| 349 | // If the specified node already has a parent, |
| 350 | // remove it from the original parent's list of children |
| 351 | if child.Parent() != nil { |
| 352 | child.Parent().GetNode().Remove(child) |
| 353 | } |
| 354 | child.GetNode().parent = parent |
| 355 | } |
| 356 | |
| 357 | // ChildAt returns the child at the specified index. |
| 358 | func (n *Node) ChildAt(idx int) INode { |