示例#1
0
  /**
   * Adds a GenomeLoc to the collection, merging it if it overlaps another region. If it's not
   * overlapping then we add it in sorted order.
   *
   * @param e the GenomeLoc to add to the collection
   * @return true, if the GenomeLoc could be added to the collection
   */
  public boolean addRegion(GenomeLoc e) {
    if (e == null) {
      return false;
    }
    // have we added it to the collection?
    boolean haveAdded = false;

    /**
     * check if the specified element overlaps any current locations, if so we should merge the two.
     */
    for (GenomeLoc g : mArray) {
      if (g.contiguousP(e)) {
        GenomeLoc c = g.merge(e);
        mArray.set(mArray.indexOf(g), c);
        haveAdded = true;
      } else if ((g.getContigIndex() == e.getContigIndex())
          && (e.getStart() < g.getStart())
          && !haveAdded) {
        mArray.add(mArray.indexOf(g), e);
        return true;
      } else if (haveAdded
          && ((e.getContigIndex() > e.getContigIndex())
              || (g.getContigIndex() == e.getContigIndex() && e.getStart() > g.getStart()))) {
        return true;
      }
    }
    /**
     * we're at the end and we haven't found locations that should fall after it, so we'll put it at
     * the end
     */
    if (!haveAdded) {
      mArray.add(e);
    }
    return true;
  }