Merged revisions 703092 via svnmerge from

https://svn.apache.org/repos/asf/poi/trunk

........
  r703092 | josh | 2008-10-09 00:44:37 -0700 (Thu, 09 Oct 2008) | 1 line
  
  converted short HSSFCell.getCellNum to int getColumnIndex
........


git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@703096 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-10-09 08:03:43 +00:00
parent b3959ec237
commit 91d6061c07
12 changed files with 50 additions and 33 deletions

View File

@ -232,7 +232,7 @@ public class HSSFCell implements Cell {
/** /**
* Set the cell's number within the row (0 based). * Set the cell's number within the row (0 based).
* @param num short the cell number * @param num short the cell number
* @deprecated Doesn't update the row's idea of what cell this is, use {@link HSSFRow#moveCell(HSSFCell, short)} instead * @deprecated (Jan 2008) Doesn't update the row's idea of what cell this is, use {@link HSSFRow#moveCell(HSSFCell, short)} instead
*/ */
public void setCellNum(short num) public void setCellNum(short num)
{ {
@ -250,13 +250,14 @@ public class HSSFCell implements Cell {
} }
/** /**
* get the cell's number within the row * @deprecated (Oct 2008) use {@link #getColumnIndex()}
* @return short reperesenting the column number (logical!)
*/ */
public short getCellNum() {
public short getCellNum() return (short) getColumnIndex();
{ }
return record.getColumn();
public int getColumnIndex() {
return record.getColumn() & 0xFFFF;
} }
/** /**

View File

@ -55,7 +55,7 @@ final class HSSFEvaluationCell implements EvaluationCell {
return _cell.getCellType(); return _cell.getCellType();
} }
public int getColumnIndex() { public int getColumnIndex() {
return _cell.getCellNum(); return _cell.getColumnIndex();
} }
public int getErrorCellValue() { public int getErrorCellValue() {
return _cell.getErrorCellValue(); return _cell.getErrorCellValue();

View File

@ -155,7 +155,7 @@ public final class HSSFRow implements Comparable, Row {
} }
private void removeCell(HSSFCell cell, boolean alsoRemoveRecords) { private void removeCell(HSSFCell cell, boolean alsoRemoveRecords) {
short column=cell.getCellNum(); int column=cell.getColumnIndex();
if(column < 0) { if(column < 0) {
throw new RuntimeException("Negative cell indexes not allowed"); throw new RuntimeException("Negative cell indexes not allowed");
} }
@ -169,10 +169,10 @@ public final class HSSFRow implements Comparable, Row {
sheet.getSheet().removeValueRecord(getRowNum(), cval); sheet.getSheet().removeValueRecord(getRowNum(), cval);
} }
if (cell.getCellNum()+1 == row.getLastCol()) { if (cell.getColumnIndex()+1 == row.getLastCol()) {
row.setLastCol((short) (findLastCell(row.getLastCol())+1)); row.setLastCol((short) (findLastCell(row.getLastCol())+1));
} }
if (cell.getCellNum() == row.getFirstCol()) { if (cell.getColumnIndex() == row.getFirstCol()) {
row.setFirstCol(findFirstCell(row.getFirstCol())); row.setFirstCol(findFirstCell(row.getFirstCol()));
} }
} }
@ -252,7 +252,7 @@ public final class HSSFRow implements Comparable, Row {
} }
// Check it's one of ours // Check it's one of ours
if(! cells[cell.getCellNum()].equals(cell)) { if(! cells[cell.getColumnIndex()].equals(cell)) {
throw new IllegalArgumentException("Asked to move a cell, but it didn't belong to our row"); throw new IllegalArgumentException("Asked to move a cell, but it didn't belong to our row");
} }
@ -268,7 +268,7 @@ public final class HSSFRow implements Comparable, Row {
*/ */
private void addCell(HSSFCell cell) { private void addCell(HSSFCell cell) {
short column=cell.getCellNum(); int column=cell.getColumnIndex();
// re-allocate cells array as required. // re-allocate cells array as required.
if(column>=cells.length) { if(column>=cells.length) {
HSSFCell[] oldCells=cells; HSSFCell[] oldCells=cells;
@ -283,7 +283,7 @@ public final class HSSFRow implements Comparable, Row {
// fix up firstCol and lastCol indexes // fix up firstCol and lastCol indexes
if (row.getFirstCol() == -1 || column < row.getFirstCol()) { if (row.getFirstCol() == -1 || column < row.getFirstCol()) {
row.setFirstCol(column); row.setFirstCol((short)column);
} }
if (row.getLastCol() == -1 || column >= row.getLastCol()) { if (row.getLastCol() == -1 || column >= row.getLastCol()) {

View File

@ -77,7 +77,15 @@ public interface Cell {
int getCellType(); int getCellType();
/**
* @deprecated (Oct 2008) use {@link #getColumnIndex()}
*/
short getCellNum(); short getCellNum();
/**
* @return the cell's column index (zero based)
*/
int getColumnIndex();
int getRowIndex(); int getRowIndex();
String getCellFormula(); String getCellFormula();

View File

@ -98,11 +98,14 @@ public interface Cell {
void setCellNum(short num); void setCellNum(short num);
/** /**
* get the cell's number within the row * @deprecated (Oct 2008) use {@link #getColumnIndex()}
* @return short reperesenting the column number (logical!)
*/ */
short getCellNum(); short getCellNum();
/**
* @return the cell's column index (zero based)
*/
int getColumnIndex();
int getRowIndex(); int getRowIndex();

View File

@ -107,8 +107,14 @@ public final class XSSFCell implements Cell {
return this.cell.getF().getStringValue(); return this.cell.getF().getStringValue();
} }
/**
* @deprecated use {@link #getColumnIndex()}
*/
public short getCellNum() { public short getCellNum() {
return (short)this.cellNum; return (short)getColumnIndex();
}
public int getColumnIndex() {
return this.cellNum;
} }
public int getRowIndex() { public int getRowIndex() {
return row.getRowNum(); return row.getRowNum();

View File

@ -205,10 +205,10 @@ public final class TestIndexFunctionFromSpreadsheet extends TestCase {
} }
private static String formatTestCaseDetails(String sheetName, int rowNum, HSSFCell c) { private static String formatTestCaseDetails(String sheetName, int rowIndex, HSSFCell c) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
CellReference cr = new CellReference(sheetName, rowNum, c.getCellNum(), false, false); CellReference cr = new CellReference(sheetName, rowIndex, c.getColumnIndex(), false, false);
sb.append(cr.formatAsString()); sb.append(cr.formatAsString());
sb.append(" {=").append(c.getCellFormula()).append("}"); sb.append(" {=").append(c.getCellFormula()).append("}");
return sb.toString(); return sb.toString();

View File

@ -256,11 +256,11 @@ public final class TestLookupFunctionsFromSpreadsheet extends TestCase {
} }
private static String formatTestCaseDetails(String sheetName, int rowNum, HSSFCell c, String currentGroupComment, private static String formatTestCaseDetails(String sheetName, int rowIndex, HSSFCell c, String currentGroupComment,
String rowComment) { String rowComment) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
CellReference cr = new CellReference(sheetName, rowNum, c.getCellNum(), false, false); CellReference cr = new CellReference(sheetName, rowIndex, c.getColumnIndex(), false, false);
sb.append(cr.formatAsString()); sb.append(cr.formatAsString());
sb.append(" {=").append(c.getCellFormula()).append("}"); sb.append(" {=").append(c.getCellFormula()).append("}");

View File

@ -66,7 +66,7 @@ public final class TestBug42464 extends TestCase {
FormulaRecord r = record.getFormulaRecord(); FormulaRecord r = record.getFormulaRecord();
Ptg[] ptgs = r.getParsedExpression(); Ptg[] ptgs = r.getParsedExpression();
String cellRef = new CellReference(row.getRowNum(), cell.getCellNum(), false, false).formatAsString(); String cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex(), false, false).formatAsString();
if(false && cellRef.equals("BP24")) { // TODO - replace System.out.println()s with asserts if(false && cellRef.equals("BP24")) { // TODO - replace System.out.println()s with asserts
System.out.print(cellRef); System.out.print(cellRef);
System.out.println(" - has " + ptgs.length + " ptgs:"); System.out.println(" - has " + ptgs.length + " ptgs:");

View File

@ -619,7 +619,7 @@ public final class TestBugs extends TestCase {
int cellNum = 0; int cellNum = 0;
for (Iterator it2 = row.cellIterator(); it2.hasNext(); cellNum++) { for (Iterator it2 = row.cellIterator(); it2.hasNext(); cellNum++) {
HSSFCell cell = (HSSFCell)it2.next(); HSSFCell cell = (HSSFCell)it2.next();
assertEquals(cellNum, cell.getCellNum()); assertEquals(cellNum, cell.getColumnIndex());
} }
} }
} }

View File

@ -134,7 +134,7 @@ public final class TestHSSFComment extends TestCase {
assertFalse("cells in the second column have not empyy notes", assertFalse("cells in the second column have not empyy notes",
"".equals(comment.getString().getString())); "".equals(comment.getString().getString()));
assertEquals(rownum, comment.getRow()); assertEquals(rownum, comment.getRow());
assertEquals(cell.getCellNum(), comment.getColumn()); assertEquals(cell.getColumnIndex(), comment.getColumn());
} }
} }

View File

@ -20,7 +20,6 @@ package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
/** /**
* Test HSSFRow is okay. * Test HSSFRow is okay.
@ -152,7 +151,7 @@ public final class TestHSSFRow extends TestCase {
assertNull(row.getCell(1)); assertNull(row.getCell(1));
assertNotNull(row.getCell(5)); assertNotNull(row.getCell(5));
assertEquals(5, cellB2.getCellNum()); assertEquals(5, cellB2.getColumnIndex());
assertEquals(2, row.getFirstCellNum()); assertEquals(2, row.getFirstCellNum());
assertEquals(6, row.getLastCellNum()); assertEquals(6, row.getLastCellNum());
} }
@ -258,12 +257,12 @@ public final class TestHSSFRow extends TestCase {
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getCellType());
// Check created ones get the right column // Check created ones get the right column
assertEquals((short)0, row.getCell(0, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); assertEquals(0, row.getCell(0, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
assertEquals((short)1, row.getCell(1, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); assertEquals(1, row.getCell(1, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
assertEquals((short)2, row.getCell(2, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); assertEquals(2, row.getCell(2, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
assertEquals((short)3, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); assertEquals(3, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
assertEquals((short)4, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); assertEquals(4, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
assertEquals((short)5, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); assertEquals(5, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
// Now change the cell policy on the workbook, check // Now change the cell policy on the workbook, check