diff --git a/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java b/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java
index b2a46d831b..24e5d0a535 100644
--- a/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java
+++ b/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java
@@ -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;
-
/** #NULL! - 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);
/** #DIV/0! - 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);
/** #VALUE! - 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);
/** #REF! - 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);
/** #NAME? - 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);
/** #NUM! - 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);
/** #N/A - 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 ValueEval {
// 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 ValueEval {
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 ValueEval {
* @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 ValueEval {
private ErrorEval(int errorCode) {
_errorCode = errorCode;
}
+ private ErrorEval(FormulaError error) {
+ _errorCode = error.getCode();
+ }
public int getErrorCode() {
return _errorCode;
diff --git a/src/java/org/apache/poi/ss/usermodel/ErrorConstants.java b/src/java/org/apache/poi/ss/usermodel/ErrorConstants.java
index 1bfa184523..b9be6f1e64 100644
--- a/src/java/org/apache/poi/ss/usermodel/ErrorConstants.java
+++ b/src/java/org/apache/poi/ss/usermodel/ErrorConstants.java
@@ -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() {
diff --git a/src/java/org/apache/poi/ss/usermodel/FormulaError.java b/src/java/org/apache/poi/ss/usermodel/FormulaError.java
index 162f24aa4b..f313ab6d0a 100644
--- a/src/java/org/apache/poi/ss/usermodel/FormulaError.java
+++ b/src/java/org/apache/poi/ss/usermodel/FormulaError.java
@@ -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);