diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java index a893bdd693..51d18bdb59 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java @@ -43,26 +43,18 @@ public final class HSSFRow implements Comparable { /** * reference to low level representation */ - private RowRecord row; /** * reference to containing low level Workbook */ - private HSSFWorkbook book; /** * reference to containing Sheet */ - private Sheet sheet; - // TODO - ditch this constructor - HSSFRow() - { - } - /** * Creates new HSSFRow from scratch. Only HSSFSheet should do this. * diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index 486fa96301..84a71a89aa 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -81,7 +81,8 @@ public final class HSSFSheet { */ private Sheet sheet; - private TreeMap rows; // TODO - use simple key into this map + /** stores HSSFRows by Integer (zero-based row number) key */ + private TreeMap rows; protected Workbook book; protected HSSFWorkbook workbook; private int firstrow; @@ -99,7 +100,7 @@ public final class HSSFSheet { protected HSSFSheet(HSSFWorkbook workbook) { sheet = Sheet.createSheet(); - rows = new TreeMap(); // new ArrayList(INITIAL_CAPACITY); + rows = new TreeMap(); this.workbook = workbook; this.book = workbook.getWorkbook(); } @@ -224,7 +225,14 @@ public final class HSSFSheet { public void removeRow(HSSFRow row) { 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()) { lastrow = findLastRow(lastrow); @@ -284,7 +292,7 @@ public final class HSSFSheet { private void addRow(HSSFRow row, boolean addLow) { - rows.put(row, row); + rows.put(new Integer(row.getRowNum()), row); if (addLow) { 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 * 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 */ - - public HSSFRow getRow(int rownum) - { - HSSFRow row = new HSSFRow(); - - //row.setRowNum((short) rownum); - row.setRowNum( rownum); - return (HSSFRow) rows.get(row); + public HSSFRow getRow(int rowIndex) { + return (HSSFRow) rows.get(new Integer(rowIndex)); } /** @@ -573,7 +575,7 @@ public final class HSSFSheet { public void setHorizontallyCenter(boolean value) { - sheet.getPageSettings().getHCenter().setHCenter(value); + sheet.getPageSettings().getHCenter().setHCenter(value); } /**