Browse Source

please go to the branch, oh please oh please oh please... I goofed apparently before

and the reason the performance branch was so broken was I didn't check in HSSFRow the new HSSFRow!! doh!


git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/performance-branch@353038 13f79535-47bb-0310-9956-ffa450edef68
remotes/performance-branch@550310
Andrew C. Oliver 21 years ago
parent
commit
da3d9f9cd5
1 changed files with 109 additions and 47 deletions
  1. 109
    47
      src/java/org/apache/poi/hssf/usermodel/HSSFRow.java

+ 109
- 47
src/java/org/apache/poi/hssf/usermodel/HSSFRow.java View File

import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.CellValueRecordInterface; import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.RowRecord; import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;


import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
public final static int INITIAL_CAPACITY = 5; public final static int INITIAL_CAPACITY = 5;
//private short rowNum; //private short rowNum;
private int rowNum; private int rowNum;
private HashMap cells;
//private ValueRecordsAggregate cells;
// private short firstcell = -1; // private short firstcell = -1;
// private short lastcell = -1; // private short lastcell = -1;


* reference to low level representation * reference to low level representation
*/ */


private RowRecord row;
//private RowRecord row;


/** /**
* reference to containing low level Workbook * reference to containing low level Workbook
protected HSSFRow(Workbook book, Sheet sheet, int rowNum) protected HSSFRow(Workbook book, Sheet sheet, int rowNum)
{ {
this.rowNum = rowNum; this.rowNum = rowNum;
cells = new HashMap(10); // new ArrayList(INITIAL_CAPACITY);
//cells = new HashMap(10); // new ArrayList(INITIAL_CAPACITY);
this.book = book; this.book = book;
this.sheet = sheet; this.sheet = sheet;
row = new RowRecord();
row.setHeight((short) 0xff);
row.setLastCol((short) -1);
row.setFirstCol((short) -1);
//row = new RowRecord();
//row.setHeight((short) 0xff);
//row.setLastCol((short) -1);
//row.setFirstCol((short) -1);


// row.setRowNumber(rowNum); // row.setRowNumber(rowNum);
setRowNum(rowNum);
//setRowNum(rowNum);
} }


/** /**
protected HSSFRow(Workbook book, Sheet sheet, RowRecord record) protected HSSFRow(Workbook book, Sheet sheet, RowRecord record)
{ {
//this.rowNum = rowNum; //this.rowNum = rowNum;
cells = new HashMap(); // ArrayList(INITIAL_CAPACITY);
//cells = new HashMap(); // ArrayList(INITIAL_CAPACITY);
this.book = book; this.book = book;
this.sheet = sheet; this.sheet = sheet;
row = record;
//row = record;


// row.setHeight(record.getHeight()); // row.setHeight(record.getHeight());
// row.setRowNumber(rowNum); // row.setRowNumber(rowNum);
{ {
HSSFCell cell = new HSSFCell(book, sheet, getRowNum(), column); HSSFCell cell = new HSSFCell(book, sheet, getRowNum(), column);


addCell(cell);
sheet.addValueRecord(getRowNum(), cell.getCellValueRecord());
//addCell(cell);
//sheet.addValueRecord(getRowNum(), cell.getCellValueRecord());
return cell; return cell;
} }


CellValueRecordInterface cval = cell.getCellValueRecord(); CellValueRecordInterface cval = cell.getCellValueRecord();


sheet.removeValueRecord(getRowNum(), cval); sheet.removeValueRecord(getRowNum(), cval);
cells.remove(new Integer(cell.getCellNum()));
//cells.remove(new Integer(cell.getCellNum()));


if (cell.getCellNum() == row.getLastCol())
if (cell.getCellNum() == getLastCol(rowNum))
{ {
row.setLastCol(findLastCell(row.getLastCol()));
sheet.getRow(rowNum).setLastCol(findLastCell(sheet.getRow(rowNum).getLastCol()));
} }
if (cell.getCellNum() == row.getFirstCol())
if (cell.getCellNum() == getFirstCol(rowNum))
{ {
row.setFirstCol(findFirstCell(row.getFirstCol()));
setFirstCol(findFirstCell(getFirstCol(rowNum)));
} }
} }




addCell(hcell); addCell(hcell);


// sheet.addValueRecord(getRowNum(),cell.getCellValueRecord());
sheet.addValueRecord(getRowNum(),cell);
return hcell; return hcell;
} }


public void setRowNum(int rowNum) public void setRowNum(int rowNum)
{ {
this.rowNum = rowNum; this.rowNum = rowNum;
if (row != null)
{
row.setRowNumber(rowNum); // used only for KEY comparison (HSSFRow)
}
//if (row != null)
//{
// row.setRowNumber(rowNum); // used only for KEY comparison (HSSFRow)
//}
} }


/** /**


private void addCell(HSSFCell cell) private void addCell(HSSFCell cell)
{ {
if (row.getFirstCol() == -1)
if (getFirstCol(rowNum) == -1)
{ {
row.setFirstCol(cell.getCellNum());
setFirstCol(cell.getCellNum());
} }
if (row.getLastCol() == -1)
if (getLastCol(rowNum) == -1)
{ {
row.setLastCol(cell.getCellNum());
setLastCol(cell.getCellNum());
} }
cells.put(new Integer(cell.getCellNum()), cell);
//cells.put(new Integer(cell.getCellNum()), cell);
sheet.addValueRecord(this.rowNum, cell.getCellValueRecord());


if (cell.getCellNum() < row.getFirstCol())
if (cell.getCellNum() < getFirstCol(rowNum))
{ {
row.setFirstCol(cell.getCellNum());
setFirstCol(cell.getCellNum());
} }
if (cell.getCellNum() > row.getLastCol())
if (cell.getCellNum() > getLastCol(rowNum))
{ {
row.setLastCol(cell.getCellNum());
setLastCol(cell.getCellNum());
} }
} }


private void setLastCol(short cell) {
sheet.setLastColForRow(rowNum, cell);
}

private void setFirstCol(short cell) {
sheet.setFirstColForRow(rowNum, cell);
}

private short getLastCol(int row) {
return sheet.getLastColForRow(row);
}

private short getFirstCol(int row) {
return sheet.getFirstColForRow(row);
}


/** /**
* get the hssfcell representing a given column (logical cell) 0-based. If you * get the hssfcell representing a given column (logical cell) 0-based. If you
* ask for a cell that is not defined....you get a null. * ask for a cell that is not defined....you get a null.


public HSSFCell getCell(short cellnum) public HSSFCell getCell(short cellnum)
{ {
HSSFCell retval = null;
CellValueRecordInterface cval = sheet.getValueRecord(rowNum, cellnum);
if (cval != null) {
retval = new HSSFCell(book, sheet, rowNum, cval);
}


/* for (int k = 0; k < cells.size(); k++) /* for (int k = 0; k < cells.size(); k++)
{ {
return cell; return cell;
} }
}*/ }*/
return (HSSFCell) cells.get(new Integer(cellnum));
return retval;
} }


