while (index1 > 0) { WeakReference r = (WeakReference) positions.get(index1 - 1); GapContentPosition p = (GapContentPosition) r.get(); if (p != null && p.mark == offset || p == null) index1--; else break;
assert (startIndex <= 0 || positionMarks[startIndex - 1] <= positionMarks [startIndex] + incr) && (endIndex >= numMarks - 1 || positionMarks[endIndex + 1] >= positionMarks[endIndex] + incr) : "Adjusting the marks must not change their order";    if (startIndex > 0 && positionMarks[startIndex - 1] == positionMarks[startIndex] + incr) System.err.println("DEBUG: We could coalesce the start of the region" + " in GapContent.adjustPositionsInRange()"); if (endIndex < numMarks - 1 && positionMarks[endIndex + 1] == positionMarks[endIndex] + incr) System.err.println("DEBUG: We could coalesce the end of the region" + " in GapContent.adjustPositionsInRange()");   for (int i = startIndex; i <= endIndex; i++) positionMarks[i] += incr;
  private void adjustPositionsInRange(int offset, int length, int incr)  {    int endOffset = offset + length;    int index1 = Collections.binarySearch(positions,                                          new GapContentPosition(offset),                                          new WeakPositionComparator());    if (index1 < 0)      index1 = -(index1 + 1);    // Search the first index with the specified offset. The binarySearch does    // not necessarily find the first one.    while (index1 > 0)      {        WeakReference r = (WeakReference) positions.get(index1 - 1);        GapContentPosition p = (GapContentPosition) r.get();        if (p != null && p.mark == offset || p == null)      index1--;        else          break;      }    for (ListIterator i = positions.listIterator(index1); i.hasNext();)      {        WeakReference r = (WeakReference) i.next();        GapContentPosition p = (GapContentPosition) r.get();        if (p == null)          continue;        if (p.mark > endOffset)          break;                if (p.mark >= offset && p.mark <= endOffset)          p.mark += incr;      }  }