diff --git a/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java b/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java
index 24d012577..4f121ab0c 100644
--- a/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java
@@ -676,8 +676,8 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
functionData[209][0]=new Byte(Ptg.CLASS_VALUE);functionData[209][1]=new byte[] {Ptg.CLASS_VALUE};functionData[209][2]=new Integer(2);
functionData[210][0]=new Byte(Ptg.CLASS_VALUE);functionData[210][1]=new byte[] {Ptg.CLASS_VALUE};functionData[210][2]=new Integer(2);
functionData[211][0]=new Byte(Ptg.CLASS_VALUE);functionData[211][1]=new byte[] {Ptg.CLASS_VALUE};functionData[211][2]=new Integer(1);
- functionData[212][0]=new Byte(Ptg.CLASS_VALUE);functionData[212][1]=new byte[] {Ptg.CLASS_VALUE};functionData[212][2]=new Integer(1);
- functionData[213][0]=new Byte(Ptg.CLASS_VALUE);functionData[213][1]=new byte[] {Ptg.CLASS_REF};functionData[213][2]=new Integer(-1);
+ functionData[212][0]=new Byte(Ptg.CLASS_VALUE);functionData[212][1]=new byte[] {Ptg.CLASS_VALUE};functionData[212][2]=new Integer(2);
+ functionData[213][0]=new Byte(Ptg.CLASS_VALUE);functionData[213][1]=new byte[] {Ptg.CLASS_REF};functionData[213][2]=new Integer(2);
functionData[214][0]=new Byte(Ptg.CLASS_VALUE);functionData[214][1]=new byte[] {Ptg.CLASS_VALUE};functionData[214][2]=new Integer(-1);
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AddEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AddEval.java
index bc993a662..0947659c3 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AddEval.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AddEval.java
@@ -31,6 +31,7 @@ public class AddEval extends NumericOperationEval {
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
public AddEval(Ptg ptg) {
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/DivideEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/DivideEval.java
index 3b9d193bc..38803c968 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/DivideEval.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/DivideEval.java
@@ -22,6 +22,7 @@ public class DivideEval extends NumericOperationEval {
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
public DivideEval(Ptg ptg) {
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ErrorEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ErrorEval.java
index e1c8a7fcc..a32db9686 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ErrorEval.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ErrorEval.java
@@ -7,576 +7,15 @@ package org.apache.poi.hssf.record.formula.eval;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
- * Error code reference from OpenOffice documentation:
- *
- *
- *
- * Error Code
- *
- * |
- *
- *
- * Message
- *
- * |
- *
- *
- * Explanation
- *
- * |
- *
- *
- *
- *
- * 501
- *
- * |
- *
- *
- * Invalid character
- *
- * |
- *
- *
- * Character in a formula is not valid, for example, "=1Eq" instead of
- * "=1E2".
- *
- * |
- *
- *
- *
- *
- * 502
- *
- * |
- *
- *
- * Invalid argument
- *
- * |
- *
- *
- * Function argument is not valid, for example, a negative number for the root
- * function.
- *
- * |
- *
- *
- *
- *
- * 503
- *
- * |
- *
- *
- * Invalid floating point operation
- *
- * |
- *
- *
- * Division by 0, or another calculation that results in an overflow of the
- * defined value range.
- *
- * |
- *
- *
- *
- *
- * 504
- *
- * |
- *
- *
- * Parameter list error
- *
- * |
- *
- *
- * Function parameter is not valid, for example, text instead of a number, or a
- * domain reference instead of cell reference.
- *
- * |
- *
- *
- *
- *
- * 505
- *
- * |
- *
- *
- * Internal syntax error
- *
- * |
- *
- *
- * Not used
- *
- * |
- *
- *
- *
- *
- * 506
- *
- * |
- *
- *
- * Invalid semicolon
- *
- * |
- *
- *
- * Not used
- *
- * |
- *
- *
- *
- *
- * 507
- *
- * |
- *
- *
- * Error: Pair missing
- *
- * |
- *
- *
- * Not used
- *
- * |
- *
- *
- *
- *
- * 508
- *
- * |
- *
- *
- * Error: Pair missing
- *
- * |
- *
- *
- * Missing bracket, for example, closing brackets, but no opening brackets
- *
- * |
- *
- *
- *
- *
- * 509
- *
- * |
- *
- *
- * Missing operator
- *
- * |
- *
- *
- * Operator is missing, for example, "=2(3+4) * ", where the operator
- * between "2" and "(" is missing.
- *
- * |
- *
- *
- *
- *
- * 510
- *
- * |
- *
- *
- * Missing variable
- *
- * |
- *
- *
- * Variable is missing, for example when two operators are together
- * "=1+*2".
- *
- * |
- *
- *
- *
- *
- * 511
- *
- * |
- *
- *
- * Missing variable
- *
- * |
- *
- *
- * Function requires more variables than are provided, for example, AND() and
- * OR().
- *
- * |
- *
- *
- *
- *
- * 512
- *
- * |
- *
- *
- * Formula overflow
- *
- * |
- *
- *
- * Compiler: the total number of internal tokens, (that is, operators,
- * variables, brackets) in the formula exceeds 512. Interpreter: the
- * total number of matrices that the formula creates exceeds 150. This includes
- * basic functions that receive too large an array as a parameter (max. 0xFFFE,
- * for example, 65534 bytes).
- *
- * |
- *
- *
- *
- *
- * 513
- *
- * |
- *
- *
- * String overflow
- *
- * |
- *
- *
- * Compiler: an identifier in the formula exceeds 64 KB in size.
- * Interpreter: a result of a string operation exceeds 64 KB in size.
- *
- * |
- *
- *
- *
- *
- * 514
- *
- * |
- *
- *
- * Internal overflow
- *
- * |
- *
- *
- * Sort operation attempted on too much numerical data (max. 100000) or a
- * calculation stack overflow.
- *
- * |
- *
- *
- *
- *
- * 515
- *
- * |
- *
- *
- * Internal syntax error
- *
- * |
- *
- *
- * Not used
- *
- * |
- *
- *
- *
- *
- * 516
- *
- * |
- *
- *
- * Internal syntax error
- *
- * |
- *
- *
- * Matrix is expected on the calculation stack, but is not available.
- *
- * |
- *
- *
- *
- *
- * 517
- *
- * |
- *
- *
- * Internal syntax error
- *
- * |
- *
- *
- * Unknown code, for example, a document with a newer function is loaded in an
- * older version that does not contain the function.
- *
- * |
- *
- *
- *
- *
- * 518
- *
- * |
- *
- *
- * Internal syntax error
- *
- * |
- *
- *
- * Variable is not available
- *
- * |
- *
- *
- *
- *
- * 519
- *
- * |
- *
- *
- * No result (#VALUE is in the cell rather than Err:519!)
- *
- * |
- *
- *
- * Formula yields a value that does not corresponds to the definition, or a cell
- * that is referenced in the formula contains text instead of a number.
- *
- * |
- *
- *
- *
- *
- * 520
- *
- * |
- *
- *
- * Internal syntax error
- *
- * |
- *
- *
- * Compiler creates an unknown compiler code.
- *
- * |
- *
- *
- *
- *
- * 521
- *
- * |
- *
- *
- * Internal syntax error
- *
- * |
- *
- *
- * No result.
- *
- * |
- *
- *
- *
- *
- * 522
- *
- * |
- *
- *
- * Circular reference
- *
- * |
- *
- *
- * Formula refers directly or indirectly to itself and the iterations option is
- * not selected under Tools - Options - Table Document - Calculate.
- *
- * |
- *
- *
- *
- *
- * 523
- *
- * |
- *
- *
- * The calculation procedure does not converge
- *
- * |
- *
- *
- * Financial statistics function missed a targeted value or iterations of
- * circular references do not reach the minimum change within the maximum steps
- * that are set.
- *
- * |
- *
- *
- *
- *
- * 524
- *
- * |
- *
- *
- * invalid references
- * (instead of Err:524 cell contains #REF)
- *
- * |
- *
- *
- * Compiler: a column or row description name could not be resolved.
- * Interpreter: in a formula, the column, row, or sheet that contains a
- * referenced cell is missing.
- *
- * |
- *
- *
- *
- *
- * 525
- *
- * |
- *
- *
- * invalid names (instead of
- * Err:525 cell contains #NAME?)
- *
- * |
- *
- *
- * An identifier could not be evaluated, for example, no valid reference, no
- * valid domain name, no column/row label, no macro, incorrect decimal divider,
- * add-in not found.
- *
- * |
- *
- *
- *
- *
- * 526
- *
- * |
- *
- *
- * Internal syntax error
- *
- * |
- *
- *
- * Obsolete, no longer used, but could come from old documents if the result is
- * a formula from a domain.
- *
- * |
- *
- *
- *
- *
- * 527
- *
- * |
- *
- *
- * Internal overflow
- *
- * |
- *
- *
- * Interpreter: References, such as when a cell references a cell, are
- * too encapsulated.
- *
- * |
- *
- *
- *
*/
public class ErrorEval implements ValueEval {
private int errorCode;
- // Oo std error codes
- public static final ErrorEval ERROR_501 = new ErrorEval(501);
- public static final ErrorEval ERROR_502 = new ErrorEval(502);
+ public static final ErrorEval NAME_INVALID = new ErrorEval(525);
- public static final ErrorEval ERROR_503 = new ErrorEval(503);
-
- public static final ErrorEval ERROR_504 = new ErrorEval(504);
-
- public static final ErrorEval ERROR_505 = new ErrorEval(505);
-
- public static final ErrorEval ERROR_506 = new ErrorEval(506);
-
- public static final ErrorEval ERROR_507 = new ErrorEval(507);
-
- public static final ErrorEval ERROR_508 = new ErrorEval(508);
-
- public static final ErrorEval ERROR_509 = new ErrorEval(509);
-
- public static final ErrorEval ERROR_510 = new ErrorEval(510);
-
- public static final ErrorEval ERROR_511 = new ErrorEval(511);
-
- public static final ErrorEval ERROR_512 = new ErrorEval(512);
-
- public static final ErrorEval ERROR_513 = new ErrorEval(513);
-
- public static final ErrorEval ERROR_514 = new ErrorEval(514);
-
- public static final ErrorEval ERROR_515 = new ErrorEval(515);
-
- public static final ErrorEval ERROR_516 = new ErrorEval(516);
-
- public static final ErrorEval ERROR_517 = new ErrorEval(517);
-
- public static final ErrorEval ERROR_518 = new ErrorEval(518);
-
- public static final ErrorEval ERROR_519 = new ErrorEval(519);
-
- public static final ErrorEval ERROR_520 = new ErrorEval(520);
-
- public static final ErrorEval ERROR_521 = new ErrorEval(521);
-
- public static final ErrorEval ERROR_522 = new ErrorEval(522);
-
- public static final ErrorEval ERROR_523 = new ErrorEval(523);
-
- public static final ErrorEval ERROR_524 = new ErrorEval(524);
-
- public static final ErrorEval ERROR_525 = new ErrorEval(525);
-
- public static final ErrorEval ERROR_526 = new ErrorEval(526);
-
- public static final ErrorEval ERROR_527 = new ErrorEval(527);
-
- public static final ErrorEval NAME_INVALID = ERROR_525;
-
- public static final ErrorEval VALUE_INVALID = ERROR_519;
+ public static final ErrorEval VALUE_INVALID = new ErrorEval(519);
// Non std error codes
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/MultiplyEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/MultiplyEval.java
index e55d53226..bd4d0c539 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/MultiplyEval.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/MultiplyEval.java
@@ -22,6 +22,7 @@ public class MultiplyEval extends NumericOperationEval {
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
public MultiplyEval(Ptg ptg) {
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumberEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumberEval.java
index 764c59f20..9ca0d7468 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumberEval.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumberEval.java
@@ -13,6 +13,8 @@ import org.apache.poi.hssf.record.formula.Ptg;
*
*/
public class NumberEval implements NumericValueEval, StringValueEval {
+
+ public static final NumberEval ZERO = new NumberEval(0);
private double value;
private String stringValue;
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/PowerEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/PowerEval.java
index 641cf10ae..ef34d21f5 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/PowerEval.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/PowerEval.java
@@ -22,6 +22,7 @@ public class PowerEval extends NumericOperationEval {
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
public PowerEval(Ptg ptg) {
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RelationalOperationEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RelationalOperationEval.java
index de5004d92..b07f70879 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RelationalOperationEval.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RelationalOperationEval.java
@@ -38,7 +38,7 @@ public abstract class RelationalOperationEval implements OperationEval {
switch (operands.length) {
default:
- retval.ee = ErrorEval.ERROR_520;
+ retval.ee = ErrorEval.VALUE_INVALID;
break;
case 2:
internalDoEvaluate(operands, srcRow, srcCol, retval, 0);
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringEval.java
index f8b4cca00..9f7869c9a 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringEval.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringEval.java
@@ -13,6 +13,8 @@ import org.apache.poi.hssf.record.formula.StringPtg;
*/
public class StringEval implements StringValueEval {
+ public static final StringEval EMPTY_INSTANCE = new StringEval("");
+
private String value;
public StringEval(Ptg ptg) {
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/SubtractEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/SubtractEval.java
index 6b2c9899c..8b8208db6 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/SubtractEval.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/SubtractEval.java
@@ -22,6 +22,7 @@ public class SubtractEval extends NumericOperationEval {
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
public SubtractEval(Ptg ptg) {
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryMinusEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryMinusEval.java
index 84eececce..793290a04 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryMinusEval.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryMinusEval.java
@@ -21,6 +21,7 @@ public class UnaryMinusEval extends NumericOperationEval {
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryPlusEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryPlusEval.java
index 5b311661f..556b3f8de 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryPlusEval.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryPlusEval.java
@@ -18,7 +18,7 @@ public class UnaryPlusEval implements OperationEval /*extends NumericOperationEv
/*
* COMMENT FOR COMMENTED CODE IN THIS FILE
*
- * The loser who programmed this in excel didnt care to
+ * In excel the programmer seems to not have cared to
* think about how strings were handled in other numeric
* operations when he/she was implementing this operation :P
*
@@ -27,10 +27,8 @@ public class UnaryPlusEval implements OperationEval /*extends NumericOperationEv
* Q. If the formula -"hello" evaluates to #VALUE! in excel, what should
* the formula +"hello" evaluate to?
*
- * A. +"hello" evaluates to "hello"
+ * A. +"hello" evaluates to "hello" (what the...?)
*
- * DO NOT remove the commented code (In memory of the excel
- * programmer who implemented the UnaryPlus operation :)
*/
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ValueEvalToNumericXlator.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ValueEvalToNumericXlator.java
index fb089227e..3111a4215 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ValueEvalToNumericXlator.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ValueEvalToNumericXlator.java
@@ -10,25 +10,33 @@ package org.apache.poi.hssf.record.formula.eval;
*/
public class ValueEvalToNumericXlator {
- public static final short STRING_IS_PARSED = 0x0001;
- public static final short BOOL_IS_PARSED = 0x0002;
+ public static final int STRING_IS_PARSED = 0x0001;
+ public static final int BOOL_IS_PARSED = 0x0002;
+ public static final int BLANK_IS_PARSED = 0x0004; // => blanks are not ignored, converted to 0
- public static final short REF_STRING_IS_PARSED = 0x0004;
- public static final short REF_BOOL_IS_PARSED = 0x0008;
+ public static final int REF_STRING_IS_PARSED = 0x0008;
+ public static final int REF_BOOL_IS_PARSED = 0x0010;
+ public static final int REF_BLANK_IS_PARSED = 0x0020;
- public static final short EVALUATED_REF_STRING_IS_PARSED = 0x0010;
- public static final short EVALUATED_REF_BOOL_IS_PARSED = 0x0020;
+ public static final int EVALUATED_REF_STRING_IS_PARSED = 0x0040;
+ public static final int EVALUATED_REF_BOOL_IS_PARSED = 0x0080;
+ public static final int EVALUATED_REF_BLANK_IS_PARSED = 0x0100;
- public static final short STRING_TO_BOOL_IS_PARSED = 0x0040;
- public static final short REF_STRING_TO_BOOL_IS_PARSED = 0x0080;
+ public static final int STRING_TO_BOOL_IS_PARSED = 0x0200;
+ public static final int REF_STRING_TO_BOOL_IS_PARSED = 0x0400;
- public static final short STRING_IS_INVALID_VALUE = 0x0100;
- public static final short REF_STRING_IS_INVALID_VALUE = 0x200;
+ public static final int STRING_IS_INVALID_VALUE = 0x0800;
+ public static final int REF_STRING_IS_INVALID_VALUE = 0x1000;
- private final short flags;
+// public static final int BOOL_IS_BLANK = 0x2000;
+// public static final int REF_BOOL_IS_BLANK = 0x4000;
+// public static final int STRING_IS_BLANK = 0x8000;
+// public static final int REF_STRING_IS_BLANK = 0x10000;
+
+ private final int flags;
- public ValueEvalToNumericXlator(short flags) {
+ public ValueEvalToNumericXlator(int flags) {
this.flags = flags;
}
@@ -52,23 +60,20 @@ public class ValueEvalToNumericXlator {
}
// booleval
- else if (((flags | BOOL_IS_PARSED) > 0) && eval instanceof BoolEval) {
- retval = (NumericValueEval) eval;
+ else if (eval instanceof BoolEval) {
+ retval = ((flags & BOOL_IS_PARSED) > 0)
+ ? (NumericValueEval) eval
+ : xlateBlankEval(BLANK_IS_PARSED);
}
// stringeval
else if (eval instanceof StringEval) {
- retval = handleStringEval((StringEval) eval);
+ retval = xlateStringEval((StringEval) eval); // TODO: recursive call needed
}
// refeval
else if (eval instanceof RefEval) {
- retval = handleRefEval((RefEval) eval);
- }
-
- //blankeval
- else if (eval instanceof BlankEval) {
- retval = eval;
+ retval = xlateRefEval((RefEval) eval);
}
// erroreval
@@ -76,40 +81,55 @@ public class ValueEvalToNumericXlator {
retval = eval;
}
+ else if (eval instanceof BlankEval) {
+ retval = xlateBlankEval(BLANK_IS_PARSED);
+ }
+
// probably AreaEval? then not acceptable.
else {
throw new RuntimeException("Invalid ValueEval type passed for conversion: " + eval.getClass());
}
+
return retval;
}
+ /**
+ * no args are required since BlankEval has only one
+ * instance. If flag is set, a zero
+ * valued numbereval is returned, else BlankEval.INSTANCE
+ * is returned.
+ * @return
+ */
+ private ValueEval xlateBlankEval(int flag) {
+ return ((flags & flag) > 0)
+ ? (ValueEval) NumberEval.ZERO
+ : BlankEval.INSTANCE;
+ }
+
/**
* uses the relevant flags to decode the supplied RefVal
* @param eval
* @return
*/
- private ValueEval handleRefEval(RefEval reval) {
+ private ValueEval xlateRefEval(RefEval reval) {
ValueEval retval = null;
ValueEval eval = (ValueEval) reval.getInnerValueEval();
// most common case - least worries :)
if (eval instanceof NumberEval) {
- retval = (NumberEval) eval; // the cast is correct :)
+ retval = (NumberEval) eval;
}
// booleval
- else if (((flags | REF_BOOL_IS_PARSED) > 0) && eval instanceof BoolEval) {
- retval = (NumericValueEval) eval;
+ else if (eval instanceof BoolEval) {
+ retval = ((flags & REF_BOOL_IS_PARSED) > 0)
+ ? (ValueEval) eval
+ : BlankEval.INSTANCE;
}
// stringeval
else if (eval instanceof StringEval) {
- retval = handleRefStringEval((StringEval) eval);
- }
-
- //blankeval
- else if (eval instanceof BlankEval) {
- retval = eval;
+ retval = xlateRefStringEval((StringEval) eval);
}
// erroreval
@@ -117,10 +137,24 @@ public class ValueEvalToNumericXlator {
retval = eval;
}
- // probably AreaEval or another RefEval? then not acceptable.
- else {
+ // refeval
+ else if (eval instanceof RefEval) {
+ RefEval re = (RefEval) eval;
+ retval = xlateRefEval(re);
+ }
+
+ else if (eval instanceof BlankEval) {
+ retval = xlateBlankEval(reval.isEvaluated() ? EVALUATED_REF_BLANK_IS_PARSED : REF_BLANK_IS_PARSED);
+ }
+
+ // probably AreaEval ? then not acceptable.
+ else {
throw new RuntimeException("Invalid ValueEval type passed for conversion: " + eval.getClass());
}
+
+
+
+
return retval;
}
@@ -129,20 +163,29 @@ public class ValueEvalToNumericXlator {
* @param eval
* @return
*/
- private ValueEval handleStringEval(StringEval eval) {
+ private ValueEval xlateStringEval(StringEval eval) {
ValueEval retval = null;
- if ((flags | STRING_IS_PARSED) > 0) {
- StringEval sve = (StringEval) eval;
- String s = sve.getStringValue();
+ if ((flags & STRING_IS_PARSED) > 0) {
+ String s = eval.getStringValue();
try {
double d = Double.parseDouble(s);
retval = new NumberEval(d);
}
- catch (Exception e) { retval = ErrorEval.VALUE_INVALID; }
+ catch (Exception e) {
+ if ((flags & STRING_TO_BOOL_IS_PARSED) > 0) {
+ try {
+ boolean b = Boolean.getBoolean(s);
+ retval = b ? BoolEval.TRUE : BoolEval.FALSE;
+ }
+ catch (Exception e2) { retval = ErrorEval.VALUE_INVALID; }
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
}
- else if ((flags | STRING_TO_BOOL_IS_PARSED) > 0) {
- StringEval sve = (StringEval) eval;
- String s = sve.getStringValue();
+ else if ((flags & STRING_TO_BOOL_IS_PARSED) > 0) {
+ String s = eval.getStringValue();
try {
boolean b = Boolean.getBoolean(s);
retval = b ? BoolEval.TRUE : BoolEval.FALSE;
@@ -151,13 +194,13 @@ public class ValueEvalToNumericXlator {
}
// strings are errors?
- else if ((flags | STRING_IS_INVALID_VALUE) > 0) {
+ else if ((flags & STRING_IS_INVALID_VALUE) > 0) {
retval = ErrorEval.VALUE_INVALID;
}
// ignore strings
else {
- retval = BlankEval.INSTANCE;
+ retval = xlateBlankEval(BLANK_IS_PARSED);
}
return retval;
}
@@ -167,18 +210,29 @@ public class ValueEvalToNumericXlator {
* @param eval
* @return
*/
- private ValueEval handleRefStringEval(StringEval eval) {
+ private ValueEval xlateRefStringEval(StringEval eval) {
ValueEval retval = null;
- if ((flags | REF_STRING_IS_PARSED) > 0) {
+ if ((flags & REF_STRING_IS_PARSED) > 0) {
StringEval sve = (StringEval) eval;
String s = sve.getStringValue();
try {
double d = Double.parseDouble(s);
retval = new NumberEval(d);
}
- catch (Exception e) { retval = ErrorEval.VALUE_INVALID; }
+ catch (Exception e) {
+ if ((flags & REF_STRING_TO_BOOL_IS_PARSED) > 0) {
+ try {
+ boolean b = Boolean.getBoolean(s);
+ retval = b ? BoolEval.TRUE : BoolEval.FALSE;
+ }
+ catch (Exception e2) { retval = ErrorEval.VALUE_INVALID; }
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
}
- else if ((flags | REF_STRING_TO_BOOL_IS_PARSED) > 0) {
+ else if ((flags & REF_STRING_TO_BOOL_IS_PARSED) > 0) {
StringEval sve = (StringEval) eval;
String s = sve.getStringValue();
try {
@@ -189,11 +243,11 @@ public class ValueEvalToNumericXlator {
}
// strings are errors?
- else if ((flags | REF_STRING_IS_INVALID_VALUE) > 0) {
+ else if ((flags & REF_STRING_IS_INVALID_VALUE) > 0) {
retval = ErrorEval.VALUE_INVALID;
}
- // ignore strings
+ // strings are blanks
else {
retval = BlankEval.INSTANCE;
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Abs.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Abs.java
index 9f29615ae..31960a9b9 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Abs.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Abs.java
@@ -10,7 +10,6 @@ import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
@@ -18,19 +17,6 @@ import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
*/
public class Abs extends NumericFunction {
- private static final ValueEvalToNumericXlator NUM_XLATOR =
- new ValueEvalToNumericXlator((short)
- ( ValueEvalToNumericXlator.BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
- | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_PARSED
- ));
-
- protected ValueEvalToNumericXlator getXlator() {
- return NUM_XLATOR;
- }
-
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
double d = 0;
ValueEval retval = null;
@@ -54,7 +40,10 @@ public class Abs extends NumericFunction {
}
if (retval == null) {
- retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(Math.abs(d));
+ d = Math.abs(d);
+ retval = (Double.isNaN(d))
+ ? (ValueEval) ErrorEval.VALUE_INVALID
+ : new NumberEval(d);
}
return retval;
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Acos.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Acos.java
index eb8e69301..dc6030ca9 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Acos.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Acos.java
@@ -10,33 +10,20 @@ import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *
+ *
*/
public class Acos extends NumericFunction {
-
- private static final ValueEvalToNumericXlator NUM_XLATOR =
- new ValueEvalToNumericXlator((short)
- ( ValueEvalToNumericXlator.BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
- | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_PARSED
- ));
-
- protected ValueEvalToNumericXlator getXlator() {
- return NUM_XLATOR;
- }
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
double d = 0;
ValueEval retval = null;
-
+
switch (operands.length) {
default:
+ retval = ErrorEval.VALUE_INVALID;
break;
case 1:
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
@@ -51,10 +38,12 @@ public class Acos extends NumericFunction {
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
d = Math.acos(d);
- retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ retval = (Double.isNaN(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
}
return retval;
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Acosh.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Acosh.java
index 570e10932..1ff637071 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Acosh.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Acosh.java
@@ -9,38 +9,25 @@ import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- * Support for hyperbolic trig functions was added as a part of
- * Java distribution only in JDK1.5. This class uses custom
+ * Support for hyperbolic trig functions was added as a part of
+ * Java distribution only in JDK1.5. This class uses custom
* naive implementation based on formulas at:
* http://www.math2.org/math/trig/hyperbolics.htm
* These formulas seem to agree with excel's implementation.
- *
+ *
*/
public class Acosh extends NumericFunction {
-
- private static final ValueEvalToNumericXlator NUM_XLATOR =
- new ValueEvalToNumericXlator((short)
- ( ValueEvalToNumericXlator.BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
- | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_PARSED
- ));
-
- protected ValueEvalToNumericXlator getXlator() {
- return NUM_XLATOR;
- }
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
double d = 0;
ValueEval retval = null;
-
+
switch (operands.length) {
default:
+ retval = ErrorEval.VALUE_INVALID;
break;
case 1:
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
@@ -49,10 +36,12 @@ public class Acosh extends NumericFunction {
d = ne.getNumberValue();
}
}
-
+
if (retval == null) {
- d = Math.log(Math.sqrt(Math.pow(d, 2) - 1) + d);
- retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.NUM_ERROR : new NumberEval(d);
+ d = MathX.acosh(d);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
}
return retval;
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Asin.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Asin.java
index ebf169b93..a4e005e91 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Asin.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Asin.java
@@ -10,33 +10,20 @@ import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *
+ *
*/
public class Asin extends NumericFunction {
-
- private static final ValueEvalToNumericXlator NUM_XLATOR =
- new ValueEvalToNumericXlator((short)
- ( ValueEvalToNumericXlator.BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
- | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_PARSED
- ));
-
- protected ValueEvalToNumericXlator getXlator() {
- return NUM_XLATOR;
- }
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
double d = 0;
ValueEval retval = null;
-
+
switch (operands.length) {
default:
+ retval = ErrorEval.VALUE_INVALID;
break;
case 1:
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
@@ -51,10 +38,12 @@ public class Asin extends NumericFunction {
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
d = Math.asin(d);
- retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ retval = (Double.isNaN(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
}
return retval;
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Asinh.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Asinh.java
index b33f12c72..12c7bdc06 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Asinh.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Asinh.java
@@ -10,38 +10,26 @@ import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- * Support for hyperbolic trig functions was added as a part of
- * Java distribution only in JDK1.5. This class uses custom
+ * Support for hyperbolic trig functions was added as a part of
+ * Java distribution only in JDK1.5. This class uses custom
* naive implementation based on formulas at:
* http://www.math2.org/math/trig/hyperbolics.htm
* These formulas seem to agree with excel's implementation.
- *
+ *
*/
public class Asinh extends NumericFunction {
+
- private static final ValueEvalToNumericXlator NUM_XLATOR =
- new ValueEvalToNumericXlator((short)
- ( ValueEvalToNumericXlator.BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
- | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_PARSED
- ));
-
- protected ValueEvalToNumericXlator getXlator() {
- return NUM_XLATOR;
- }
-
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
double d = 0;
ValueEval retval = null;
-
+
switch (operands.length) {
default:
+ retval = ErrorEval.VALUE_INVALID;
break;
case 1:
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
@@ -56,9 +44,9 @@ public class Asinh extends NumericFunction {
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
- d = Math.log(Math.sqrt(Math.pow(d, 2) + 1) + d);
+ d = MathX.asinh(d);
retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.NUM_ERROR : new NumberEval(d);
}
return retval;
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan.java
index a156c0f2d..6fcc9c3c2 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan.java
@@ -10,33 +10,20 @@ import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *
+ *
*/
public class Atan extends NumericFunction {
-
- private static final ValueEvalToNumericXlator NUM_XLATOR =
- new ValueEvalToNumericXlator((short)
- ( ValueEvalToNumericXlator.BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
- | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_PARSED
- ));
-
- protected ValueEvalToNumericXlator getXlator() {
- return NUM_XLATOR;
- }
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
double d = 0;
ValueEval retval = null;
-
+
switch (operands.length) {
default:
+ retval = ErrorEval.VALUE_INVALID;
break;
case 1:
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
@@ -51,10 +38,12 @@ public class Atan extends NumericFunction {
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
d = Math.atan(d);
- retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ retval = (Double.isNaN(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
}
return retval;
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan2.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan2.java
index 89e6b0904..fa1afbf42 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan2.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan2.java
@@ -10,34 +10,21 @@ import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *
+ *
*/
public class Atan2 extends NumericFunction {
-
- private static final ValueEvalToNumericXlator NUM_XLATOR =
- new ValueEvalToNumericXlator((short)
- ( ValueEvalToNumericXlator.BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
- | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_PARSED
- ));
-
- protected ValueEvalToNumericXlator getXlator() {
- return NUM_XLATOR;
- }
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
double d0 = 0;
double d1 = 0;
ValueEval retval = null;
-
+
switch (operands.length) {
default:
+ retval = ErrorEval.VALUE_INVALID;
break;
case 2:
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
@@ -51,7 +38,7 @@ public class Atan2 extends NumericFunction {
else {
retval = ErrorEval.NUM_ERROR;
}
-
+
if (retval == null) {
ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
if (ve instanceof NumericValueEval) {
@@ -66,10 +53,14 @@ public class Atan2 extends NumericFunction {
}
}
}
-
+
if (retval == null) {
- double d = (d0 == d1 && d1 == 0) ? Double.NaN : Math.atan2(d1, d0);
- retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ double d = (d0 == d1 && d1 == 0)
+ ? Double.NaN
+ : Math.atan2(d1, d0);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
}
return retval;
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atanh.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atanh.java
index 704918541..a17a9aff5 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atanh.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atanh.java
@@ -10,38 +10,25 @@ import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- * Support for hyperbolic trig functions was added as a part of
- * Java distribution only in JDK1.5. This class uses custom
+ * Support for hyperbolic trig functions was added as a part of
+ * Java distribution only in JDK1.5. This class uses custom
* naive implementation based on formulas at:
* http://www.math2.org/math/trig/hyperbolics.htm
* These formulas seem to agree with excel's implementation.
- *
+ *
*/
public class Atanh extends NumericFunction {
-
- private static final ValueEvalToNumericXlator NUM_XLATOR =
- new ValueEvalToNumericXlator((short)
- ( ValueEvalToNumericXlator.BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
- | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_PARSED
- ));
-
- protected ValueEvalToNumericXlator getXlator() {
- return NUM_XLATOR;
- }
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
double d = 0;
ValueEval retval = null;
-
+
switch (operands.length) {
default:
+ retval = ErrorEval.VALUE_INVALID;
break;
case 1:
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
@@ -56,9 +43,9 @@ public class Atanh extends NumericFunction {
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
- d = Math.log((1 + d)/(1 - d)) / 2;
+ d = MathX.atanh(d);
retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.NUM_ERROR : new NumberEval(d);
}
return retval;
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Avedev.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Avedev.java
index 850e40e3f..98e5bd70b 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Avedev.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Avedev.java
@@ -4,10 +4,58 @@
*/
package org.apache.poi.hssf.record.formula.functions;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
-public class Avedev extends DefaultFunctionImpl {
+public class Avedev extends MultiOperandNumericFunction {
+ private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
+ new ValueEvalToNumericXlator((short) (0
+ // ValueEvalToNumericXlator.BOOL_IS_PARSED
+ //| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ //| ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ //| ValueEvalToNumericXlator.REF_STRING_IS_PARSED
+ //| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ //| ValueEvalToNumericXlator.STRING_TO_BOOL_IS_PARSED
+ //| ValueEvalToNumericXlator.REF_STRING_TO_BOOL_IS_PARSED
+ //| ValueEvalToNumericXlator.STRING_IS_INVALID_VALUE
+ //| ValueEvalToNumericXlator.REF_STRING_IS_INVALID_VALUE
+ | ValueEvalToNumericXlator.EVALUATED_REF_BLANK_IS_PARSED
+ ));
+
+ /**
+ * this is the default impl for the factory method getXlator
+ * of the super class NumericFunction. Subclasses can override this method
+ * if they desire to return a different ValueEvalToNumericXlator instance
+ * than the default.
+ */
+ protected ValueEvalToNumericXlator getXlator() {
+ return DEFAULT_NUM_XLATOR;
+ }
+
+
+
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ double[] values = getNumberArray(operands, srcCellRow, srcCellCol);
+ if (values == null) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ else {
+ double d = StatsLib.avedev(values);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Average.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Average.java
index 90accd5cc..879ba7829 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Average.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Average.java
@@ -4,10 +4,58 @@
*/
package org.apache.poi.hssf.record.formula.functions;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
-public class Average extends DefaultFunctionImpl {
+public class Average extends MultiOperandNumericFunction {
+ private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
+ new ValueEvalToNumericXlator((short) (0
+ // ValueEvalToNumericXlator.BOOL_IS_PARSED
+ //| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ //| ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ //| ValueEvalToNumericXlator.REF_STRING_IS_PARSED
+ //| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ //| ValueEvalToNumericXlator.STRING_TO_BOOL_IS_PARSED
+ //| ValueEvalToNumericXlator.REF_STRING_TO_BOOL_IS_PARSED
+ //| ValueEvalToNumericXlator.STRING_IS_INVALID_VALUE
+ //| ValueEvalToNumericXlator.REF_STRING_IS_INVALID_VALUE
+ | ValueEvalToNumericXlator.EVALUATED_REF_BLANK_IS_PARSED
+ ));
+
+ /**
+ * this is the default impl for the factory method getXlator
+ * of the super class NumericFunction. Subclasses can override this method
+ * if they desire to return a different ValueEvalToNumericXlator instance
+ * than the default.
+ */
+ protected ValueEvalToNumericXlator getXlator() {
+ return DEFAULT_NUM_XLATOR;
+ }
+
+
+
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ double[] values = getNumberArray(operands, srcCellRow, srcCellCol);
+ if (values == null) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ else {
+ double d = MathX.average(values);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Averagea.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Averagea.java
index 719b1b668..d87194ed1 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Averagea.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Averagea.java
@@ -4,10 +4,10 @@
*/
package org.apache.poi.hssf.record.formula.functions;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
public class Averagea extends DefaultFunctionImpl {
-
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Ceiling.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Ceiling.java
index ee7313785..64ba61236 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Ceiling.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Ceiling.java
@@ -1,14 +1,66 @@
/*
- * Created on May 6, 2005
+ * Created on May 15, 2005
*
*/
package org.apache.poi.hssf.record.formula.functions;
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
/**
- * @author
- *
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
*/
-public class Ceiling extends DefaultFunctionImpl {
-
+public class Ceiling extends NumericFunction {
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d0 = 0;
+ double d1 = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 2:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d0 = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+
+ if (retval == null) {
+ ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d1 = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+ }
+
+ if (retval == null) {
+ double d = MathX.ceiling(d0, d1);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+ return retval;
+ }
+
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Column.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Column.java
index fa04a3ce0..0bf4b7279 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Column.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Column.java
@@ -4,10 +4,50 @@
*/
package org.apache.poi.hssf.record.formula.functions;
+import org.apache.poi.hssf.record.formula.eval.AreaEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.RefEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
/**
* @author
*
*/
public class Column extends DefaultFunctionImpl {
+ public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ int cnum = -1;
+
+ switch (evals.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ case 1:
+ if (evals[0] instanceof AreaEval) {
+ AreaEval ae = (AreaEval) evals[0];
+ cnum = ae.getFirstColumn();
+ }
+ else if (evals[0] instanceof RefEval) {
+ RefEval re = (RefEval) evals[0];
+ cnum = re.getColumn();
+ }
+ else { // anything else is not valid argument
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ break;
+ case 0:
+ cnum = srcCellCol;
+ }
+
+ if (retval == null) {
+ retval = (cnum >= 0)
+ ? new NumberEval(cnum + 1) // +1 since excel colnums are 1 based
+ : (ValueEval) ErrorEval.VALUE_INVALID;
+ }
+
+ return retval;
+ }
+
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Combin.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Combin.java
index 1360d9a66..82e951090 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Combin.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Combin.java
@@ -4,10 +4,68 @@
*/
package org.apache.poi.hssf.record.formula.functions;
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
-public class Combin extends DefaultFunctionImpl {
+public class Combin extends NumericFunction {
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d0 = 0;
+ double d1 = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 2:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d0 = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+
+ if (retval == null) {
+ ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d1 = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+ }
+
+ if (retval == null) {
+ if (d0 > Integer.MAX_VALUE || d1 > Integer.MAX_VALUE) {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ else {
+ double d = MathX.nChooseK((int) d0, (int) d1);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+ }
+ return retval;
+ }
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Concatenate.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Concatenate.java
index ed920f583..beaa32d4e 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Concatenate.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Concatenate.java
@@ -4,10 +4,41 @@
*/
package org.apache.poi.hssf.record.formula.functions;
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+import org.apache.poi.hssf.record.formula.eval.StringValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
-public class Concatenate extends DefaultFunctionImpl {
+public class Concatenate extends TextFunction {
+
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ StringBuffer sb = new StringBuffer();
+
+ for (int i=0, iSize=operands.length; i