/** /**
if (getPhysicalNumberOfCells() == 0) if (getPhysicalNumberOfCells() == 0)
return -1; return -1;
else else
return row.getFirstCol();
return getFirstCol(rowNum);
} }


/** /**
if (getPhysicalNumberOfCells() == 0) if (getPhysicalNumberOfCells() == 0)
return -1; return -1;
else else
return row.getLastCol();
return getLastCol(rowNum);
} }






public int getPhysicalNumberOfCells() public int getPhysicalNumberOfCells()
{ {
if (cells == null)
{
return 0; // shouldn't be possible but it is due to missing API support for BLANK/MULBLANK
}
return cells.size();
// sheet.get
// if (cells == null)
// {
// return 0; // shouldn't be possible but it is due to missing API support for BLANK/MULBLANK
// }
// return cells.size();
return sheet.getPhysicalNumberOfRows();
} }


/** /**
{ {


// row.setOptionFlags( // row.setOptionFlags(
row.setBadFontHeight(true);
row.setHeight(height);
sheet.getRow(rowNum).setBadFontHeight(true);
sheet.getRow(rowNum).setHeight(height);
} }


/** /**
{ {


// row.setOptionFlags( // row.setOptionFlags(
row.setBadFontHeight(true);
row.setHeight((short) (height * 20));
sheet.getRow(rowNum).setBadFontHeight(true);
sheet.getRow(rowNum).setHeight((short) (height * 20));
} }


/** /**


public short getHeight() public short getHeight()
{ {
return row.getHeight();
return sheet.getRow(rowNum).getHeight();
} }


/** /**


public float getHeightInPoints() public float getHeightInPoints()
{ {
return (row.getHeight() / 20);
return (sheet.getRow(rowNum).getHeight() / 20);
} }


/** /**


protected RowRecord getRowRecord() protected RowRecord getRowRecord()
{ {
return row;
return sheet.getRow(rowNum);
} }


/** /**


public Iterator cellIterator() public Iterator cellIterator()
{ {
return cells.values().iterator();
return new RowCellIterator(this.book, this.sheet, this.rowNum);
} }


public int compareTo(Object obj) public int compareTo(Object obj)
} }
return false; return false;
} }



} }


class RowCellIterator implements Iterator {
Iterator cells;
Workbook book;
Sheet sheet;
int row;

public RowCellIterator(Workbook book, Sheet sheet, int row) {
this.sheet = sheet;
this.book = book;
this.row = row;
cells = this.sheet.rowCellIterator(row);
}

public boolean hasNext() {
return cells.hasNext();
}

public Object next() {
HSSFCell retval = null;
if (cells.hasNext()) {
retval = new HSSFCell(book, sheet, row, ((CellValueRecordInterface)cells.next()));
}
return retval;
}

public void remove() {
cells.remove();
}


}

Loading…
Cancel
Save