]> source.dussan.org Git - poi.git/commitdiff
converted short HSSFCell.getCellNum to int getColumnIndex
authorJosh Micich <josh@apache.org>
Thu, 9 Oct 2008 07:44:37 +0000 (07:44 +0000)
committerJosh Micich <josh@apache.org>
Thu, 9 Oct 2008 07:44:37 +0000 (07:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@703092 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java
src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
src/testcases/org/apache/poi/hssf/record/formula/functions/TestIndexFunctionFromSpreadsheet.java
src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java
src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java

index 3d2f99f41ed2e27c2fb1bd5fc3173d0f6edc68d3..9c1f1457f505ca3e6494f902b534492a6738700a 100644 (file)
@@ -228,7 +228,7 @@ public final class HSSFCell {
     /**
      * Set the cell's number within the row (0 based).
      * @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)
     {
@@ -246,13 +246,14 @@ public final class HSSFCell {
     }
 
     /**
-     *  get the cell's number within the row
-     * @return short reperesenting the column number (logical!)
+     * @deprecated (Oct 2008) use {@link #getColumnIndex()}
      */
-
-    public short getCellNum()
-    {
-        return record.getColumn();
+    public short getCellNum() {
+        return (short) getColumnIndex();
+    }
+    
+    public int getColumnIndex() {
+       return record.getColumn() & 0xFFFF;
     }
 
     /**
index e5e7116ae34a672b62f18f9c408fc675ea400d23..97b581724a75ce8c05f3bb25ca658bae53aae7c8 100644 (file)
@@ -55,7 +55,7 @@ final class HSSFEvaluationCell implements EvaluationCell {
                return _cell.getCellType();
        }
        public int getColumnIndex() {
-               return _cell.getCellNum();
+               return _cell.getColumnIndex();
        }
        public int getErrorCellValue() {
                return _cell.getErrorCellValue();
index 47dbc03d4fb3c9bbdeb11ddd051ee51bc207d097..b64d3de6e26f0f6b9e3d1bf3049f62cb57e9c7f9 100644 (file)
@@ -149,7 +149,7 @@ public final class HSSFRow implements Comparable {
     }
     private void removeCell(HSSFCell cell, boolean alsoRemoveRecords) {
         
-        short column=cell.getCellNum();
+        int column=cell.getColumnIndex();
         if(column < 0) {
             throw new RuntimeException("Negative cell indexes not allowed");
         }
@@ -163,10 +163,10 @@ public final class HSSFRow implements Comparable {
             sheet.getSheet().removeValueRecord(getRowNum(), cval);
         }
         
-        if (cell.getCellNum()+1 == row.getLastCol()) {
+        if (cell.getColumnIndex()+1 == row.getLastCol()) {
             row.setLastCol((short) (findLastCell(row.getLastCol())+1));
         }
-        if (cell.getCellNum() == row.getFirstCol()) {
+        if (cell.getColumnIndex() == row.getFirstCol()) {
             row.setFirstCol(findFirstCell(row.getFirstCol()));
         }
     }
@@ -246,7 +246,7 @@ public final class HSSFRow implements Comparable {
         }
         
         // 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");
         }
         
@@ -262,7 +262,7 @@ public final class HSSFRow implements Comparable {
      */
     private void addCell(HSSFCell cell) {
 
-        short column=cell.getCellNum();
+        int column=cell.getColumnIndex();
         // re-allocate cells array as required.
         if(column>=cells.length) {
             HSSFCell[] oldCells=cells;
@@ -277,7 +277,7 @@ public final class HSSFRow implements Comparable {
         
         // fix up firstCol and lastCol indexes
         if (row.getFirstCol() == -1 || column < row.getFirstCol()) {
-            row.setFirstCol(column);
+            row.setFirstCol((short)column);
         }
         
         if (row.getLastCol() == -1 || column >= row.getLastCol()) {
index c869bd4b23641b021066c22b81fa71d48ad9a273..1fbf0ce9422ac519148d6093d094f1bfae52a919 100644 (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();
-               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(" {=").append(c.getCellFormula()).append("}");
                return sb.toString();
index 84a9417fa6ec729193102408d299ebdf020926e2..a5d156e4ccbe855c1acb6a828a5fae57504b46f6 100644 (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) {
 
                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(" {=").append(c.getCellFormula()).append("}");
 
index e2e3234fca1fff2667bae15de587c649ebbc0222..31a8a7dfb53f58c7fa48b81cdbe6a3196f324818 100644 (file)
@@ -66,7 +66,7 @@ public final class TestBug42464 extends TestCase {
                        FormulaRecord r = record.getFormulaRecord();
                        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
                                System.out.print(cellRef);
                                System.out.println(" - has " + ptgs.length + " ptgs:");
index fdaf1d04d4a33ea9247c7c39905a940a6dd22368..08a700466c9acac8913e2c66d466653a2c85d81f 100644 (file)
@@ -617,7 +617,7 @@ public final class TestBugs extends TestCase {
             int cellNum = 0;
             for (Iterator it2 = row.cellIterator(); it2.hasNext(); cellNum++) {
                 HSSFCell cell = (HSSFCell)it2.next();
-                assertEquals(cellNum, cell.getCellNum());
+                assertEquals(cellNum, cell.getColumnIndex());
             }
         }
     }
index b26f8717d9a594fc1cf15213fc3fdd7444a1033c..b0bb2b097d58d4805b561d93da7ac25029c2384f 100644 (file)
@@ -114,7 +114,7 @@ public final class TestHSSFComment extends TestCase {
              assertFalse("cells in the second column have not empyy notes", 
                      "".equals(comment.getString().getString()));
              assertEquals(rownum, comment.getRow());
-             assertEquals(cell.getCellNum(), comment.getColumn());
+             assertEquals(cell.getColumnIndex(), comment.getColumn());
          }
      }
 
index d11e8856eae6059114974aced953ef3f2cbbe777..8e7864fad2a61c9311f528a17ec7f87498488614 100644 (file)
@@ -20,7 +20,6 @@ package org.apache.poi.hssf.usermodel;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.hssf.usermodel.HSSFRow.MissingCellPolicy;
 
 /**
  * Test HSSFRow is okay.
@@ -152,7 +151,7 @@ public final class TestHSSFRow extends TestCase {
         assertNull(row.getCell(1));
         assertNotNull(row.getCell(5));
 
-        assertEquals(5, cellB2.getCellNum());
+        assertEquals(5, cellB2.getColumnIndex());
         assertEquals(2, row.getFirstCellNum());
         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());
         
         // Check created ones get the right column
-        assertEquals((short)0, row.getCell(0, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
-        assertEquals((short)1, row.getCell(1, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
-        assertEquals((short)2, row.getCell(2, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
-        assertEquals((short)3, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
-        assertEquals((short)4, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
-        assertEquals((short)5, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
+        assertEquals(0, row.getCell(0, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
+        assertEquals(1, row.getCell(1, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
+        assertEquals(2, row.getCell(2, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
+        assertEquals(3, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
+        assertEquals(4, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
+        assertEquals(5, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
         
         
         // Now change the cell policy on the workbook, check