poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1757235 - in /poi/trunk/src: java/org/apache/poi/ss/usermodel/Cell.java testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
Date Mon, 22 Aug 2016 17:57:46 GMT
Author: onealj
Date: Mon Aug 22 17:57:45 2016
New Revision: 1757235

URL: http://svn.apache.org/viewvc?rev=1757235&view=rev
Log:
bug 59791: improve Cell.CELL_TYPE_* backwards compatibility

Modified:
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java?rev=1757235&r1=1757234&r2=1757235&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java Mon Aug 22 17:57:45 2016
@@ -46,7 +46,7 @@ public interface Cell {
      * @see #getCellType()
      * @deprecated POI 3.15 beta 3. Use {@link CellType#NUMERIC} instead.
      */
-    CellType CELL_TYPE_NUMERIC = CellType.NUMERIC;
+    int CELL_TYPE_NUMERIC = 0; //CellType.NUMERIC.getCode();
 
     /**
      * String Cell type (1)
@@ -54,7 +54,7 @@ public interface Cell {
      * @see #getCellType()
      * @deprecated POI 3.15 beta 3. Use {@link CellType#STRING} instead.
      */
-    CellType CELL_TYPE_STRING = CellType.STRING;
+    int CELL_TYPE_STRING = 1; //CellType.STRING.getCode();
 
     /**
      * Formula Cell type (2)
@@ -62,7 +62,7 @@ public interface Cell {
      * @see #getCellType()
      * @deprecated POI 3.15 beta 3. Use {@link CellType#FORMULA} instead.
      */
-    CellType CELL_TYPE_FORMULA = CellType.FORMULA;
+    int CELL_TYPE_FORMULA = 2; //CellType.FORMULA.getCode();
 
     /**
      * Blank Cell type (3)
@@ -70,7 +70,7 @@ public interface Cell {
      * @see #getCellType()
      * @deprecated POI 3.15 beta 3. Use {@link CellType#BLANK} instead.
      */
-    CellType CELL_TYPE_BLANK = CellType.BLANK;
+    int CELL_TYPE_BLANK = 3; //CellType.BLANK.getCode();
 
     /**
      * Boolean Cell type (4)
@@ -78,7 +78,7 @@ public interface Cell {
      * @see #getCellType()
      * @deprecated POI 3.15 beta 3. Use {@link CellType#BOOLEAN} instead.
      */
-    CellType CELL_TYPE_BOOLEAN = CellType.BOOLEAN;
+    int CELL_TYPE_BOOLEAN = 4; //CellType.BOOLEAN.getCode();
 
     /**
      * Error Cell type (5)
@@ -86,7 +86,7 @@ public interface Cell {
      * @see #getCellType()
      * @deprecated POI 3.15 beta 3. Use {@link CellType#ERROR} instead.
      */
-    CellType CELL_TYPE_ERROR = CellType.ERROR;
+    int CELL_TYPE_ERROR = 5; //CellType.ERROR.getCode();
 
     /**
      * Returns column index of this cell

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java?rev=1757235&r1=1757234&r2=1757235&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
Mon Aug 22 17:57:45 2016
@@ -136,45 +136,45 @@ public final class TestHSSFConditionalFo
         Row row = sheet.createRow(0);
 
         Cell cell0 = row.createCell(0);
-        cell0.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC);
+        cell0.setCellType(CellType.NUMERIC);
         cell0.setCellValue(100);
 
         Cell cell1 = row.createCell(1);
-        cell1.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC);
+        cell1.setCellType(CellType.NUMERIC);
         cell1.setCellValue(120);
 
         Cell cell2 = row.createCell(2);
-        cell2.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC);
+        cell2.setCellType(CellType.NUMERIC);
         cell2.setCellValue(130);
 
         // row 1
         row = sheet.createRow(1);
 
         cell0 = row.createCell(0);
-        cell0.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC);
+        cell0.setCellType(CellType.NUMERIC);
         cell0.setCellValue(200);
 
         cell1 = row.createCell(1);
-        cell1.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC);
+        cell1.setCellType(CellType.NUMERIC);
         cell1.setCellValue(220);
 
         cell2 = row.createCell(2);
-        cell2.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC);
+        cell2.setCellType(CellType.NUMERIC);
         cell2.setCellValue(230);
 
         // row 2
         row = sheet.createRow(2);
 
         cell0 = row.createCell(0);
-        cell0.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC);
+        cell0.setCellType(CellType.NUMERIC);
         cell0.setCellValue(300);
 
         cell1 = row.createCell(1);
-        cell1.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC);
+        cell1.setCellType(CellType.NUMERIC);
         cell1.setCellValue(320);
 
         cell2 = row.createCell(2);
-        cell2.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC);
+        cell2.setCellType(CellType.NUMERIC);
         cell2.setCellValue(330);
 
         // Create conditional formatting, CELL1 should be yellow if CELL0 is not blank.

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java?rev=1757235&r1=1757234&r2=1757235&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java Mon Aug 22 17:57:45
2016
@@ -1015,4 +1015,34 @@ public abstract class BaseTestCell {
 
         wb.close();
     }
+
+    @Test
+    public void primitiveToEnumReplacementDoesNotBreakBackwardsCompatibility() {
+        // bug 59836
+        // until we have changes POI from working on primitives (int) to enums,
+        // we should make sure we minimize backwards compatibility breakages.
+        // This method tests the old way of working with cell types, alignment, etc.
+        Workbook wb = _testDataProvider.createWorkbook();
+        Sheet sheet = wb.createSheet();
+        Row row = sheet.createRow(0);
+        Cell cell = row.createCell(0);
+
+        // Cell.CELL_TYPE_* -> CellType.*
+        cell.setCellValue(5.0);
+        assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+        assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); // make sure old way and
new way are compatible
+
+        // make sure switch(int|Enum) still works. Cases must be statically resolvable in
Java 6 ("constant expression required")
+        switch(cell.getCellType()) {
+            case Cell.CELL_TYPE_NUMERIC:
+                // expected
+                break;
+            case Cell.CELL_TYPE_STRING:
+            case Cell.CELL_TYPE_ERROR:
+            case Cell.CELL_TYPE_FORMULA:
+            case Cell.CELL_TYPE_BLANK:
+            default:
+                fail("unexpected cell type: " + cell.getCellType());
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message