poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1658185 - in /poi/trunk/src/java/org/apache/poi/ss: formula/eval/ErrorEval.java usermodel/ErrorConstants.java usermodel/FormulaError.java
Date Sun, 08 Feb 2015 15:17:21 GMT
Author: nick
Date: Sun Feb  8 15:17:20 2015
New Revision: 1658185

URL: http://svn.apache.org/r1658185
Log:
Reduce duplication between FormulaError and ErrorConstants

Modified:
    poi/trunk/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/ErrorConstants.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaError.java

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java?rev=1658185&r1=1658184&r2=1658185&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java Sun Feb  8 15:17:20 2015
@@ -18,38 +18,26 @@
 package org.apache.poi.ss.formula.eval;
 
 import org.apache.poi.ss.usermodel.ErrorConstants;
+import org.apache.poi.ss.usermodel.FormulaError;
 
 /**
- * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *
+ * Evaluations for formula errors
  */
 public final class ErrorEval implements ValueEval {
-
-    // convenient access to namespace
-    private static final ErrorConstants EC = null;
-
     /** <b>#NULL!</b>  - Intersection of two cell ranges is empty */
-    @SuppressWarnings("static-access")
-    public static final ErrorEval NULL_INTERSECTION = new ErrorEval(EC.ERROR_NULL);
+    public static final ErrorEval NULL_INTERSECTION = new ErrorEval(FormulaError.NULL);
     /** <b>#DIV/0!</b> - Division by zero */
-    @SuppressWarnings("static-access")
-    public static final ErrorEval DIV_ZERO = new ErrorEval(EC.ERROR_DIV_0);
+    public static final ErrorEval DIV_ZERO = new ErrorEval(FormulaError.DIV0);
     /** <b>#VALUE!</b> - Wrong type of operand */
-    @SuppressWarnings("static-access")
-    public static final ErrorEval VALUE_INVALID = new ErrorEval(EC.ERROR_VALUE);
+    public static final ErrorEval VALUE_INVALID = new ErrorEval(FormulaError.VALUE);
     /** <b>#REF!</b> - Illegal or deleted cell reference */
-    @SuppressWarnings("static-access")
-    public static final ErrorEval REF_INVALID = new ErrorEval(EC.ERROR_REF);
+    public static final ErrorEval REF_INVALID = new ErrorEval(FormulaError.REF);
     /** <b>#NAME?</b> - Wrong function or range name */
-    @SuppressWarnings("static-access")
-    public static final ErrorEval NAME_INVALID = new ErrorEval(EC.ERROR_NAME);
+    public static final ErrorEval NAME_INVALID = new ErrorEval(FormulaError.NAME);
     /** <b>#NUM!</b> - Value range overflow */
-    @SuppressWarnings("static-access")
-    public static final ErrorEval NUM_ERROR = new ErrorEval(EC.ERROR_NUM);
+    public static final ErrorEval NUM_ERROR = new ErrorEval(FormulaError.NUM);
     /** <b>#N/A</b> - Argument or function not available */
-    @SuppressWarnings("static-access")
-    public static final ErrorEval NA = new ErrorEval(EC.ERROR_NA);
-
+    public static final ErrorEval NA = new ErrorEval(FormulaError.NA);
 
     // POI internal error codes
     private static final int CIRCULAR_REF_ERROR_CODE = 0xFFFFFFC4;
@@ -58,7 +46,6 @@ public final class ErrorEval implements
     // Note - Excel does not seem to represent this condition with an error code
     public static final ErrorEval CIRCULAR_REF_ERROR = new ErrorEval(CIRCULAR_REF_ERROR_CODE);
 
-
     /**
      * Translates an Excel internal error code into the corresponding POI ErrorEval instance
      * @param errorCode
@@ -72,7 +59,7 @@ public final class ErrorEval implements
             case ErrorConstants.ERROR_NAME:  return NAME_INVALID;
             case ErrorConstants.ERROR_NUM:   return NUM_ERROR;
             case ErrorConstants.ERROR_NA:    return NA;
-            // non-std errors (conditions modeled as errors by POI)
+            // non-std errors (conditions modelled as errors by POI)
             case CIRCULAR_REF_ERROR_CODE:        return CIRCULAR_REF_ERROR;
         }
         throw new RuntimeException("Unexpected error code (" + errorCode + ")");
@@ -84,8 +71,8 @@ public final class ErrorEval implements
      * @return the String representation of the specified Excel error code.
      */
     public static String getText(int errorCode) {
-        if(ErrorConstants.isValidCode(errorCode)) {
-            return ErrorConstants.getText(errorCode);
+        if(FormulaError.isValidCode(errorCode)) {
+            return FormulaError.forInt((byte)errorCode).getString();
         }
         // It is desirable to make these (arbitrary) strings look clearly different from
any other
         // value expression that might appear in a formula.  In addition these error strings
should
@@ -104,6 +91,9 @@ public final class ErrorEval implements
     private ErrorEval(int errorCode) {
         _errorCode = errorCode;
     }
+    private ErrorEval(FormulaError error) {
+        _errorCode = error.getCode();
+    }
 
     public int getErrorCode() {
         return _errorCode;

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/ErrorConstants.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/ErrorConstants.java?rev=1658185&r1=1658184&r2=1658185&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/ErrorConstants.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/ErrorConstants.java Sun Feb  8 15:17:20
2015
@@ -20,7 +20,7 @@ package org.apache.poi.ss.usermodel;
 /**
  * Contains raw Excel error codes (as defined in OOO's excelfileformat.pdf (2.5.6)
  * 
- * @author  Michael Harhen
+ * @deprecated Use {@link FormulaError} instead where possible
  */
 public class ErrorConstants {
     protected ErrorConstants() {

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaError.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaError.java?rev=1658185&r1=1658184&r2=1658185&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaError.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaError.java Sun Feb  8 15:17:20 2015
@@ -21,8 +21,8 @@ import java.util.HashMap;
 
 /**
  * Enumerates error values in SpreadsheetML formula calculations.
- *
- * @author Yegor Kozlov
+ * 
+ * See also OOO's excelfileformat.pdf (2.5.6)
  */
 public enum FormulaError {
     /**
@@ -125,6 +125,13 @@ public enum FormulaError {
             smap.put(error.getString(), error);
         }
     }
+    
+    public static final boolean isValidCode(int errorCode) {
+        for (FormulaError error : values()) {
+            if (error.getCode() == errorCode) return true;
+        }
+        return false;
+    }
 
     public static FormulaError forInt(byte type){
         FormulaError err = imap.get(type);



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


Mime
View raw message