You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2016/07/04 09:45:47 UTC

svn commit: r1751237 [1/4] - in /poi/trunk/src: examples/src/org/apache/poi/hssf/usermodel/examples/ examples/src/org/apache/poi/hssf/view/ examples/src/org/apache/poi/ss/examples/ examples/src/org/apache/poi/ss/examples/html/ java/org/apache/poi/hssf/...

Author: onealj
Date: Mon Jul  4 09:45:46 2016
New Revision: 1751237

URL: http://svn.apache.org/viewvc?rev=1751237&view=rev
Log:
bug 59791: convert Cell Type to an enum

Added:
    poi/trunk/src/java/org/apache/poi/ss/usermodel/CellType.java   (with props)
Modified:
    poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
    poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java
    poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java
    poi/trunk/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java
    poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java
    poi/trunk/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java
    poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
    poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
    poi/trunk/src/java/org/apache/poi/ss/format/CellFormat.java
    poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationCell.java
    poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
    poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java
    poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluator.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/CellValue.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaError.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Row.java
    poi/trunk/src/java/org/apache/poi/ss/util/SheetUtil.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/ss/format/TestCellFormatPart.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/AbstractExcelConverter.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java Mon Jul  4 09:45:46 2016
@@ -187,15 +187,15 @@ public final class HSSFReadWrite {
 
 							switch (cell.getCellType()) {
 
-								case HSSFCell.CELL_TYPE_FORMULA:
+								case FORMULA:
 									value = "FORMULA value=" + cell.getCellFormula();
 									break;
 
-								case HSSFCell.CELL_TYPE_NUMERIC:
+								case NUMERIC:
 									value = "NUMERIC value=" + cell.getNumericCellValue();
 									break;
 
-								case HSSFCell.CELL_TYPE_STRING:
+								case STRING:
 									value = "STRING value=" + cell.getStringCellValue();
 									break;
 

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java Mon Jul  4 09:45:46 2016
@@ -152,23 +152,23 @@ public class SVTableCellEditor extends A
 
       //Set the value that is rendered for the cell
       switch (cell.getCellType()) {
-        case HSSFCell.CELL_TYPE_BLANK:
+        case BLANK:
           editor.setText("");
           break;
-        case HSSFCell.CELL_TYPE_BOOLEAN:
+        case BOOLEAN:
           if (cell.getBooleanCellValue()) {
             editor.setText("true");
           } else {
             editor.setText("false");
           }
           break;
-        case HSSFCell.CELL_TYPE_NUMERIC:
+        case NUMERIC:
           editor.setText(Double.toString(cell.getNumericCellValue()));
           break;
-        case HSSFCell.CELL_TYPE_STRING:
+        case STRING:
           editor.setText(cell.getRichStringCellValue().getString());
           break;
-        case HSSFCell.CELL_TYPE_FORMULA:
+        case FORMULA:
         default:
           editor.setText("?");
       }

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java Mon Jul  4 09:45:46 2016
@@ -166,17 +166,17 @@ public class SVTableCellRenderer extends
 
             //Set the value that is rendered for the cell
             switch (c.getCellType()) {
-              case HSSFCell.CELL_TYPE_BLANK:
+              case BLANK:
                 setValue("");
               break;
-              case HSSFCell.CELL_TYPE_BOOLEAN:
+              case BOOLEAN:
                 if (c.getBooleanCellValue()) {
                   setValue("true");
                 } else {
                   setValue("false");
                 }
               break;
-              case HSSFCell.CELL_TYPE_NUMERIC:
+              case NUMERIC:
                 short format = s.getDataFormat();
                 double numericValue = c.getNumericCellValue();
                 if (cellFormatter.useRedColor(format, numericValue))
@@ -184,10 +184,10 @@ public class SVTableCellRenderer extends
                 else setForeground(null);
                 setValue(cellFormatter.format(format, c.getNumericCellValue()));
               break;
-              case HSSFCell.CELL_TYPE_STRING:
+              case STRING:
                 setValue(c.getRichStringCellValue().getString());
               break;
-              case HSSFCell.CELL_TYPE_FORMULA:
+              case FORMULA:
               default:
                 setValue("?");
             }

Modified: poi/trunk/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java Mon Jul  4 09:45:46 2016
@@ -25,6 +25,7 @@ import java.util.Locale;
 
 import org.apache.poi.ss.usermodel.BorderStyle;
 import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.Color;
 import org.apache.poi.ss.usermodel.DateUtil;
 import org.apache.poi.ss.usermodel.Row;
@@ -178,25 +179,28 @@ public class ExcelComparator {
 
     private void compareDataInCell(Locator loc1, Locator loc2) {
         if (isCellTypeMatches(loc1, loc2)) {
-            switch(loc1.cell.getCellType()) {
-            case Cell.CELL_TYPE_BLANK:
-            case Cell.CELL_TYPE_STRING:
-            case Cell.CELL_TYPE_ERROR:
-                isCellContentMatches(loc1,loc2);
-                break;
-            case Cell.CELL_TYPE_BOOLEAN:
-                isCellContentMatchesForBoolean(loc1,loc2);
-                break;
-            case Cell.CELL_TYPE_FORMULA:
-                isCellContentMatchesForFormula(loc1,loc2);
-                break;
-            case Cell.CELL_TYPE_NUMERIC:
-                if (DateUtil.isCellDateFormatted(loc1.cell)) {
-                    isCellContentMatchesForDate(loc1,loc2);
-                } else {
-                    isCellContentMatchesForNumeric(loc1,loc2);
-                }
-                break;
+            final CellType loc1cellType = loc1.cell.getCellType();
+            switch(loc1cellType) {
+                case BLANK:
+                case STRING:
+                case ERROR:
+                    isCellContentMatches(loc1,loc2);
+                    break;
+                case BOOLEAN:
+                    isCellContentMatchesForBoolean(loc1,loc2);
+                    break;
+                case FORMULA:
+                    isCellContentMatchesForFormula(loc1,loc2);
+                    break;
+                case NUMERIC:
+                    if (DateUtil.isCellDateFormatted(loc1.cell)) {
+                        isCellContentMatchesForDate(loc1,loc2);
+                    } else {
+                        isCellContentMatchesForNumeric(loc1,loc2);
+                    }
+                    break;
+                default:
+                    throw new IllegalStateException("Unexpected cell type: " + loc1cellType);
             }
         }
 
@@ -577,13 +581,12 @@ public class ExcelComparator {
      * Checks if cell type matches.
      */
     private boolean isCellTypeMatches(Locator loc1, Locator loc2) {
-        int type1 = loc1.cell.getCellType();
-        int type2 = loc2.cell.getCellType();
+        CellType type1 = loc1.cell.getCellType();
+        CellType type2 = loc2.cell.getCellType();
         if (type1 == type2) return true;
         addMessage(loc1, loc2,
             "Cell Data-Type does not Match in :: ",
-            Integer.toString(type1),
-            Integer.toString(type2)
+            type1.name(), type2.name()
         );
         return false;
     }

Modified: poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java Mon Jul  4 09:45:46 2016
@@ -16,7 +16,6 @@
 ==================================================================== */
 package org.apache.poi.ss.examples.html;
 
-import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFFont;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.format.CellFormat;
@@ -336,9 +335,9 @@ public class ToHtml {
         }
     }
 
-    private static int ultimateCellType(Cell c) {
-        int type = c.getCellType();
-        if (type == Cell.CELL_TYPE_FORMULA)
+    private static CellType ultimateCellType(Cell c) {
+        CellType type = c.getCellType();
+        if (type == CellType.FORMULA)
             type = c.getCachedFormulaResultType();
         return type;
     }
@@ -443,12 +442,12 @@ public class ToHtml {
     private String tagStyle(Cell cell, CellStyle style) {
         if (style.getAlignment() == ALIGN_GENERAL) {
             switch (ultimateCellType(cell)) {
-            case HSSFCell.CELL_TYPE_STRING:
+            case STRING:
                 return "style=\"text-align: left;\"";
-            case HSSFCell.CELL_TYPE_BOOLEAN:
-            case HSSFCell.CELL_TYPE_ERROR:
+            case BOOLEAN:
+            case ERROR:
                 return "style=\"text-align: center;\"";
-            case HSSFCell.CELL_TYPE_NUMERIC:
+            case NUMERIC:
             default:
                 // "right" is the default
                 break;

Modified: poi/trunk/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java Mon Jul  4 09:45:46 2016
@@ -323,42 +323,40 @@ public class ExcelExtractor extends POIO
 						outputContents = _includeBlankCells;
 					} else {
 						switch(cell.getCellType()) {
-							case Cell.CELL_TYPE_STRING:
+							case STRING:
 								text.append(cell.getRichStringCellValue().getString());
 								break;
-							case Cell.CELL_TYPE_NUMERIC:
-								text.append(
-								      _formatter.formatCellValue(cell)
-								);
+							case NUMERIC:
+								text.append(_formatter.formatCellValue(cell));
 								break;
-							case Cell.CELL_TYPE_BOOLEAN:
+							case BOOLEAN:
 								text.append(cell.getBooleanCellValue());
 								break;
-							case Cell.CELL_TYPE_ERROR:
+							case ERROR:
 								text.append(ErrorEval.getText(cell.getErrorCellValue()));
 								break;
-							case Cell.CELL_TYPE_FORMULA:
+							case FORMULA:
 								if(!_shouldEvaluateFormulas) {
 									text.append(cell.getCellFormula());
 								} else {
 									switch(cell.getCachedFormulaResultType()) {
-										case Cell.CELL_TYPE_STRING:
+										case STRING:
 											HSSFRichTextString str = cell.getRichStringCellValue();
 											if(str != null && str.length() > 0) {
 												text.append(str.toString());
 											}
 											break;
-										case Cell.CELL_TYPE_NUMERIC:
+										case NUMERIC:
 											HSSFCellStyle style = cell.getCellStyle();
 											double nVal = cell.getNumericCellValue();
 											short df = style.getDataFormat();
 											String dfs = style.getDataFormatString();
 											text.append(_formatter.formatRawCellContents(nVal, df, dfs));
 											break;
-										case Cell.CELL_TYPE_BOOLEAN:
+										case BOOLEAN:
 											text.append(cell.getBooleanCellValue());
 											break;
-										case Cell.CELL_TYPE_ERROR:
+										case ERROR:
 											text.append(ErrorEval.getText(cell.getErrorCellValue()));
 											break;
 										default:

Modified: poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java Mon Jul  4 09:45:46 2016
@@ -43,7 +43,7 @@ import org.apache.poi.poifs.filesystem.D
 import org.apache.poi.poifs.filesystem.DocumentNode;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.NotOLE2FileException;
-import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.util.IOUtils;
 
 /**
@@ -266,12 +266,12 @@ public class OldExcelExtractor implement
                     // Biff 2 and 5+ share the same SID, due to a bug...
                     if (biffVersion == 5) {
                         FormulaRecord fr = new FormulaRecord(ris);
-                        if (fr.getCachedResultType() == Cell.CELL_TYPE_NUMERIC) {
+                        if (fr.getCachedResultType() == CellType.NUMERIC.getCode()) {
                             handleNumericCell(text, fr.getValue());
                         }
                     } else {
                         OldFormulaRecord fr = new OldFormulaRecord(ris);
-                        if (fr.getCachedResultType() == Cell.CELL_TYPE_NUMERIC) {
+                        if (fr.getCachedResultType() == CellType.NUMERIC.getCode()) {
                             handleNumericCell(text, fr.getValue());
                         }
                     }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java Mon Jul  4 09:45:46 2016
@@ -17,10 +17,10 @@
 
 package org.apache.poi.hssf.record;
 
-import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.ss.formula.Formula;
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.ptg.Ptg;
+import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.HexDump;
@@ -53,6 +53,8 @@ public final class FormulaRecord extends
 		private static final int VARIABLE_DATA_LENGTH = 6;
 		private static final int DATA_INDEX = 2;
 
+		// FIXME: can these be merged with {@link CellType}?
+		// are the numbers specific to the HSSF formula record format or just a poor-man's enum?
 		public static final int STRING = 0;
 		public static final int BOOLEAN = 1;
 		public static final int ERROR_CODE = 2;
@@ -146,10 +148,10 @@ public final class FormulaRecord extends
 		public int getValueType() {
 			int typeCode = getTypeCode();
 			switch (typeCode) {
-				case STRING:	 return HSSFCell.CELL_TYPE_STRING;
-				case BOOLEAN:	return HSSFCell.CELL_TYPE_BOOLEAN;
-				case ERROR_CODE: return HSSFCell.CELL_TYPE_ERROR;
-				case EMPTY:	  return HSSFCell.CELL_TYPE_STRING; // is this correct?
+				case STRING:	 return CellType.STRING.getCode();
+				case BOOLEAN:	return CellType.BOOLEAN.getCode();
+				case ERROR_CODE: return CellType.ERROR.getCode();
+				case EMPTY:	  return CellType.STRING.getCode(); // is this correct?
 			}
 			throw new IllegalStateException("Unexpected type id (" + typeCode + ")");
 		}
@@ -241,7 +243,7 @@ public final class FormulaRecord extends
 
 	public int getCachedResultType() {
 		if (specialCachedValue == null) {
-			return HSSFCell.CELL_TYPE_NUMERIC;
+			return CellType.NUMERIC.getCode();
 		}
 		return specialCachedValue.getValueType();
 	}

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java Mon Jul  4 09:45:46 2016
@@ -21,6 +21,7 @@ import org.apache.poi.hssf.record.Formul
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.ss.formula.Formula;
 import org.apache.poi.ss.formula.ptg.Ptg;
+import org.apache.poi.ss.usermodel.CellType;
 
 /**
  * Formula Record (0x0006 / 0x0206 / 0x0406) - holds a formula in
@@ -63,7 +64,7 @@ public final class OldFormulaRecord exte
 
     public int getCachedResultType() {
         if (specialCachedValue == null) {
-            return HSSFCell.CELL_TYPE_NUMERIC;
+            return CellType.NUMERIC.getCode();
         }
         return specialCachedValue.getValueType();
     }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Mon Jul  4 09:45:46 2016
@@ -44,6 +44,7 @@ import org.apache.poi.ss.formula.ptg.Exp
 import org.apache.poi.ss.formula.ptg.Ptg;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.Comment;
 import org.apache.poi.ss.usermodel.FormulaError;
 import org.apache.poi.ss.usermodel.Hyperlink;
@@ -80,7 +81,7 @@ public class HSSFCell implements Cell {
 
     private final HSSFWorkbook       _book;
     private final HSSFSheet          _sheet;
-    private int                      _cellType;
+    private CellType                 _cellType;
     private HSSFRichTextString       _stringValue;
     private CellValueRecordInterface _record;
     private HSSFComment              _comment;
@@ -89,7 +90,7 @@ public class HSSFCell implements Cell {
      * Creates new Cell - Should only be called by HSSFRow.  This creates a cell
      * from scratch.
      * <p>
-     * When the cell is initially created it is set to CELL_TYPE_BLANK. Cell types
+     * When the cell is initially created it is set to {@link CellType#BLANK}. Cell types
      * can be changed/overwritten by calling setCellValue with the appropriate
      * type as a parameter although conversions from one type to another may be
      * prohibited.
@@ -109,10 +110,10 @@ public class HSSFCell implements Cell {
         _sheet   = sheet;
 
         // Relying on the fact that by default the cellType is set to 0 which
-        // is different to CELL_TYPE_BLANK hence the following method call correctly
+        // is different to {@link CellType#BLANK} hence the following method call correctly
         // creates a new blank cell.
         short xfindex = sheet.getSheet().getXFIndexForColAt(col);
-        setCellType(CELL_TYPE_BLANK, false, row, col,xfindex);
+        setCellType(CellType.BLANK, false, row, col,xfindex);
     }
 
     /**
@@ -142,16 +143,14 @@ public class HSSFCell implements Cell {
      * @param sheet - Sheet record of the sheet containing this cell
      * @param row   - the row of this cell
      * @param col   - the column for this cell
-     * @param type  - CELL_TYPE_NUMERIC, CELL_TYPE_STRING, CELL_TYPE_FORMULA, CELL_TYPE_BLANK,
-     *                CELL_TYPE_BOOLEAN, CELL_TYPE_ERROR
-     *                Type of cell
+     * @param type  - Type of cell
      * @see org.apache.poi.hssf.usermodel.HSSFRow#createCell(int,int)
      */
     protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col,
-                       int type)
+                       CellType type)
     {
         checkBounds(col);
-        _cellType     = -1; // Force 'setCellType' to create a first Record
+        _cellType     = CellType._UNINITIALIZED; // Force 'setCellType' to create a first Record
         _stringValue  = null;
         _book    = book;
         _sheet   = sheet;
@@ -176,14 +175,14 @@ public class HSSFCell implements Cell {
         _sheet  = sheet;
         switch (_cellType)
         {
-            case CELL_TYPE_STRING :
+            case STRING :
                 _stringValue = new HSSFRichTextString(book.getWorkbook(), (LabelSSTRecord ) cval);
                 break;
 
-            case CELL_TYPE_BLANK :
+            case BLANK :
                 break;
 
-            case CELL_TYPE_FORMULA :
+            case FORMULA :
                 _stringValue=new HSSFRichTextString(((FormulaRecordAggregate) cval).getStringValue());
                 break;
 
@@ -196,23 +195,23 @@ public class HSSFCell implements Cell {
     /**
      * used internally -- given a cell value record, figure out its type
      */
-    private static int determineType(CellValueRecordInterface cval) {
+    private static CellType determineType(CellValueRecordInterface cval) {
         if (cval instanceof FormulaRecordAggregate) {
-            return HSSFCell.CELL_TYPE_FORMULA;
+            return CellType.FORMULA;
         }
         // all others are plain BIFF records
         Record record = ( Record ) cval;
         switch (record.getSid()) {
 
-            case NumberRecord.sid :   return HSSFCell.CELL_TYPE_NUMERIC;
-            case BlankRecord.sid :    return HSSFCell.CELL_TYPE_BLANK;
-            case LabelSSTRecord.sid : return HSSFCell.CELL_TYPE_STRING;
+            case NumberRecord.sid :   return CellType.NUMERIC;
+            case BlankRecord.sid :    return CellType.BLANK;
+            case LabelSSTRecord.sid : return CellType.STRING;
             case BoolErrRecord.sid :
                 BoolErrRecord boolErrRecord = ( BoolErrRecord ) record;
 
                 return boolErrRecord.isBoolean()
-                         ? HSSFCell.CELL_TYPE_BOOLEAN
-                         : HSSFCell.CELL_TYPE_ERROR;
+                         ? CellType.BOOLEAN
+                         : CellType.ERROR;
         }
         throw new RuntimeException("Bad cell value rec (" + cval.getClass().getName() + ")");
     }
@@ -255,19 +254,29 @@ public class HSSFCell implements Cell {
         return new CellAddress(this);
     }
     
-
     /**
      * Set the cells type (numeric, formula or string).
      * If the cell currently contains a value, the value will
      *  be converted to match the new type, if possible.
-     * @see #CELL_TYPE_NUMERIC
-     * @see #CELL_TYPE_STRING
-     * @see #CELL_TYPE_FORMULA
-     * @see #CELL_TYPE_BLANK
-     * @see #CELL_TYPE_BOOLEAN
-     * @see #CELL_TYPE_ERROR
+     * @see CellType#NUMERIC
+     * @see CellType#STRING
+     * @see CellType#FORMULA
+     * @see CellType#BLANK
+     * @see CellType#BOOLEAN
+     * @see CellType#ERROR
+     * @deprecated POI 3.15 beta 3. Use {@link #setCellType(CellType)} instead.
      */
+    @Override
     public void setCellType(int cellType) {
+        setCellType(CellType.forInt(cellType));
+    }
+    /**
+     * Set the cells type (numeric, formula or string).
+     * If the cell currently contains a value, the value will
+     *  be converted to match the new type, if possible.
+     */
+    @Override
+    public void setCellType(CellType cellType) {
         notifyFormulaChanging();
         if(isPartOfArrayFormulaGroup()){
             notifyArrayFormulaChanging();
@@ -287,17 +296,12 @@ public class HSSFCell implements Cell {
      *
      */
 
-    private void setCellType(int cellType, boolean setValue, int row,short col, short styleIndex)
+    private void setCellType(CellType cellType, boolean setValue, int row,short col, short styleIndex)
     {
-
-        if (cellType > CELL_TYPE_ERROR)
-        {
-            throw new RuntimeException("I have no idea what type that is!");
-        }
         switch (cellType)
         {
 
-            case CELL_TYPE_FORMULA :
+            case FORMULA :
                 FormulaRecordAggregate frec;
 
                 if (cellType != _cellType) {
@@ -315,7 +319,7 @@ public class HSSFCell implements Cell {
                 _record = frec;
                 break;
 
-            case CELL_TYPE_NUMERIC :
+            case NUMERIC :
                 NumberRecord nrec = null;
 
                 if (cellType != _cellType)
@@ -336,7 +340,7 @@ public class HSSFCell implements Cell {
                 _record = nrec;
                 break;
 
-            case CELL_TYPE_STRING :
+            case STRING :
                 LabelSSTRecord lrec;
 
                 if (cellType == _cellType) {
@@ -352,7 +356,7 @@ public class HSSFCell implements Cell {
                     if(str == null) {
                         // bug 55668: don't try to store null-string when formula
                         // results in empty/null value
-                        setCellType(CELL_TYPE_BLANK, false, row, col, styleIndex);
+                        setCellType(CellType.BLANK, false, row, col, styleIndex);
                         return;
                     } else {
                         int sstIndex = _book.getWorkbook().addSSTString(new UnicodeString(str));
@@ -365,7 +369,7 @@ public class HSSFCell implements Cell {
                 _record = lrec;
                 break;
 
-            case CELL_TYPE_BLANK :
+            case BLANK :
                 BlankRecord brec = null;
 
                 if (cellType != _cellType)
@@ -384,7 +388,7 @@ public class HSSFCell implements Cell {
                 _record = brec;
                 break;
 
-            case CELL_TYPE_BOOLEAN :
+            case BOOLEAN :
                 BoolErrRecord boolRec = null;
 
                 if (cellType != _cellType)
@@ -405,7 +409,7 @@ public class HSSFCell implements Cell {
                 _record = boolRec;
                 break;
 
-            case CELL_TYPE_ERROR :
+            case ERROR :
                 BoolErrRecord errRec = null;
 
                 if (cellType != _cellType)
@@ -429,7 +433,7 @@ public class HSSFCell implements Cell {
                 throw new IllegalStateException("Invalid cell type: " + cellType);
         }
         if (cellType != _cellType &&
-            _cellType!=-1 )  // Special Value to indicate an uninitialized Cell
+            _cellType != CellType._UNINITIALIZED )  // Special Value to indicate an uninitialized Cell
         {
             _sheet.getSheet().replaceValueRecord(_record);
         }
@@ -438,14 +442,9 @@ public class HSSFCell implements Cell {
 
     /**
      * get the cells type (numeric, formula or string)
-     * @see #CELL_TYPE_STRING
-     * @see #CELL_TYPE_NUMERIC
-     * @see #CELL_TYPE_FORMULA
-     * @see #CELL_TYPE_BOOLEAN
-     * @see #CELL_TYPE_ERROR
      */
-
-    public int getCellType()
+    @Override
+    public CellType getCellType()
     {
         return _cellType;
     }
@@ -458,6 +457,7 @@ public class HSSFCell implements Cell {
      *        will change the cell to a numeric cell and set its value.
      */
     @SuppressWarnings("fallthrough")
+    @Override
     public void setCellValue(double value) {
         if(Double.isInfinite(value)) {
             // Excel does not support positive/negative infinities,
@@ -474,12 +474,12 @@ public class HSSFCell implements Cell {
 
             switch (_cellType) {
                 default:
-                    setCellType(CELL_TYPE_NUMERIC, false, row, col, styleIndex);
+                    setCellType(CellType.NUMERIC, false, row, col, styleIndex);
                     // fall through
-                case CELL_TYPE_NUMERIC:
+                case NUMERIC:
                     (( NumberRecord ) _record).setValue(value);
                     break;
-                case CELL_TYPE_FORMULA:
+                case FORMULA:
                     ((FormulaRecordAggregate)_record).setCachedDoubleResult(value);
                     break;
             }
@@ -550,7 +550,7 @@ public class HSSFCell implements Cell {
         if (value == null)
         {
             notifyFormulaChanging();
-            setCellType(CELL_TYPE_BLANK, false, row, col, styleIndex);
+            setCellType(CellType.BLANK, false, row, col, styleIndex);
             return;
         }
 
@@ -558,7 +558,7 @@ public class HSSFCell implements Cell {
             throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters");
         }
 
-        if (_cellType == CELL_TYPE_FORMULA) {
+        if (_cellType == CellType.FORMULA) {
             // Set the 'pre-evaluated result' for the formula
             // note - formulas do not preserve text formatting.
             FormulaRecordAggregate fr = (FormulaRecordAggregate) _record;
@@ -573,8 +573,8 @@ public class HSSFCell implements Cell {
         // If we get here, we're not dealing with a formula,
         //  so handle things as a normal rich text cell
 
-        if (_cellType != CELL_TYPE_STRING) {
-            setCellType(CELL_TYPE_STRING, false, row, col, styleIndex);
+        if (_cellType != CellType.STRING) {
+            setCellType(CellType.STRING, false, row, col, styleIndex);
         }
         int index = 0;
 
@@ -598,12 +598,12 @@ public class HSSFCell implements Cell {
 
         if (formula==null) {
             notifyFormulaChanging();
-            setCellType(CELL_TYPE_BLANK, false, row, col, styleIndex);
+            setCellType(CellType.BLANK, false, row, col, styleIndex);
             return;
         }
         int sheetIndex = _book.getSheetIndex(_sheet);
         Ptg[] ptgs = HSSFFormulaParser.parse(formula, _book, FormulaType.CELL, sheetIndex);
-        setCellType(CELL_TYPE_FORMULA, false, row, col, styleIndex);
+        setCellType(CellType.FORMULA, false, row, col, styleIndex);
         FormulaRecordAggregate agg = (FormulaRecordAggregate) _record;
         FormulaRecord frec = agg.getFormulaRecord();
         frec.setOptions((short) 2);
@@ -627,34 +627,18 @@ public class HSSFCell implements Cell {
 
     public String getCellFormula() {
         if (!(_record instanceof FormulaRecordAggregate)) {
-            throw typeMismatch(CELL_TYPE_FORMULA, _cellType, true);
+            throw typeMismatch(CellType.FORMULA, _cellType, true);
         }
         return HSSFFormulaParser.toFormulaString(_book, ((FormulaRecordAggregate)_record).getFormulaTokens());
     }
 
-    /**
-     * Used to help format error messages
-     */
-    private static String getCellTypeName(int cellTypeCode) {
-        switch (cellTypeCode) {
-            case CELL_TYPE_BLANK:   return "blank";
-            case CELL_TYPE_STRING:  return "text";
-            case CELL_TYPE_BOOLEAN: return "boolean";
-            case CELL_TYPE_ERROR:   return "error";
-            case CELL_TYPE_NUMERIC: return "numeric";
-            case CELL_TYPE_FORMULA: return "formula";
-        }
-        return "#unknown cell type (" + cellTypeCode + ")#";
-    }
-
-    private static RuntimeException typeMismatch(int expectedTypeCode, int actualTypeCode, boolean isFormulaCell) {
-        String msg = "Cannot get a "
-            + getCellTypeName(expectedTypeCode) + " value from a "
-            + getCellTypeName(actualTypeCode) + " " + (isFormulaCell ? "formula " : "") + "cell";
+    private static RuntimeException typeMismatch(CellType expectedTypeCode, CellType actualTypeCode, boolean isFormulaCell) {
+        String msg = "Cannot get a " + expectedTypeCode + " value from a " + actualTypeCode
+            + " " + (isFormulaCell ? "formula " : "") + "cell";
         return new IllegalStateException(msg);
     }
-    private static void checkFormulaCachedValueType(int expectedTypeCode, FormulaRecord fr) {
-        int cachedValueType = fr.getCachedResultType();
+    private static void checkFormulaCachedValueType(CellType expectedTypeCode, FormulaRecord fr) {
+        CellType cachedValueType = CellType.forInt(fr.getCachedResultType());
         if (cachedValueType != expectedTypeCode) {
             throw typeMismatch(expectedTypeCode, cachedValueType, true);
         }
@@ -671,17 +655,17 @@ public class HSSFCell implements Cell {
     public double getNumericCellValue() {
 
         switch(_cellType) {
-            case CELL_TYPE_BLANK:
+            case BLANK:
                 return 0.0;
-            case CELL_TYPE_NUMERIC:
+            case NUMERIC:
                 return ((NumberRecord)_record).getValue();
             default:
-                throw typeMismatch(CELL_TYPE_NUMERIC, _cellType, false);
-            case CELL_TYPE_FORMULA:
+                throw typeMismatch(CellType.NUMERIC, _cellType, false);
+            case FORMULA:
                 break;
         }
         FormulaRecord fr = ((FormulaRecordAggregate)_record).getFormulaRecord();
-        checkFormulaCachedValueType(CELL_TYPE_NUMERIC, fr);
+        checkFormulaCachedValueType(CellType.NUMERIC, fr);
         return fr.getValue();
     }
 
@@ -694,7 +678,7 @@ public class HSSFCell implements Cell {
      */
     public Date getDateCellValue() {
 
-        if (_cellType == CELL_TYPE_BLANK) {
+        if (_cellType == CellType.BLANK) {
             return null;
         }
         double value = getNumericCellValue();
@@ -723,17 +707,17 @@ public class HSSFCell implements Cell {
     public HSSFRichTextString getRichStringCellValue() {
 
         switch(_cellType) {
-            case CELL_TYPE_BLANK:
+            case BLANK:
                 return new HSSFRichTextString("");
-            case CELL_TYPE_STRING:
+            case STRING:
                 return _stringValue;
             default:
-                throw typeMismatch(CELL_TYPE_STRING, _cellType, false);
-            case CELL_TYPE_FORMULA:
+                throw typeMismatch(CellType.STRING, _cellType, false);
+            case FORMULA:
                 break;
         }
         FormulaRecordAggregate fra = ((FormulaRecordAggregate)_record);
-        checkFormulaCachedValueType(CELL_TYPE_STRING, fra.getFormulaRecord());
+        checkFormulaCachedValueType(CellType.STRING, fra.getFormulaRecord());
         String strVal = fra.getStringValue();
         return new HSSFRichTextString(strVal == null ? "" : strVal);
     }
@@ -753,12 +737,12 @@ public class HSSFCell implements Cell {
 
         switch (_cellType) {
             default:
-                setCellType(CELL_TYPE_BOOLEAN, false, row, col, styleIndex);
+                setCellType(CellType.BOOLEAN, false, row, col, styleIndex);
                 // fall through
-            case CELL_TYPE_BOOLEAN:
+            case BOOLEAN:
                 (( BoolErrRecord ) _record).setValue(value);
                 break;
-            case CELL_TYPE_FORMULA:
+            case FORMULA:
                 ((FormulaRecordAggregate)_record).setCachedBooleanResult(value);
                 break;
         }
@@ -793,12 +777,12 @@ public class HSSFCell implements Cell {
         short styleIndex=_record.getXFIndex();
         switch (_cellType) {
             default:
-                setCellType(CELL_TYPE_ERROR, false, row, col, styleIndex);
+                setCellType(CellType.ERROR, false, row, col, styleIndex);
                 // fall through
-            case CELL_TYPE_ERROR:
+            case ERROR:
                 (( BoolErrRecord ) _record).setValue(error);
                 break;
-            case CELL_TYPE_FORMULA:
+            case FORMULA:
                 ((FormulaRecordAggregate)_record).setCachedErrorResult(error.getCode());
                 break;
         }
@@ -816,24 +800,24 @@ public class HSSFCell implements Cell {
     private boolean convertCellValueToBoolean() {
 
         switch (_cellType) {
-            case CELL_TYPE_BOOLEAN:
+            case BOOLEAN:
                 return (( BoolErrRecord ) _record).getBooleanValue();
-            case CELL_TYPE_STRING:
+            case STRING:
                 int sstIndex = ((LabelSSTRecord)_record).getSSTIndex();
                 String text = _book.getWorkbook().getSSTString(sstIndex).getString();
                 return Boolean.valueOf(text).booleanValue();
-            case CELL_TYPE_NUMERIC:
+            case NUMERIC:
                 return ((NumberRecord)_record).getValue() != 0;
 
-            case CELL_TYPE_FORMULA:
+            case FORMULA:
                 // use cached formula result if it's the right type:
                 FormulaRecord fr = ((FormulaRecordAggregate)_record).getFormulaRecord();
-                checkFormulaCachedValueType(CELL_TYPE_BOOLEAN, fr);
+                checkFormulaCachedValueType(CellType.BOOLEAN, fr);
                 return fr.getCachedBooleanValue();
             // Other cases convert to false
             // These choices are not well justified.
-            case CELL_TYPE_ERROR:
-            case CELL_TYPE_BLANK:
+            case ERROR:
+            case BLANK:
                 return false;
         }
         throw new RuntimeException("Unexpected cell type (" + _cellType + ")");
@@ -841,18 +825,18 @@ public class HSSFCell implements Cell {
     private String convertCellValueToString() {
 
         switch (_cellType) {
-            case CELL_TYPE_BLANK:
+            case BLANK:
                 return "";
-            case CELL_TYPE_BOOLEAN:
+            case BOOLEAN:
                 return ((BoolErrRecord) _record).getBooleanValue() ? "TRUE" : "FALSE";
-            case CELL_TYPE_STRING:
+            case STRING:
                 int sstIndex = ((LabelSSTRecord)_record).getSSTIndex();
                 return _book.getWorkbook().getSSTString(sstIndex).getString();
-            case CELL_TYPE_NUMERIC:
+            case NUMERIC:
                 return NumberToTextConverter.toText(((NumberRecord)_record).getValue());
-            case CELL_TYPE_ERROR:
+            case ERROR:
                    return FormulaError.forInt(((BoolErrRecord)_record).getErrorValue()).getString();
-            case CELL_TYPE_FORMULA:
+            case FORMULA:
                 // should really evaluate, but HSSFCell can't call HSSFFormulaEvaluator
                 // just use cached formula result instead
                 break;
@@ -861,37 +845,40 @@ public class HSSFCell implements Cell {
         }
         FormulaRecordAggregate fra = ((FormulaRecordAggregate)_record);
         FormulaRecord fr = fra.getFormulaRecord();
-        switch (fr.getCachedResultType()) {
-            case CELL_TYPE_BOOLEAN:
+        switch (CellType.forInt(fr.getCachedResultType())) {
+            case BOOLEAN:
                 return fr.getCachedBooleanValue() ? "TRUE" : "FALSE";
-            case CELL_TYPE_STRING:
+            case STRING:
                 return fra.getStringValue();
-            case CELL_TYPE_NUMERIC:
+            case NUMERIC:
                 return NumberToTextConverter.toText(fr.getValue());
-            case CELL_TYPE_ERROR:
-                   return FormulaError.forInt(fr.getCachedErrorValue()).getString();
+            case ERROR:
+                return FormulaError.forInt(fr.getCachedErrorValue()).getString();
+            default:
+                throw new IllegalStateException("Unexpected formula result type (" + _cellType + ")");
         }
-        throw new IllegalStateException("Unexpected formula result type (" + _cellType + ")");
+        
     }
 
     /**
      * get the value of the cell as a boolean.  For strings, numbers, and errors, we throw an exception.
      * For blank cells we return a false.
      */
+    @Override
     public boolean getBooleanCellValue() {
 
         switch(_cellType) {
-            case CELL_TYPE_BLANK:
+            case BLANK:
                 return false;
-            case CELL_TYPE_BOOLEAN:
+            case BOOLEAN:
                 return (( BoolErrRecord ) _record).getBooleanValue();
-            default:
-                throw typeMismatch(CELL_TYPE_BOOLEAN, _cellType, false);
-            case CELL_TYPE_FORMULA:
+            case FORMULA:
                 break;
+            default:
+                throw typeMismatch(CellType.BOOLEAN, _cellType, false);
         }
         FormulaRecord fr = ((FormulaRecordAggregate)_record).getFormulaRecord();
-        checkFormulaCachedValueType(CELL_TYPE_BOOLEAN, fr);
+        checkFormulaCachedValueType(CellType.BOOLEAN, fr);
         return fr.getCachedBooleanValue();
     }
 
@@ -899,17 +886,18 @@ public class HSSFCell implements Cell {
      * get the value of the cell as an error code.  For strings, numbers, and booleans, we throw an exception.
      * For blank cells we return a 0.
      */
+    @Override
     public byte getErrorCellValue() {
         switch(_cellType) {
-            case CELL_TYPE_ERROR:
+            case ERROR:
                 return (( BoolErrRecord ) _record).getErrorValue();
-            default:
-                throw typeMismatch(CELL_TYPE_ERROR, _cellType, false);
-            case CELL_TYPE_FORMULA:
+            case FORMULA:
                 break;
+            default:
+                throw typeMismatch(CellType.ERROR, _cellType, false);
         }
         FormulaRecord fr = ((FormulaRecordAggregate)_record).getFormulaRecord();
-        checkFormulaCachedValueType(CELL_TYPE_ERROR, fr);
+        checkFormulaCachedValueType(CellType.ERROR, fr);
         return (byte) fr.getCachedErrorValue();
     }
 
@@ -1008,15 +996,15 @@ public class HSSFCell implements Cell {
      */
     public String toString() {
         switch (getCellType()) {
-            case CELL_TYPE_BLANK:
+            case BLANK:
                 return "";
-            case CELL_TYPE_BOOLEAN:
+            case BOOLEAN:
                 return getBooleanCellValue()?"TRUE":"FALSE";
-            case CELL_TYPE_ERROR:
+            case ERROR:
                 return ErrorEval.getText((( BoolErrRecord ) _record).getErrorValue());
-            case CELL_TYPE_FORMULA:
+            case FORMULA:
                 return getCellFormula();
-            case CELL_TYPE_NUMERIC:
+            case NUMERIC:
                 //TODO apply the dataformat for this cell
                 if (HSSFDateUtil.isCellDateFormatted(this)) {
                     SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", LocaleUtil.getUserLocale());
@@ -1024,7 +1012,7 @@ public class HSSFCell implements Cell {
                     return sdf.format(getDateCellValue());
                 }
 				return  String.valueOf(getNumericCellValue());
-            case CELL_TYPE_STRING:
+            case STRING:
                 return getStringCellValue();
             default:
                 return "Unknown Cell Type: " + getCellType();
@@ -1142,22 +1130,23 @@ public class HSSFCell implements Cell {
 
     /**
      * Only valid for formula cells
-     * @return one of ({@link #CELL_TYPE_NUMERIC}, {@link #CELL_TYPE_STRING},
-     *     {@link #CELL_TYPE_BOOLEAN}, {@link #CELL_TYPE_ERROR}) depending
+     * @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING},
+     *     {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending
      * on the cached value of the formula
      */
-    public int getCachedFormulaResultType() {
-        if (_cellType != CELL_TYPE_FORMULA) {
+    public CellType getCachedFormulaResultType() {
+        if (_cellType != CellType.FORMULA) {
             throw new IllegalStateException("Only formula cells have cached results");
         }
-        return ((FormulaRecordAggregate)_record).getFormulaRecord().getCachedResultType();
+        int code = ((FormulaRecordAggregate)_record).getFormulaRecord().getCachedResultType();
+        return CellType.forInt(code);
     }
 
     void setCellArrayFormula(CellRangeAddress range) {
         int row = _record.getRow();
         short col = _record.getColumn();
         short styleIndex = _record.getXFIndex();
-        setCellType(CELL_TYPE_FORMULA, false, row, col, styleIndex);
+        setCellType(CellType.FORMULA, false, row, col, styleIndex);
 
         // Billet for formula in rec
         Ptg[] ptgsForCell = {new ExpPtg(range.getFirstRow(), range.getFirstColumn())};
@@ -1166,7 +1155,7 @@ public class HSSFCell implements Cell {
     }
 
     public CellRangeAddress getArrayFormulaRange() {
-        if (_cellType != CELL_TYPE_FORMULA) {
+        if (_cellType != CellType.FORMULA) {
             String ref = new CellReference(this).formatAsString();
             throw new IllegalStateException("Cell " + ref
                     + " is not part of an array formula.");
@@ -1175,7 +1164,7 @@ public class HSSFCell implements Cell {
     }
 
     public boolean isPartOfArrayFormulaGroup() {
-        if (_cellType != CELL_TYPE_FORMULA) {
+        if (_cellType != CellType.FORMULA) {
             return false;
         }
         return ((FormulaRecordAggregate)_record).isPartOfArrayFormula();

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java Mon Jul  4 09:45:46 2016
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel;
 
 import org.apache.poi.ss.formula.EvaluationCell;
 import org.apache.poi.ss.formula.EvaluationSheet;
+import org.apache.poi.ss.usermodel.CellType;
 /**
  * HSSF wrapper for a cell under evaluation
  */
@@ -34,6 +35,7 @@ final class HSSFEvaluationCell implement
 	public HSSFEvaluationCell(HSSFCell cell) {
 		this(cell, new HSSFEvaluationSheet(cell.getSheet()));
 	}
+	@Override
 	public Object getIdentityKey() {
 		// save memory by just using the cell itself as the identity key
 		// Note - this assumes HSSFCell has not overridden hashCode and equals
@@ -43,31 +45,40 @@ final class HSSFEvaluationCell implement
 	public HSSFCell getHSSFCell() {
 		return _cell;
 	}
+	@Override
 	public boolean getBooleanCellValue() {
 		return _cell.getBooleanCellValue();
 	}
-	public int getCellType() {
+	@Override
+	public CellType getCellType() {
 		return _cell.getCellType();
 	}
+	@Override
 	public int getColumnIndex() {
 		return _cell.getColumnIndex();
 	}
+	@Override
 	public int getErrorCellValue() {
 		return _cell.getErrorCellValue();
 	}
+	@Override
 	public double getNumericCellValue() {
 		return _cell.getNumericCellValue();
 	}
+	@Override
 	public int getRowIndex() {
 		return _cell.getRowIndex();
 	}
+	@Override
 	public EvaluationSheet getSheet() {
 		return _evalSheet;
 	}
+	@Override
 	public String getStringCellValue() {
 		return _cell.getRichStringCellValue().getString();
 	}
-	public int getCachedFormulaResultType() {
+	@Override
+	public CellType getCachedFormulaResultType() {
 		return _cell.getCachedFormulaResultType();
 	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java Mon Jul  4 09:45:46 2016
@@ -30,6 +30,7 @@ import org.apache.poi.ss.formula.eval.St
 import org.apache.poi.ss.formula.eval.ValueEval;
 import org.apache.poi.ss.formula.udf.UDFFinder;
 import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.CellValue;
 import org.apache.poi.ss.usermodel.FormulaEvaluator;
 import org.apache.poi.ss.usermodel.Row;
@@ -171,26 +172,28 @@ public class HSSFFormulaEvaluator implem
 	 * @return <code>null</code> if the supplied cell is <code>null</code> or blank
 	 */
 	@Override
-    public CellValue evaluate(Cell cell) {
+	public CellValue evaluate(Cell cell) {
 		if (cell == null) {
 			return null;
 		}
 
 		switch (cell.getCellType()) {
-			case Cell.CELL_TYPE_BOOLEAN:
+			case BOOLEAN:
 				return CellValue.valueOf(cell.getBooleanCellValue());
-			case Cell.CELL_TYPE_ERROR:
+			case ERROR:
 				return CellValue.getError(cell.getErrorCellValue());
-			case Cell.CELL_TYPE_FORMULA:
+			case FORMULA:
 				return evaluateFormulaCellValue(cell);
-			case Cell.CELL_TYPE_NUMERIC:
+			case NUMERIC:
 				return new CellValue(cell.getNumericCellValue());
-			case Cell.CELL_TYPE_STRING:
+			case STRING:
 				return new CellValue(cell.getRichStringCellValue().getString());
-			case Cell.CELL_TYPE_BLANK:
+			case BLANK:
 				return null;
+			default:
+				throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
 		}
-		throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
+		
 	}
 
 
@@ -210,9 +213,9 @@ public class HSSFFormulaEvaluator implem
 	 * @return -1 for non-formula cells, or the type of the <em>formula result</em>
 	 */
 	@Override
-    public int evaluateFormulaCell(Cell cell) {
-		if (cell == null || cell.getCellType() != Cell.CELL_TYPE_FORMULA) {
-			return -1;
+	public CellType evaluateFormulaCell(Cell cell) {
+		if (cell == null || cell.getCellType() != CellType.FORMULA) {
+			return CellType._UNINITIALIZED;
 		}
 		CellValue cv = evaluateFormulaCellValue(cell);
 		// cell remains a formula cell, but the cached value is changed
@@ -241,7 +244,7 @@ public class HSSFFormulaEvaluator implem
 			return null;
 		}
 		HSSFCell result = (HSSFCell) cell;
-		if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
+		if (cell.getCellType() == CellType.FORMULA) {
 			CellValue cv = evaluateFormulaCellValue(cell);
 			setCellValue(cell, cv);
 			setCellType(cell, cv); // cell will no longer be a formula cell
@@ -249,40 +252,42 @@ public class HSSFFormulaEvaluator implem
 		return result;
 	}
 	private static void setCellType(Cell cell, CellValue cv) {
-		int cellType = cv.getCellType();
+		CellType cellType = cv.getCellType();
 		switch (cellType) {
-			case Cell.CELL_TYPE_BOOLEAN:
-			case Cell.CELL_TYPE_ERROR:
-			case Cell.CELL_TYPE_NUMERIC:
-			case Cell.CELL_TYPE_STRING:
+			case BOOLEAN:
+			case ERROR:
+			case NUMERIC:
+			case STRING:
 				cell.setCellType(cellType);
 				return;
-			case Cell.CELL_TYPE_BLANK:
+			case BLANK:
 				// never happens - blanks eventually get translated to zero
-			case Cell.CELL_TYPE_FORMULA:
+			case FORMULA:
 				// this will never happen, we have already evaluated the formula
+			default:
+				throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
 		}
-		throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
+		
 	}
 
 	private static void setCellValue(Cell cell, CellValue cv) {
-		int cellType = cv.getCellType();
+		CellType cellType = cv.getCellType();
 		switch (cellType) {
-			case Cell.CELL_TYPE_BOOLEAN:
+			case BOOLEAN:
 				cell.setCellValue(cv.getBooleanValue());
 				break;
-			case Cell.CELL_TYPE_ERROR:
+			case ERROR:
 				cell.setCellErrorValue(cv.getErrorValue());
 				break;
-			case Cell.CELL_TYPE_NUMERIC:
+			case NUMERIC:
 				cell.setCellValue(cv.getNumberValue());
 				break;
-			case Cell.CELL_TYPE_STRING:
+			case STRING:
 				cell.setCellValue(new HSSFRichTextString(cv.getStringValue()));
 				break;
-			case Cell.CELL_TYPE_BLANK:
+			case BLANK:
 				// never happens - blanks eventually get translated to zero
-			case Cell.CELL_TYPE_FORMULA:
+			case FORMULA:
 				// this will never happen, we have already evaluated the formula
 			default:
 				throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
@@ -325,7 +330,7 @@ public class HSSFFormulaEvaluator implem
 
          for(Row r : sheet) {
             for (Cell c : r) {
-               if (c.getCellType() == Cell.CELL_TYPE_FORMULA) {
+               if (c.getCellType() == CellType.FORMULA) {
                   evaluator.evaluateFormulaCell(c);
                }
             }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java Mon Jul  4 09:45:46 2016
@@ -26,6 +26,7 @@ import org.apache.poi.hssf.record.RowRec
 import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.util.Configurator;
 
@@ -110,26 +111,46 @@ public final class HSSFRow implements Ro
     @Override
     public HSSFCell createCell(int column)
     {
-        return this.createCell(column,Cell.CELL_TYPE_BLANK);
+        return this.createCell(column,CellType.BLANK);
     }
-
+    
     /**
      * Use this to create new cells within the row and return it.
      * <p>
      * The cell that is returned will be of the requested type.
      * The type can be changed either through calling setCellValue 
      *  or setCellType, but there is a small overhead to doing this,
-     *  so it is best to create of the required type up front.
+     *  so it is best to create the required type up front.
      *
      * @param columnIndex - the column number this cell represents
      *
      * @return HSSFCell a high level representation of the created cell.
      * @throws IllegalArgumentException if columnIndex < 0 or greater than 255,
      *   the maximum number of columns supported by the Excel binary format (.xls)
+     * @deprecated POI 3.15 beta 3
      */
     @Override
     public HSSFCell createCell(int columnIndex, int type)
     {
+        return createCell(columnIndex, CellType.forInt(type));
+    }
+    /**
+     * Use this to create new cells within the row and return it.
+     * <p>
+     * The cell that is returned will be of the requested type.
+     * The type can be changed either through calling setCellValue 
+     *  or setCellType, but there is a small overhead to doing this,
+     *  so it is best to create the required type up front.
+     *
+     * @param columnIndex - the column number this cell represents
+     *
+     * @return HSSFCell a high level representation of the created cell.
+     * @throws IllegalArgumentException if columnIndex < 0 or greater than 255,
+     *   the maximum number of columns supported by the Excel binary format (.xls)
+     */
+    @Override
+    public HSSFCell createCell(int columnIndex, CellType type)
+    {
         short shortCellNum = (short)columnIndex;
         if(columnIndex > 0x7FFF) {
             shortCellNum = (short)(0xffff - columnIndex);
@@ -367,10 +388,10 @@ public final class HSSFRow implements Ro
             case RETURN_NULL_AND_BLANK:
                 return cell;
             case RETURN_BLANK_AS_NULL:
-                boolean isBlank = (cell != null && cell.getCellType() == Cell.CELL_TYPE_BLANK);
+                boolean isBlank = (cell != null && cell.getCellType() == CellType.BLANK);
                 return (isBlank) ? null : cell;
             case CREATE_NULL_AS_BLANK:
-                return (cell == null) ? createCell(cellnum, Cell.CELL_TYPE_BLANK) : cell;
+                return (cell == null) ? createCell(cellnum, CellType.BLANK) : cell;
             default:
                 throw new IllegalArgumentException("Illegal policy " + policy + " (" + policy.id + ")");
         }

Modified: poi/trunk/src/java/org/apache/poi/ss/format/CellFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/format/CellFormat.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/format/CellFormat.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/format/CellFormat.java Mon Jul  4 09:45:46 2016
@@ -29,6 +29,7 @@ import java.util.regex.Pattern;
 import javax.swing.JLabel;
 
 import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.ConditionalFormatting;
 import org.apache.poi.ss.usermodel.ConditionalFormattingRule;
 import org.apache.poi.ss.usermodel.DataFormatter;
@@ -265,11 +266,11 @@ public class CellFormat {
      */
     public CellFormatResult apply(Cell c) {
         switch (ultimateType(c)) {
-        case Cell.CELL_TYPE_BLANK:
+        case BLANK:
             return apply("");
-        case Cell.CELL_TYPE_BOOLEAN:
+        case BOOLEAN:
             return apply(c.getBooleanCellValue());
-        case Cell.CELL_TYPE_NUMERIC:
+        case NUMERIC:
             Double value = c.getNumericCellValue();
             if (getApplicableFormatPart(value).getCellFormatType() == CellFormatType.DATE) {
                 if (DateUtil.isValidExcelDate(value)) {
@@ -280,7 +281,7 @@ public class CellFormat {
             } else {
                 return apply(value);
             }
-        case Cell.CELL_TYPE_STRING:
+        case STRING:
             return apply(c.getStringCellValue());
         default:
             return apply("?");
@@ -335,26 +336,26 @@ public class CellFormat {
      */
     public CellFormatResult apply(JLabel label, Cell c) {
         switch (ultimateType(c)) {
-        case Cell.CELL_TYPE_BLANK:
-            return apply(label, "");
-        case Cell.CELL_TYPE_BOOLEAN:
-            return apply(label, c.getBooleanCellValue());
-        case Cell.CELL_TYPE_NUMERIC:
-            Double value = c.getNumericCellValue();
-            if (getApplicableFormatPart(value).getCellFormatType() == CellFormatType.DATE) {
-                if (DateUtil.isValidExcelDate(value)) {
-                    return apply(label, c.getDateCellValue(), value);
+            case BLANK:
+                return apply(label, "");
+            case BOOLEAN:
+                return apply(label, c.getBooleanCellValue());
+            case NUMERIC:
+                Double value = c.getNumericCellValue();
+                if (getApplicableFormatPart(value).getCellFormatType() == CellFormatType.DATE) {
+                    if (DateUtil.isValidExcelDate(value)) {
+                        return apply(label, c.getDateCellValue(), value);
+                    } else {
+                        return apply(label, INVALID_VALUE_FOR_FORMAT);
+                    }
                 } else {
-                    return apply(label, INVALID_VALUE_FOR_FORMAT);
+                    return apply(label, value);
                 }
-            } else {
-                return apply(label, value);
+            case STRING:
+                return apply(label, c.getStringCellValue());
+            default:
+                return apply(label, "?");
             }
-        case Cell.CELL_TYPE_STRING:
-            return apply(label, c.getStringCellValue());
-        default:
-            return apply(label, "?");
-        }
     }
 
     /**
@@ -417,9 +418,9 @@ public class CellFormat {
      *
      * @return The ultimate type of this cell.
      */
-    public static int ultimateType(Cell cell) {
-        int type = cell.getCellType();
-        if (type == Cell.CELL_TYPE_FORMULA)
+    public static CellType ultimateType(Cell cell) {
+        CellType type = cell.getCellType();
+        if (type == CellType.FORMULA)
             return cell.getCachedFormulaResultType();
         else
             return type;

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationCell.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationCell.java Mon Jul  4 09:45:46 2016
@@ -17,6 +17,8 @@
 
 package org.apache.poi.ss.formula;
 
+import org.apache.poi.ss.usermodel.CellType;
+
 /**
  * Abstracts a cell for the purpose of formula evaluation.  This interface represents both formula
  * and non-formula cells.<br/>
@@ -35,12 +37,12 @@ public interface EvaluationCell {
 	EvaluationSheet getSheet();
 	int getRowIndex();
 	int getColumnIndex();
-	int getCellType();
+	CellType getCellType();
 
 	double getNumericCellValue();
 	String getStringCellValue();
 	boolean getBooleanCellValue();
 	int getErrorCellValue();
 
-	int getCachedFormulaResultType();
+	CellType getCachedFormulaResultType();
 }

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java Mon Jul  4 09:45:46 2016
@@ -76,7 +76,7 @@ import org.apache.poi.ss.formula.ptg.Uni
 import org.apache.poi.ss.formula.ptg.UnknownPtg;
 import org.apache.poi.ss.formula.udf.AggregatingUDFFinder;
 import org.apache.poi.ss.formula.udf.UDFFinder;
-import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
@@ -276,7 +276,7 @@ public final class WorkbookEvaluator {
         // avoid tracking dependencies to cells that have constant definition
         boolean shouldCellDependencyBeRecorded = _stabilityClassifier == null ? true
                     : !_stabilityClassifier.isCellFinal(sheetIndex, rowIndex, columnIndex);
-        if (srcCell == null || srcCell.getCellType() != Cell.CELL_TYPE_FORMULA) {
+        if (srcCell == null || srcCell.getCellType() != CellType.FORMULA) {
             ValueEval result = getValueFromNonFormulaCell(srcCell);
             if (shouldCellDependencyBeRecorded) {
                 tracker.acceptPlainValueDependency(_workbookIx, sheetIndex, rowIndex, columnIndex, result);
@@ -315,22 +315,22 @@ public final class WorkbookEvaluator {
                  if (re.getCause() instanceof WorkbookNotFoundException && _ignoreMissingWorkbooks) {
                      logInfo(re.getCause().getMessage() + " - Continuing with cached value!");
                      switch(srcCell.getCachedFormulaResultType()) {
-                         case Cell.CELL_TYPE_NUMERIC:
+                         case NUMERIC:
                              result = new NumberEval(srcCell.getNumericCellValue());
                              break;
-                         case Cell.CELL_TYPE_STRING:
+                         case STRING:
                              result =  new StringEval(srcCell.getStringCellValue());
                              break;
-                         case Cell.CELL_TYPE_BLANK:
+                         case BLANK:
                              result = BlankEval.instance;
                              break;
-                         case Cell.CELL_TYPE_BOOLEAN:
+                         case BOOLEAN:
                              result =  BoolEval.valueOf(srcCell.getBooleanCellValue());
                              break;
-                         case Cell.CELL_TYPE_ERROR:
+                         case ERROR:
                             result =  ErrorEval.valueOf(srcCell.getErrorCellValue());
                             break;
-                         case Cell.CELL_TYPE_FORMULA:
+                         case FORMULA:
                         default:
                             throw new RuntimeException("Unexpected cell type '" + srcCell.getCellType()+"' found!");
                      }
@@ -385,20 +385,22 @@ public final class WorkbookEvaluator {
         if (cell == null) {
             return BlankEval.instance;
         }
-        int cellType = cell.getCellType();
+        CellType cellType = cell.getCellType();
         switch (cellType) {
-            case Cell.CELL_TYPE_NUMERIC:
+            case NUMERIC:
                 return new NumberEval(cell.getNumericCellValue());
-            case Cell.CELL_TYPE_STRING:
+            case STRING:
                 return new StringEval(cell.getStringCellValue());
-            case Cell.CELL_TYPE_BOOLEAN:
+            case BOOLEAN:
                 return BoolEval.valueOf(cell.getBooleanCellValue());
-            case Cell.CELL_TYPE_BLANK:
+            case BLANK:
                 return BlankEval.instance;
-            case Cell.CELL_TYPE_ERROR:
+            case ERROR:
                 return ErrorEval.valueOf(cell.getErrorCellValue());
+            default:
+                throw new RuntimeException("Unexpected cell type (" + cellType + ")");
         }
-        throw new RuntimeException("Unexpected cell type (" + cellType + ")");
+        
     }
 
 

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java Mon Jul  4 09:45:46 2016
@@ -26,6 +26,7 @@ import org.apache.poi.ss.formula.eval.Va
 import org.apache.poi.ss.formula.EvaluationCell;
 import org.apache.poi.ss.formula.EvaluationSheet;
 import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
 
 /**
  * Represents a cell being used for forked evaluation that has had a value set different from the
@@ -39,7 +40,7 @@ final class ForkedEvaluationCell impleme
 	/** corresponding cell from master workbook */
 	private final EvaluationCell _masterCell;
 	private boolean _booleanValue;
-	private int _cellType;
+	private CellType _cellType;
 	private int _errorValue;
 	private double _numberValue;
 	private String _stringValue;
@@ -59,64 +60,64 @@ final class ForkedEvaluationCell impleme
 		Class<? extends ValueEval> cls = value.getClass();
 
 		if (cls == NumberEval.class) {
-			_cellType = Cell.CELL_TYPE_NUMERIC;
+			_cellType = CellType.NUMERIC;
 			_numberValue = ((NumberEval)value).getNumberValue();
 			return;
 		}
 		if (cls == StringEval.class) {
-			_cellType = Cell.CELL_TYPE_STRING;
+			_cellType = CellType.STRING;
 			_stringValue = ((StringEval)value).getStringValue();
 			return;
 		}
 		if (cls == BoolEval.class) {
-			_cellType = Cell.CELL_TYPE_BOOLEAN;
+			_cellType = CellType.BOOLEAN;
 			_booleanValue = ((BoolEval)value).getBooleanValue();
 			return;
 		}
 		if (cls == ErrorEval.class) {
-			_cellType = Cell.CELL_TYPE_ERROR;
+			_cellType = CellType.ERROR;
 			_errorValue = ((ErrorEval)value).getErrorCode();
 			return;
 		}
 		if (cls == BlankEval.class) {
-			_cellType = Cell.CELL_TYPE_BLANK;
+			_cellType = CellType.BLANK;
 			return;
 		}
 		throw new IllegalArgumentException("Unexpected value class (" + cls.getName() + ")");
 	}
 	public void copyValue(Cell destCell) {
 		switch (_cellType) {
-			case Cell.CELL_TYPE_BLANK:   destCell.setCellType(Cell.CELL_TYPE_BLANK);    return;
-			case Cell.CELL_TYPE_NUMERIC: destCell.setCellValue(_numberValue);           return;
-			case Cell.CELL_TYPE_BOOLEAN: destCell.setCellValue(_booleanValue);          return;
-			case Cell.CELL_TYPE_STRING:  destCell.setCellValue(_stringValue);           return;
-			case Cell.CELL_TYPE_ERROR:   destCell.setCellErrorValue((byte)_errorValue); return;
+			case BLANK:   destCell.setCellType(CellType.BLANK);          return;
+			case NUMERIC: destCell.setCellValue(_numberValue);           return;
+			case BOOLEAN: destCell.setCellValue(_booleanValue);          return;
+			case STRING:  destCell.setCellValue(_stringValue);           return;
+			case ERROR:   destCell.setCellErrorValue((byte)_errorValue); return;
+			default: throw new IllegalStateException("Unexpected data type (" + _cellType + ")");
 		}
-		throw new IllegalStateException("Unexpected data type (" + _cellType + ")");
 	}
 
-	private void checkCellType(int expectedCellType) {
+	private void checkCellType(CellType expectedCellType) {
 		if (_cellType != expectedCellType) {
 			throw new RuntimeException("Wrong data type (" + _cellType + ")");
 		}
 	}
-	public int getCellType() {
+	public CellType getCellType() {
 		return _cellType;
 	}
 	public boolean getBooleanCellValue() {
-		checkCellType(Cell.CELL_TYPE_BOOLEAN);
+		checkCellType(CellType.BOOLEAN);
 		return _booleanValue;
 	}
 	public int getErrorCellValue() {
-		checkCellType(Cell.CELL_TYPE_ERROR);
+		checkCellType(CellType.ERROR);
 		return _errorValue;
 	}
 	public double getNumericCellValue() {
-		checkCellType(Cell.CELL_TYPE_NUMERIC);
+		checkCellType(CellType.NUMERIC);
 		return _numberValue;
 	}
 	public String getStringCellValue() {
-		checkCellType(Cell.CELL_TYPE_STRING);
+		checkCellType(CellType.STRING);
 		return _stringValue;
 	}
 	public EvaluationSheet getSheet() {
@@ -128,7 +129,7 @@ final class ForkedEvaluationCell impleme
 	public int getColumnIndex() {
 		return _masterCell.getColumnIndex();
 	}
-    public int getCachedFormulaResultType() {
+    public CellType getCachedFormulaResultType() {
         return _masterCell.getCachedFormulaResultType();
     }
 

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluator.java?rev=1751237&r1=1751236&r2=1751237&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluator.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluator.java Mon Jul  4 09:45:46 2016
@@ -33,7 +33,6 @@ import org.apache.poi.ss.formula.Evaluat
 import org.apache.poi.ss.formula.EvaluationWorkbook;
 import org.apache.poi.ss.formula.IStabilityClassifier;
 import org.apache.poi.ss.formula.WorkbookEvaluator;
-import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Workbook;
 
 /**
@@ -114,20 +113,21 @@ public final class ForkedEvaluator {
 		EvaluationCell cell = _sewb.getEvaluationCell(sheetName, rowIndex, columnIndex);
 
 		switch (cell.getCellType()) {
-			case Cell.CELL_TYPE_BOOLEAN:
+			case BOOLEAN:
 				return BoolEval.valueOf(cell.getBooleanCellValue());
-			case Cell.CELL_TYPE_ERROR:
+			case ERROR:
 				return ErrorEval.valueOf(cell.getErrorCellValue());
-			case Cell.CELL_TYPE_FORMULA:
+			case FORMULA:
 				return _evaluator.evaluate(cell);
-			case Cell.CELL_TYPE_NUMERIC:
+			case NUMERIC:
 				return new NumberEval(cell.getNumericCellValue());
-			case Cell.CELL_TYPE_STRING:
+			case STRING:
 				return new StringEval(cell.getStringCellValue());
-			case Cell.CELL_TYPE_BLANK:
+			case BLANK:
 				return null;
+			default:
+				throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
 		}
-		throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
 	}
 	/**
 	 * Coordinates several formula evaluators together so that formulas that involve external

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=1751237&r1=1751236&r2=1751237&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 Jul  4 09:45:46 2016
@@ -43,43 +43,49 @@ public interface Cell {
      * Numeric Cell type (0)
      * @see #setCellType(int)
      * @see #getCellType()
+     * @deprecated POI 3.15 beta 3. Use {@link CellType#NUMERIC} instead.
      */
-    int CELL_TYPE_NUMERIC = 0;
+    CellType CELL_TYPE_NUMERIC = CellType.NUMERIC;
 
     /**
      * String Cell type (1)
      * @see #setCellType(int)
      * @see #getCellType()
+     * @deprecated POI 3.15 beta 3. Use {@link CellType#STRING} instead.
      */
-    int CELL_TYPE_STRING = 1;
+    CellType CELL_TYPE_STRING = CellType.STRING;
 
     /**
      * Formula Cell type (2)
      * @see #setCellType(int)
      * @see #getCellType()
+     * @deprecated POI 3.15 beta 3. Use {@link CellType#FORMULA} instead.
      */
-    int CELL_TYPE_FORMULA = 2;
+    CellType CELL_TYPE_FORMULA = CellType.FORMULA;
 
     /**
      * Blank Cell type (3)
      * @see #setCellType(int)
      * @see #getCellType()
+     * @deprecated POI 3.15 beta 3. Use {@link CellType#BLANK} instead.
      */
-    int CELL_TYPE_BLANK = 3;
+    CellType CELL_TYPE_BLANK = CellType.BLANK;
 
     /**
      * Boolean Cell type (4)
      * @see #setCellType(int)
      * @see #getCellType()
+     * @deprecated POI 3.15 beta 3. Use {@link CellType#BOOLEAN} instead.
      */
-    int CELL_TYPE_BOOLEAN = 4;
+    CellType CELL_TYPE_BOOLEAN = CellType.BOOLEAN;
 
     /**
      * Error Cell type (5)
      * @see #setCellType(int)
      * @see #getCellType()
+     * @deprecated POI 3.15 beta 3. Use {@link CellType#ERROR} instead.
      */
-    int CELL_TYPE_ERROR = 5;
+    CellType CELL_TYPE_ERROR = CellType.ERROR;
 
     /**
      * Returns column index of this cell
@@ -127,29 +133,38 @@ public interface Cell {
      * @see #CELL_TYPE_BLANK
      * @see #CELL_TYPE_BOOLEAN
      * @see #CELL_TYPE_ERROR
+     * @deprecated POI 3.15 beta 3. Use {@link #setCellType(CellType)} instead.
      */
     void setCellType(int cellType);
+    /**
+     * Set the cells type (numeric, formula or string).
+     * <p>If the cell currently contains a value, the value will
+     *  be converted to match the new type, if possible. Formatting
+     *  is generally lost in the process however.</p>
+     * <p>If what you want to do is get a String value for your
+     *  numeric cell, <i>stop!</i>. This is not the way to do it.
+     *  Instead, for fetching the string value of a numeric or boolean
+     *  or date cell, use {@link DataFormatter} instead.</p> 
+     *
+     * @throws IllegalArgumentException if the specified cell type is invalid
+     * @throws IllegalStateException if the current value cannot be converted to the new type
+     */
+    void setCellType(CellType cellType);
 
     /**
      * Return the cell type.
      *
      * @return the cell type
-     * @see Cell#CELL_TYPE_BLANK
-     * @see Cell#CELL_TYPE_NUMERIC
-     * @see Cell#CELL_TYPE_STRING
-     * @see Cell#CELL_TYPE_FORMULA
-     * @see Cell#CELL_TYPE_BOOLEAN
-     * @see Cell#CELL_TYPE_ERROR
      */
-    int getCellType();
+    CellType getCellType();
 
     /**
      * Only valid for formula cells
-     * @return one of ({@link #CELL_TYPE_NUMERIC}, {@link #CELL_TYPE_STRING},
-     *     {@link #CELL_TYPE_BOOLEAN}, {@link #CELL_TYPE_ERROR}) depending
+     * @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING},
+     *     {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending
      * on the cached value of the formula
      */
-    int getCachedFormulaResultType();
+    CellType getCachedFormulaResultType();
 
     /**
      * Set a numeric value for the cell
@@ -167,7 +182,7 @@ public interface Cell {
      * <p><b>Note</b> - There is actually no 'DATE' cell type in Excel. In many
      * cases (when entering date values), Excel automatically adjusts the
      * <i>cell style</i> to some date format, creating the illusion that the cell
-     * data type is now something besides {@link Cell#CELL_TYPE_NUMERIC}.  POI
+     * data type is now something besides {@link CellType#NUMERIC}.  POI
      * does not attempt to replicate this behaviour.  To make a numeric cell
      * display as a date, use {@link #setCellStyle(CellStyle)} etc.</p>
      *
@@ -233,7 +248,7 @@ public interface Cell {
      * Return a formula for the cell, for example, <code>SUM(C4:E4)</code>
      *
      * @return a formula for the cell
-     * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is not CELL_TYPE_FORMULA
+     * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is not {@link CellType#FORMULA}
      */
     String getCellFormula();
 
@@ -244,7 +259,7 @@ public interface Cell {
      * For formulas or error cells we return the precalculated value;
      * </p>
      * @return the value of the cell as a number
-     * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is CELL_TYPE_STRING
+     * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is {@link CellType#STRING}
      * @exception NumberFormatException if the cell value isn't a parsable <code>double</code>.
      * @see DataFormatter for turning this number into a string similar to that which Excel would render this number as.
      */
@@ -256,7 +271,7 @@ public interface Cell {
      * For strings we throw an exception. For blank cells we return a null.
      * </p>
      * @return the value of the cell as a date
-     * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is CELL_TYPE_STRING
+     * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is {@link CellType#STRING}
      * @exception NumberFormatException if the cell value isn't a parsable <code>double</code>.
      * @see DataFormatter for formatting  this date into a string similar to how excel does.
      */
@@ -309,7 +324,7 @@ public interface Cell {
      * </p>
      * @return the value of the cell as a boolean
      * @throws IllegalStateException if the cell type returned by {@link #getCellType()}
-     *   is not CELL_TYPE_BOOLEAN, CELL_TYPE_BLANK or CELL_TYPE_FORMULA
+     *   is not {@link CellType#BOOLEAN}, {@link CellType#BLANK} or {@link CellType#FORMULA}
      */
     boolean getBooleanCellValue();
 
@@ -321,13 +336,13 @@ public interface Cell {
      * </p>
      *
      * @return the value of the cell as an error code
-     * @throws IllegalStateException if the cell type returned by {@link #getCellType()} isn't CELL_TYPE_ERROR
+     * @throws IllegalStateException if the cell type returned by {@link #getCellType()} isn't {@link CellType#ERROR}
      * @see FormulaError for error codes
      */
     byte getErrorCellValue();
 
     /**
-     * <p>Set the style for the cell.  The style should be an CellStyle created/retreived from
+     * <p>Set the style for the cell.  The style should be an CellStyle created/retrieved from
      * the Workbook.</p>
      * 
      * <p>To change the style of a cell without affecting other cells that use the same style,

Added: poi/trunk/src/java/org/apache/poi/ss/usermodel/CellType.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/CellType.java?rev=1751237&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/CellType.java (added)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/CellType.java Mon Jul  4 09:45:46 2016
@@ -0,0 +1,78 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+import org.apache.poi.ss.formula.FormulaType;
+import org.apache.poi.util.Internal;
+
+public enum CellType {
+    @Internal
+    _UNINITIALIZED(-1),
+
+    /** Numeric cell type (whole numbers, fractional numbers, dates) */
+    NUMERIC(0),
+    
+    /** String cell type */
+    STRING(1),
+    
+    /**
+     * Formula cell type
+     * @see FormulaType
+     */
+    FORMULA(2),
+    
+    /**
+     * Blank cell type
+     */
+    BLANK(3),
+    
+    /**
+     * Boolean cell type
+     */
+    BOOLEAN(4),
+    
+    /**
+     * Error cell type
+     * @see FormulaError
+     */
+    ERROR(5);
+
+    /** @deprecated POI 3.15 beta 3 */
+    private final int code;
+    
+    /** @deprecated POI 3.15 beta 3 */
+    private CellType(int code) {
+        this.code = code;
+    }
+    
+    /** @deprecated POI 3.15 beta 3. Used to transition code from <code>int</code>s to <code>CellType</code>s. */
+    public static CellType forInt(int code) {
+        for (CellType type : values()) {
+            if (type.code == code) {
+                return type;
+            }
+        }
+        throw new IllegalArgumentException("Invalid CellType code: " + code);
+    }
+    
+    /** @deprecated POI 3.15 beta 3 */
+    public int getCode() {
+        return code;
+    }
+    
+}

Propchange: poi/trunk/src/java/org/apache/poi/ss/usermodel/CellType.java
------------------------------------------------------------------------------
    svn:eol-style = native



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