public void insertRow(RowRecord row) {
   // Integer integer = Integer.valueOf(row.getRowNumber());
   _rowRecords.put(Integer.valueOf(row.getRowNumber()), row);
   if ((row.getRowNumber() < _firstrow) || (_firstrow == -1)) {
     _firstrow = row.getRowNumber();
   }
   if ((row.getRowNumber() > _lastrow) || (_lastrow == -1)) {
     _lastrow = row.getRowNumber();
   }
 }
 public void removeRow(RowRecord row) {
   int rowIndex = row.getRowNumber();
   _valuesAgg.removeAllCellsValuesForRow(rowIndex);
   Integer key = Integer.valueOf(rowIndex);
   RowRecord rr = _rowRecords.remove(key);
   if (rr == null) {
     throw new RuntimeException("Invalid row index (" + key.intValue() + ")");
   }
   if (row != rr) {
     _rowRecords.put(key, rr);
     throw new RuntimeException("Attempt to remove row that does not belong to this sheet");
   }
 }
  /** Returns the physical row number of the end row in a block */
  private int getEndRowNumberForBlock(int block) {
    int endIndex = ((block + 1) * DBCellRecord.BLOCK_SIZE) - 1;
    if (endIndex >= _rowRecords.size()) endIndex = _rowRecords.size() - 1;

    Iterator<RowRecord> rowIter = _rowRecords.values().iterator();
    RowRecord row = null;
    for (int i = 0; i <= endIndex; i++) {
      row = rowIter.next();
    }
    if (row == null) {
      throw new RuntimeException("Did not find start row for block " + block);
    }
    return row.getRowNumber();
  }
  /** Returns the physical row number of the first row in a block */
  private int getStartRowNumberForBlock(int block) {
    // Given that we basically iterate through the rows in order,
    // TODO - For a performance improvement, it would be better to return an instance of
    // an iterator and use that instance throughout, rather than recreating one and
    // having to move it to the right position.
    int startIndex = block * DBCellRecord.BLOCK_SIZE;
    Iterator<RowRecord> rowIter = _rowRecords.values().iterator();
    RowRecord row = null;
    // Position the iterator at the start of the block
    for (int i = 0; i <= startIndex; i++) {
      row = rowIter.next();
    }
    if (row == null) {
      throw new RuntimeException("Did not find start row for block " + block);
    }

    return row.getRowNumber();
  }