private void rotateUp(Node child) {
    assert child != null &&
           child.parent() != null &&
           child.parent().parent() != null;

    Node parent      = child.parent();
    Node grandparent = parent.parent();

    if (grandparent.left() == parent) {
      grandparent.setLeft(child);
    } else {
      grandparent.setRight(child);
    }
    if (parent.left() == child) {
      parent.setLeft(child.right());
      child.setRight(parent);
    } else {
      parent.setRight(child.left());
      child.setLeft(parent);
    }
  }