poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1760647 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/formula/ java/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/xssf/usermodel/
Date Wed, 14 Sep 2016 07:33:20 GMT
Author: onealj
Date: Wed Sep 14 07:33:20 2016
New Revision: 1760647

URL: http://svn.apache.org/viewvc?rev=1760647&view=rev
Log:
move BaseXSSFFormulaEvaluator#evaluateFormulaCellEnum(Cell) and HSSFFormulaEvaluator#evaluateFormulaCellEnum(Cell)
up to BaseFormulaEvaluator class to reduce duplicated code

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
    poi/trunk/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java

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=1760647&r1=1760646&r2=1760647&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 Wed Sep 14
07:33:20 2016
@@ -33,9 +33,8 @@ 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.RichTextString;
 import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.util.Internal;
-import org.apache.poi.util.Removal;
 
 /**
  * Evaluates formula cells.<p/>
@@ -82,6 +81,11 @@ public class HSSFFormulaEvaluator extend
     public static HSSFFormulaEvaluator create(HSSFWorkbook workbook, IStabilityClassifier
stabilityClassifier, UDFFinder udfFinder) {
         return new HSSFFormulaEvaluator(workbook, stabilityClassifier, udfFinder);
     }
+    
+    @Override
+    protected RichTextString createRichTextString(String str) {
+        return new HSSFRichTextString(str);
+    }
 
 
     /**
@@ -139,34 +143,6 @@ public class HSSFFormulaEvaluator extend
     }
 
     /**
-     * If cell contains formula, it evaluates the formula, and saves the result of the formula.
The
-     * cell remains as a formula cell. If the cell does not contain formula, rather than
throwing an
-     * exception, this method returns {@link CellType#_NONE} and leaves the cell unchanged.
-     *
-     * Note that the type of the <em>formula result</em> is returned, so you
know what kind of
-     * cached formula result is also stored with  the formula.
-     * <pre>
-     * CellType evaluatedCellType = evaluator.evaluateFormulaCell(cell);
-     * </pre>
-     * Be aware that your cell will hold both the formula, and the result. If you want the
cell
-     * replaced with the result of the formula, use {@link #evaluateInCell(org.apache.poi.ss.usermodel.Cell)}
-     * @param cell The cell to evaluate
-     * @return {@link CellType#_NONE} for non-formula cells, or the type of the <em>formula
result</em>
-     * @since POI 3.15 beta 3
-     * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition.
See bug 59791.
-     */
-    @Override
-    public CellType evaluateFormulaCellEnum(Cell cell) {
-        if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) {
-            return CellType._NONE;
-        }
-        CellValue cv = evaluateFormulaCellValue(cell);
-        // cell remains a formula cell, but the cached value is changed
-        setCellValue(cell, cv);
-        return cv.getCellTypeEnum();
-    }
-
-    /**
      * If cell contains formula, it evaluates the formula, and
      *  puts the formula result back into the cell, in place
      *  of the old formula.
@@ -195,30 +171,6 @@ public class HSSFFormulaEvaluator extend
         return result;
     }
 
-    private static void setCellValue(Cell cell, CellValue cv) {
-        CellType cellType = cv.getCellTypeEnum();
-        switch (cellType) {
-            case BOOLEAN:
-                cell.setCellValue(cv.getBooleanValue());
-                break;
-            case ERROR:
-                cell.setCellErrorValue(cv.getErrorValue());
-                break;
-            case NUMERIC:
-                cell.setCellValue(cv.getNumberValue());
-                break;
-            case STRING:
-                cell.setCellValue(new HSSFRichTextString(cv.getStringValue()));
-                break;
-            case BLANK:
-                // never happens - blanks eventually get translated to zero
-            case FORMULA:
-                // this will never happen, we have already evaluated the formula
-            default:
-                throw new IllegalStateException("Unexpected cell value type (" + cellType
+ ")");
-        }
-    }
-
     /**
      * Loops over all cells in all sheets of the supplied
      *  workbook.

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java?rev=1760647&r1=1760646&r2=1760647&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java Wed Sep 14 07:33:20
2016
@@ -19,10 +19,13 @@ package org.apache.poi.ss.formula;
 
 import java.util.Map;
 
+import org.apache.poi.hssf.usermodel.HSSFRichTextString;
 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.CreationHelper;
 import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.RichTextString;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -131,6 +134,38 @@ public abstract class BaseFormulaEvaluat
     public int evaluateFormulaCell(Cell cell) {
         return evaluateFormulaCellEnum(cell).getCode();
     }
+    
+    /**
+     * If cell contains formula, it evaluates the formula,
+     *  and saves the result of the formula. The cell
+     *  remains as a formula cell.
+     * Else if cell does not contain formula, this method leaves
+     *  the cell unchanged.
+     * Note that the type of the formula result is returned,
+     *  so you know what kind of value is also stored with
+     *  the formula.
+     * <pre>
+     * CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell);
+     * </pre>
+     * Be aware that your cell will hold both the formula,
+     *  and the result. If you want the cell replaced with
+     *  the result of the formula, use {@link #evaluate(org.apache.poi.ss.usermodel.Cell)}
}
+     * @param cell The cell to evaluate
+     * @return The type of the formula result (the cell's type remains as CellType.FORMULA
however)
+     *         If cell is not a formula cell, returns {@link CellType#_NONE} rather than
throwing an exception.
+     * @since POI 3.15 beta 3
+     * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition.
See bug 59791.
+     */
+    @Override
+    public CellType evaluateFormulaCellEnum(Cell cell) {
+        if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) {
+            return CellType._NONE;
+        }
+        CellValue cv = evaluateFormulaCellValue(cell);
+        // cell remains a formula cell, but the cached value is changed
+        setCellValue(cell, cv);
+        return cv.getCellTypeEnum();
+    }
 
     protected static void setCellType(Cell cell, CellValue cv) {
         CellType cellType = cv.getCellTypeEnum();
@@ -151,6 +186,33 @@ public abstract class BaseFormulaEvaluat
                 throw new IllegalStateException("Unexpected cell value type (" + cellType
+ ")");
         }
     }
