code: public void replaceNode(final ADTNode<S, I, O> oldNode, final ADTNode<S, I, O> newNode) {
  
          if (this.root.equals(oldNode)) {
              this.root = newNode;
          } else if (ADTUtil.isResetNode(oldNode)) {
              final ADTNode<S, I, O> endOfPreviousADS = oldNode.getParent();
              final O outputToReset = ADTUtil.getOutputForSuccessor(endOfPreviousADS, oldNode);
  
              newNode.setParent(endOfPreviousADS);
              endOfPreviousADS.getChildren().put(outputToReset, newNode);
          } else {
              final ADTNode<S, I, O> oldNodeParent = oldNode.getParent(); //reset node
  
              assert ADTUtil.isResetNode(oldNodeParent);
  
              final ADTNode<S, I, O> endOfPreviousADS = oldNodeParent.getParent();
              final O outputToReset = ADTUtil.getOutputForSuccessor(endOfPreviousADS, oldNodeParent);
              final ADTNode<S, I, O> newResetNode = new ADTResetNode<>(newNode);
  
              newResetNode.setParent(endOfPreviousADS);
              newNode.setParent(newResetNode);
              endOfPreviousADS.getChildren().put(outputToReset, newResetNode);
          }
      }
docs: Replaces an existing node in the tree with a new one and updates the references of parent/child nodes
  accordingly.
  
  @param oldNode
  the node to replace
  @param newNode
  the replacement