Converted rows map within HSSFSheet to use Integer keys
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@684318 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1400017540
commit
334bc3f42e
@ -43,26 +43,18 @@ public final class HSSFRow implements Comparable {
|
|||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private HSSFWorkbook book;
|
private HSSFWorkbook book;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reference to containing Sheet
|
* reference to containing Sheet
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private Sheet sheet;
|
private Sheet sheet;
|
||||||
|
|
||||||
// TODO - ditch this constructor
|
|
||||||
HSSFRow()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new HSSFRow from scratch. Only HSSFSheet should do this.
|
* Creates new HSSFRow from scratch. Only HSSFSheet should do this.
|
||||||
*
|
*
|
||||||
|
@ -81,7 +81,8 @@ public final class HSSFSheet {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
private Sheet sheet;
|
private Sheet sheet;
|
||||||
private TreeMap rows; // TODO - use simple key into this map
|
/** stores <tt>HSSFRow</tt>s by <tt>Integer</tt> (zero-based row number) key */
|
||||||
|
private TreeMap rows;
|
||||||
protected Workbook book;
|
protected Workbook book;
|
||||||
protected HSSFWorkbook workbook;
|
protected HSSFWorkbook workbook;
|
||||||
private int firstrow;
|
private int firstrow;
|
||||||
@ -99,7 +100,7 @@ public final class HSSFSheet {
|
|||||||
protected HSSFSheet(HSSFWorkbook workbook)
|
protected HSSFSheet(HSSFWorkbook workbook)
|
||||||
{
|
{
|
||||||
sheet = Sheet.createSheet();
|
sheet = Sheet.createSheet();
|
||||||
rows = new TreeMap(); // new ArrayList(INITIAL_CAPACITY);
|
rows = new TreeMap();
|
||||||
this.workbook = workbook;
|
this.workbook = workbook;
|
||||||
this.book = workbook.getWorkbook();
|
this.book = workbook.getWorkbook();
|
||||||
}
|
}
|
||||||
@ -224,7 +225,14 @@ public final class HSSFSheet {
|
|||||||
public void removeRow(HSSFRow row) {
|
public void removeRow(HSSFRow row) {
|
||||||
if (rows.size() > 0)
|
if (rows.size() > 0)
|
||||||
{
|
{
|
||||||
rows.remove(row);
|
Integer key = new Integer(row.getRowNum());
|
||||||
|
HSSFRow removedRow = (HSSFRow) rows.remove(key);
|
||||||
|
if (removedRow != row) {
|
||||||
|
if (removedRow != null) {
|
||||||
|
rows.put(key, removedRow);
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Specified row does not belong to this sheet");
|
||||||
|
}
|
||||||
if (row.getRowNum() == getLastRowNum())
|
if (row.getRowNum() == getLastRowNum())
|
||||||
{
|
{
|
||||||
lastrow = findLastRow(lastrow);
|
lastrow = findLastRow(lastrow);
|
||||||
@ -284,7 +292,7 @@ public final class HSSFSheet {
|
|||||||
|
|
||||||
private void addRow(HSSFRow row, boolean addLow)
|
private void addRow(HSSFRow row, boolean addLow)
|
||||||
{
|
{
|
||||||
rows.put(row, row);
|
rows.put(new Integer(row.getRowNum()), row);
|
||||||
if (addLow)
|
if (addLow)
|
||||||
{
|
{
|
||||||
sheet.addRow(row.getRowRecord());
|
sheet.addRow(row.getRowRecord());
|
||||||
@ -302,17 +310,11 @@ public final class HSSFSheet {
|
|||||||
/**
|
/**
|
||||||
* Returns the logical row (not physical) 0-based. If you ask for a row that is not
|
* Returns the logical row (not physical) 0-based. If you ask for a row that is not
|
||||||
* defined you get a null. This is to say row 4 represents the fifth row on a sheet.
|
* defined you get a null. This is to say row 4 represents the fifth row on a sheet.
|
||||||
* @param rownum row to get
|
* @param rowIndex row to get
|
||||||
* @return HSSFRow representing the rownumber or null if its not defined on the sheet
|
* @return HSSFRow representing the rownumber or null if its not defined on the sheet
|
||||||
*/
|
*/
|
||||||
|
public HSSFRow getRow(int rowIndex) {
|
||||||
public HSSFRow getRow(int rownum)
|
return (HSSFRow) rows.get(new Integer(rowIndex));
|
||||||
{
|
|
||||||
HSSFRow row = new HSSFRow();
|
|
||||||
|
|
||||||
//row.setRowNum((short) rownum);
|
|
||||||
row.setRowNum( rownum);
|
|
||||||
return (HSSFRow) rows.get(row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user