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) res.add(p); }
  protected Vector getPositionsInRange(Vector v, int offset, int length)  {    Vector res = v;    if (res == null)      res = new Vector();    else      res.clear();    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)          res.add(p);      }    return res;  }