+    
+    protected abstract RichTextString createRichTextString(String str);
+    
+    protected void setCellValue(Cell cell, CellValue cv) {
+        CellType cellType = cv.getCellTypeEnum();
+        switch (cellType) {
+            case BOOLEAN:
+                cell.setCellValue(cv.getBooleanValue());
+                break;
+            case ERROR:
+                cell.setCellErrorValue(cv.getErrorValue());
+                break;
+            case NUMERIC:
+                cell.setCellValue(cv.getNumberValue());
+                break;
+            case STRING:
+                cell.setCellValue(createRichTextString(cv.getStringValue()));
+                break;
+            case BLANK:
+                // never happens - blanks eventually get translated to zero
+            case FORMULA:
+                // this will never happen, we have already evaluated the formula
+            default:
+                throw new IllegalStateException("Unexpected cell value type (" + cellType
+ ")");
+        }
+    }
+    
 
     /**
      * Loops over all cells in all sheets of the supplied

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java?rev=1760647&r1=1760646&r2=1760647&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java Wed Sep 14 07:33:20
2016
@@ -101,6 +101,7 @@ public interface FormulaEvaluator {
      *      or one of {@link CellType#NUMERIC}, {@link CellType#STRING},
      *      {@link CellType#BOOLEAN}, {@link CellType#ERROR}
      *      Note: the cell's type remains as CellType.FORMULA however.
+     * @deprecated 3.15. Will return a {@link CellType} enum in the future
      */
     int evaluateFormulaCell(Cell cell);
     

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java?rev=1760647&r1=1760646&r2=1760647&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java Wed
Sep 14 07:33:20 2016
@@ -28,6 +28,7 @@ import org.apache.poi.ss.formula.eval.Va
 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.RichTextString;
 
 /**
  * Internal POI use only - parent of XSSF and SXSSF formula evaluators
@@ -36,6 +37,10 @@ public abstract class BaseXSSFFormulaEva
     protected BaseXSSFFormulaEvaluator(WorkbookEvaluator bookEvaluator) {
         super(bookEvaluator);
     }
+    @Override
+    protected RichTextString createRichTextString(String str) {
+        return new XSSFRichTextString(str);
+    }
 
     public void notifySetFormula(Cell cell) {
         _bookEvaluator.notifyUpdateCell(new XSSFEvaluationCell((XSSFCell)cell));
@@ -48,37 +53,6 @@ public abstract class BaseXSSFFormulaEva
     }
 
     /**
-     * If cell contains formula, it evaluates the formula,
-     *  and saves the result of the formula. The cell
-     *  remains as a formula cell.
-     * Else if cell does not contain formula, this method leaves
-     *  the cell unchanged.
-     * Note that the type of the formula result is returned,
-     *  so you know what kind of value is also stored with
-     *  the formula.
-     * <pre>
-     * CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell);
-     * </pre>
-     * Be aware that your cell will hold both the formula,
-     *  and the result. If you want the cell replaced with
-     *  the result of the formula, use {@link #evaluate(org.apache.poi.ss.usermodel.Cell)}
}
-     * @param cell The cell to evaluate
-     * @return The type of the formula result (the cell's type remains as CellType.FORMULA
however)
-     *         If cell is not a formula cell, returns {@link CellType#_NONE} rather than
throwing an exception.
-     * @since POI 3.15 beta 3
-     * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition.
See bug 59791.
-     */
-    public CellType evaluateFormulaCellEnum(Cell cell) {
-        if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) {
-            return CellType._NONE;
-        }
-        CellValue cv = evaluateFormulaCellValue(cell);
-        // cell remains a formula cell, but the cached value is changed
-        setCellValue(cell, cv);
-        return cv.getCellTypeEnum();
-    }
-
-    /**
      * If cell contains formula, it evaluates the formula, and
      *  puts the formula result back into the cell, in place
      *  of the old formula.
@@ -94,30 +68,6 @@ public abstract class BaseXSSFFormulaEva
         }
     }
 
-    private static void setCellValue(Cell cell, CellValue cv) {
-        CellType cellType = cv.getCellTypeEnum();
-        switch (cellType) {
-            case BOOLEAN:
-                cell.setCellValue(cv.getBooleanValue());
-                break;
-            case ERROR:
-                cell.setCellErrorValue(cv.getErrorValue());
-                break;
-            case NUMERIC:
-                cell.setCellValue(cv.getNumberValue());
-                break;
-            case STRING:
-                cell.setCellValue(new XSSFRichTextString(cv.getStringValue()));
-                break;
-            case BLANK:
-                // never happens - blanks eventually get translated to zero
-            case FORMULA:
-                // this will never happen, we have already evaluated the formula
-            default:
-                throw new IllegalStateException("Unexpected cell value type (" + cellType
+ ")");
-        }
-    }
-
     /**
      * Turns a XSSFCell / SXSSFCell into a XSSFEvaluationCell
      */



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


Mime
View raw message