Inserts {@code newChild} at {@code index}. If it is already child of
another node, it is removed from there.
963107
Node insertChildAt(Node newChild, int index) throws DOMException {
        if (newChild instanceof DocumentFragment) {
            NodeList toAdd = newChild.getChildNodes();
            for (int i = 0; i < toAdd.getLength(); i++) {
                insertChildAt(toAdd.item(i), index + i);
            }
            return newChild;
        }

        LeafNodeImpl toInsert = (LeafNodeImpl) newChild;
        if (toInsert.document != null && document != null && toInsert.document != document) {
            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
        }
        if (toInsert.isParentOf(this)) {
            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
        }

        if (toInsert.parent != null) {
            int oldIndex = toInsert.index;
            toInsert.parent.children.remove(oldIndex);
            toInsert.parent.refreshIndices(oldIndex);
        }

        children.add(index, toInsert);
        toInsert.parent = this;
        refreshIndices(index);

        return newChild;
    }
379046
public final void replaceChild(Node child, Node newChild) {
    checkArgument(newChild.next == null, "The new child node has next siblings.");
    checkArgument(newChild.previous == null, "The new child node has previous siblings.");
    checkArgument(newChild.parent == null, "The new child node already has a parent.");
    checkState(child.parent == this, "%s is not the parent of %s", this, child);

    // Copy over important information.
    newChild.useSourceInfoIfMissingFrom(child);
    newChild.parent = this;

    Node nextSibling = child.next;
    Node prevSibling = child.previous;

    Node last = first.previous;

    if (child == prevSibling) {  // first and only child
      first = newChild;
      first.previous = newChild;
    } else {
      if (child == first) {
        first = newChild;
        // prevSibling == last, and last.next remains null
      } else {
        prevSibling.next = newChild;
      }

      if (child == last) {
        first.previous = newChild;
      } else {
        nextSibling.previous = newChild;
      }

      newChild.previous = prevSibling;
    }
    newChild.next = nextSibling;  // maybe null

    child.next = null;
    child.previous = null;
    child.parent = null;
  }
387216
def insertChild(self, index, item):
        
        super(XGanttWidgetItem, self).insertChild(index, item)
        item.sync()
642213
public void setAndLinkChild(int index, AbstractPlanNode child) {
        assert(child != null);
        m_children.set(index, child);
        child.m_parents.add(this);
    }
734691
public void insertParentBefore(Node node) throws ChildNodeException {
    if (node != null) {
      if (hasParent()) {
        getParentNode().addChild(node);
        getParentNode().removeChild(this);
      }
      node.addChild(this);
    }
  }
974798
public Node replaceChild(Node newChild, Node oldChild) throws DOMException
  {

    if (oldChild == null || oldChild.getParentNode() != this)
      return null;

    ElemTemplateElement newChildElem = ((ElemTemplateElement) newChild);
    ElemTemplateElement oldChildElem = ((ElemTemplateElement) oldChild);

    // Fix up previous sibling.
    ElemTemplateElement prev =
      (ElemTemplateElement) oldChildElem.getPreviousSibling();

    if (null != prev)
      prev.m_nextSibling = newChildElem;

    // Fix up parent (this)
    if (m_firstChild == oldChildElem)
      m_firstChild = newChildElem;

    newChildElem.m_parentNode = this;
    oldChildElem.m_parentNode = null;
    newChildElem.m_nextSibling = oldChildElem.m_nextSibling;
    oldChildElem.m_nextSibling = null;

    // newChildElem.m_stylesheet = oldChildElem.m_stylesheet;
    // oldChildElem.m_stylesheet = null;
    return newChildElem;
  }
1074436
public void addChild(N child) {
    checkNotNull(child);
    tryRemoveFromOldParent(child);
    children.add(child);
    child.setParent(master);
  }
258074
public void addChild(LockedObject newChild) {
        if (_children == null) {
            _children = new LockedObject[0];
        }
        int size = _children.length;
        LockedObject[] newChildren = new LockedObject[size + 1];
        System.arraycopy(_children, 0, newChildren, 0, size);
        newChildren[size] = newChild;
        _children = newChildren;
    }
227862
public static void insertAfter(Element newElement, Element after) {
        after.parentNode.insertBefore(newElement, after.nextSibling);
    }
769763
function ( child, index ) {
            var el = this.element();
            if ( typeof index === 'number' ) {
                var children = el.children,
                    childNum = children.length;
    
                if ( childNum > 0 && index < childNum ) {
                    el.insertBefore( child, children[index] );
                    return;
                }
            }
            el.appendChild( child );
        }
774316
function(index) {
    if(lang.isNumber(index) && this._elColgroup && this._elColgroup.childNodes[index]) {
        this._elColgroup.removeChild(this._elColgroup.childNodes[index]);
    }
}
360594
@Override
	public void addChildAt(final int index, final ITreeNode<T> child)
		throws IndexOutOfBoundsException
	{
		if (children != null && children.size() < index)
		{
			children.add(index, child);
		}
		else
		{
			addChild(child);
		}
	}
999928
public ElemTemplateElement appendChild(ElemTemplateElement newChild)
  {

    int type = ((ElemTemplateElement) newChild).getXSLToken();

    if (Constants.ELEMNAME_SORT == type)
    {
      setSortElem((ElemSort) newChild);

      return newChild;
    }
    else
      return super.appendChild(newChild);
  }
233239
void setChild(int index, Node child){
        if ((this.splitTest.maxBranches() >= 0)
                && (index >= this.splitTest.maxBranches())) {
            throw new IndexOutOfBoundsException();
        }
        this.children.set(index, child);
	}
793280
protected void addChild(ElementBase child, boolean doEvent) {
        if (!child.canAcceptParent(this)) {
            CWFException.raise(child.rejectReason);
        }
        
        if (!canAcceptChild(child)) {
            CWFException.raise(rejectReason);
        }
        
        if (doEvent) {
            beforeAddChild(child);
        }
        
        if (child.getParent() != null) {
            child.getParent().removeChild(child, false);
        }
        
        children.add(child);
        child.updateParent(this);
        
        if (doEvent) {
            afterAddChild(child);
        }
    }
259901
public void insertParentAfter(Node node) throws ChildNodeException {
    if (node != null) {
      // give this node my children
      node.setFirstChild(getFirstChild());

      setFirstChild(null); // clear our list
      addChild(node);      // make our child
    }
  }
1138132
def insert(self, index, value):
        ''''''
        newnode = LookupTreeNode(index, value)
        level = 0
        node = self.root
        while True:
            ind = _getbits(newnode.index, level)
            level += 1
            child = node.children[ind]
            if child is None or child.index == newnode.index:
                if child:
                    assert child.value == newnode.value
                node.children[ind] = newnode
                break
            elif child.index == _root_index:
                # This is a branch
                node = child
            else:
                branch = LookupTreeNode()
                nind = _getbits(newnode.index, level)
                cind = _getbits(child.index, level)
                node.children[ind] = branch

                # Life gets tricky when...
                if nind == cind:
                    branch.children[cind] = child
                    # recurse
                    node = branch
                else:
                    branch.children[nind] = newnode
                    branch.children[cind] = child
                    break