public TreeNode<T> insert(final int index, final TreeNode<T> child) {
		requireNonNull(child);
		if (isAncestor(child)) {
			throw new IllegalArgumentException("The new child is an ancestor.");
		}

		if (child._parent != null) {
			child._parent.remove(child);
		}

		child.parent(this);
		createChildrenIfMissing();
		_children.add(index, child);

		return this;
	}
Removes the {@code child} from its present parent (if it has one), sets
the child's parent to this node, and then adds the child to this node's
child array at index {@code index}. The new {@code child} must not be
{@code null} and must not be an ancestor of {@code this} node.

@param index the index in the child array where this node is to be
       inserted
@param child the sub-node to be inserted
@return {@code this} tree-node, for method chaining
@throws ArrayIndexOutOfBoundsException if {@code index} is out of bounds
@throws IllegalArgumentException if {@code child} is an ancestor of
        {@code this} node
@throws NullPointerException if the given {@code child} is {@code null}
jenetics.ext/src/main/java/io/jenetics/ext/util/TreeNode.java