/**
   * Updates _lineStartPos, _lineEndPos of regions in the interval [firstRegion, lastRegion] using
   * total ordering on regions. Removes empty regions. firstRegion and lastRegion are not
   * necessarily regions in this manager.
   */
  public void updateLines(R firstRegion, R lastRegion) {
    assert Utilities.TEST_MODE || EventQueue.isDispatchThread();

    /* Get the tailSet consisting of the ordered set of regions >= firstRegion. */
    SortedSet<R> tail = getTailSet(firstRegion);
    if (tail.size() == 0)
      return; // tail can be empty if firstRegion is a constructed DocumentRegion

    List<R> toBeRemoved = new ArrayList<R>(); // nonsense to avoid concurrent modification exception
    for (R region : tail) {
      if (region.compareTo(lastRegion) > 0) break;
      region.update(); // The bounds of this region must be recomputed.
      if (region.getStartOffset() == region.getEndOffset()) toBeRemoved.add(region);
    }
    removeRegions(toBeRemoved);
  }
Example #2
0
  @Override
  public final R apply(List<T> elements) {
    if (elements.size() == 0) {
      return null;
    }

    R curMax = null;
    for (T elem : elements) {
      if (elem == null || function.apply(elem) == null) {
        continue;
      }
      if (curMax == null) {
        curMax = function.apply(elem);
      }
      if (curMax.compareTo(function.apply(elem)) < 0) {
        curMax = function.apply(elem);
      }
    }
    return curMax;
  }