private static void pruneAndRegraft(
      final Node nodeToMove, final Node newChild, final Node disownedChild) {
    final Node sourceParent = nodeToMove.getParent();
    final Node destinationParent = newChild.getParent();

    // debug string
    // System.out.println(String.format("%d-%d-%d > %d-%d", parent.getNr(), nodeToMove.getNr(),
    // disownedChild.getNr(), destinationParent.getNr(), newChild.getNr()));

    nodeToMove.removeChild(disownedChild);
    sourceParent.removeChild(nodeToMove);
    destinationParent.removeChild(newChild);

    nodeToMove.addChild(newChild);
    sourceParent.addChild(disownedChild);
    destinationParent.addChild(nodeToMove);

    nodeToMove.makeDirty(Tree.IS_FILTHY);
    sourceParent.makeDirty(Tree.IS_FILTHY);
    destinationParent.makeDirty(Tree.IS_FILTHY);
    newChild.makeDirty(Tree.IS_FILTHY);
    disownedChild.makeDirty(Tree.IS_FILTHY);
  }
 /**
  * Replace node "child" with another node.
  *
  * @param node
  * @param child
  * @param replacement
  */
 public void replace(Node node, Node child, Node replacement) {
   node.removeChild(child);
   node.addChild(replacement);
   node.makeDirty(Tree.IS_FILTHY);
   replacement.makeDirty(Tree.IS_FILTHY);
 }