code: public Node replaceNode(int index, Node newNode)
      {
          if (index == 0)
          {
              return newNode;
          }
  
          int conditionNodes = condition.countNodes();
          if (index <= conditionNodes)
          {
              return new IfThenElse(condition.replaceNode(index - 1, newNode), then, otherwise);
          }
          else
          {
              int thenNodes = then.countNodes();
              if (index <= conditionNodes + thenNodes)
              {
                  return new IfThenElse(condition, then.replaceNode(index - conditionNodes - 1, newNode), otherwise);
              }
              else
              {
                  return new IfThenElse(condition,
                                        then,
                                        otherwise.replaceNode(index - conditionNodes - thenNodes - 1, newNode));
              }
          }
      }
docs: {@inheritDoc}