if (length == 0) return;  this.offset = offset; this.pos = offset; this.endOffset = offset + length; this.length = length; documentEvent = ev;  edits.removeAllElements(); elementStack.removeAllElements(); lastFractured = null; fracNotCreated = false; insertUpdate(data);   int size = edits.size(); for (int i = 0; i < size; i++) { Edit curr = (Edit) edits.get(i); BranchElement e = (BranchElement) curr.e; Element[] removed = curr.getRemovedElements(); Element[] added = curr.getAddedElements();   if (removed.length > 0 || added.length > 0) { if (curr.index + removed.length <= e.getElementCount()) { e.replace(curr.index, removed.length, added); ElementEdit ee = new ElementEdit(e, curr.index, removed, added); ev.addEdit(ee); } else { System.err.println("WARNING: Tried to replace elements "); System.err.print("beyond boundaries: elementCount: "); System.err.println(e.getElementCount()); System.err.print("index: " + curr.index); System.err.println(", removed.length: " + removed.length); } }
if (length > 0) { prepareEdit(offset, length); insertUpdate(data); finishEdit(ev); }
    public void insert(int offset, int length, ElementSpec[] data,                       DefaultDocumentEvent ev)    {      if (length == 0)        return;            this.offset = offset;      this.pos = offset;      this.endOffset = offset + length;      this.length = length;      documentEvent = ev;            edits.removeAllElements();      elementStack.removeAllElements();      lastFractured = null;      fracNotCreated = false;      insertUpdate(data);      // This for loop applies all the changes that were made and updates the       // DocumentEvent.      int size = edits.size();      for (int i = 0; i < size; i++)        {          Edit curr = (Edit) edits.get(i);          BranchElement e = (BranchElement) curr.e;          Element[] removed = curr.getRemovedElements();          Element[] added = curr.getAddedElements();          // FIXME: We probably shouldn't create the empty Element[] in the          // first place.          if (removed.length > 0 || added.length > 0)            {              if (curr.index + removed.length <= e.getElementCount())                {          e.replace(curr.index, removed.length, added);          ElementEdit ee = new ElementEdit(e, curr.index, removed, added);          ev.addEdit(ee);        }              else                {                  System.err.println("WARNING: Tried to replace elements ");                  System.err.print("beyond boundaries: elementCount: ");                  System.err.println(e.getElementCount());                  System.err.print("index: " + curr.index);                  System.err.println(", removed.length: " + removed.length);                }            }    }    }