Element paragraph = root.getElement(i);
BranchElement paragraph = (BranchElement) root.getElement(i);
    protected void removeUpdate()    {      int startParagraph = root.getElementIndex(offset);      int endParagraph = root.getElementIndex(offset + length);      Element[] empty = new Element[0];      int removeStart = -1;      int removeEnd = -1;      for (int i = startParagraph;  i < endParagraph; i++)        {          Element paragraph = root.getElement(i);          int contentStart = paragraph.getElementIndex(offset);          int contentEnd = paragraph.getElementIndex(offset + length);          if (contentStart == paragraph.getStartOffset()              && contentEnd == paragraph.getEndOffset())            {              // In this case we only need to remove the whole paragraph. We              // do this in one go after this loop and only record the indices              // here.              if (removeStart == -1)                {                  removeStart = i;                  removeEnd = i;                }              else                removeEnd = i;            }          else            {              // In this case we remove a couple of child elements from this              // paragraph.              int removeLen = contentEnd - contentStart;              Element[] removed = new Element[removeLen];              for (int j = contentStart; j < contentEnd; j++)                removed[j] = paragraph.getElement(j);              ((BranchElement) paragraph).replace(contentStart, removeLen,                                                  empty);              documentEvent.addEdit(new ElementEdit(paragraph, contentStart,                                                    removed, empty));            }        }      // Now we remove paragraphs from the root that have been tagged for      // removal.      if (removeStart != -1)        {          int removeLen = removeEnd - removeStart;          Element[] removed = new Element[removeLen];          for (int i = removeStart; i < removeEnd; i++)            removed[i] = root.getElement(i);          ((BranchElement) root).replace(removeStart, removeLen, empty);          documentEvent.addEdit(new ElementEdit(root, removeStart, removed,                                                empty));        }    }