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);
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
public AddEval(Ptg ptg) {
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
public DivideEval(Ptg ptg) {
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
- * Error code reference from OpenOffice documentation: <br/><TABLE WIDTH=575
- * BORDER=1 CELLPADDING=2 CELLSPACING=0 BGCOLOR="#ffffff"> <COL WIDTH=42> <COL
- * WIDTH=118> <COL WIDTH=401>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="tablehead" ALIGN=LEFT>
- * Error Code
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="tablehead" ALIGN=LEFT>
- * Message
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="tablehead" ALIGN=LEFT>
- * Explanation
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 501
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Invalid character
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Character in a formula is not valid, for example, "=1Eq" instead of
- * "=1E2".
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 502
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Invalid argument
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Function argument is not valid, for example, a negative number for the root
- * function.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 503
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Invalid floating point operation
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Division by 0, or another calculation that results in an overflow of the
- * defined value range.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 504
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Parameter list error
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Function parameter is not valid, for example, text instead of a number, or a
- * domain reference instead of cell reference.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 505
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Internal syntax error
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Not used
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 506
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Invalid semicolon
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Not used
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 507
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Error: Pair missing
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Not used
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 508
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Error: Pair missing
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Missing bracket, for example, closing brackets, but no opening brackets
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 509
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Missing operator
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Operator is missing, for example, "=2(3+4) * ", where the operator
- * between "2" and "(" is missing.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 510
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Missing variable
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Variable is missing, for example when two operators are together
- * "=1+*2".
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 511
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Missing variable
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Function requires more variables than are provided, for example, AND() and
- * OR().
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 512
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Formula overflow
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * <B>Compiler: </B> the total number of internal tokens, (that is, operators,
- * variables, brackets) in the formula exceeds 512. <B>Interpreter: </B> 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).
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 513
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * String overflow
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * <B>Compiler: </B> an identifier in the formula exceeds 64 KB in size.
- * <B>Interpreter: </B> a result of a string operation exceeds 64 KB in size.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 514
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Internal overflow
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Sort operation attempted on too much numerical data (max. 100000) or a
- * calculation stack overflow.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 515
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Internal syntax error
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Not used
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 516
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Internal syntax error
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Matrix is expected on the calculation stack, but is not available.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 517
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Internal syntax error
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Unknown code, for example, a document with a newer function is loaded in an
- * older version that does not contain the function.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 518
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Internal syntax error
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Variable is not available
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 519
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * No result (#VALUE is in the cell rather than Err:519!)
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 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.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 520
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Internal syntax error
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Compiler creates an unknown compiler code.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 521
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Internal syntax error
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * No result.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 522
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Circular reference
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Formula refers directly or indirectly to itself and the iterations option is
- * not selected under Tools - Options - Table Document - Calculate.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 523
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * The calculation procedure does not converge
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 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.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 524
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * <A NAME="kw66944_5"> </A><A NAME="kw66944_4"> </A> invalid references
- * (instead of Err:524 cell contains #REF)
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * <B>Compiler: </B> a column or row description name could not be resolved.
- * <B>Interpreter: </B> in a formula, the column, row, or sheet that contains a
- * referenced cell is missing.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 525
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * <A NAME="kw66944_3"> </A><A NAME="kw66944_2"> </A> invalid names (instead of
- * Err:525 cell contains #NAME?)
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 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.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 526
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Internal syntax error
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Obsolete, no longer used, but could come from old documents if the result is
- * a formula from a domain.
- * </P>
- * </TD>
- * </TR>
- * <TR VALIGN=TOP>
- * <TD WIDTH=42 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * 527
- * </P>
- * </TD>
- * <TD WIDTH=118 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * Internal overflow
- * </P>
- * </TD>
- * <TD WIDTH=401 BGCOLOR="#ffffff">
- * <P CLASS="textintable" ALIGN=LEFT>
- * <B>Interpreter: </B>References, such as when a cell references a cell, are
- * too encapsulated.
- * </P>
- * </TD>
- * </TR>
- * </TABLE>
- *
*/
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
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
public MultiplyEval(Ptg ptg) {
*
*/
public class NumberEval implements NumericValueEval, StringValueEval {
+
+ public static final NumberEval ZERO = new NumberEval(0);
private double value;
private String stringValue;
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
public PowerEval(Ptg ptg) {
switch (operands.length) {
default:
- retval.ee = ErrorEval.ERROR_520;
+ retval.ee = ErrorEval.VALUE_INVALID;
break;
case 2:
internalDoEvaluate(operands, srcRow, srcCol, retval, 0);
*/
public class StringEval implements StringValueEval {
+ public static final StringEval EMPTY_INSTANCE = new StringEval("");
+
private String value;
public StringEval(Ptg ptg) {
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
public SubtractEval(Ptg ptg) {
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
));
/*
* 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
*
* 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 :)
*/
*/
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;
}
}
// 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
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
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;
}
* @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;
}
// 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;
}
* @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 {
}
// 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;
}
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 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;
}
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;
}
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);
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;
}
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);
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;
}
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);
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;
}
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);
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;
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);
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;
}
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);
else {
retval = ErrorEval.NUM_ERROR;
}
-
+
if (retval == null) {
ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
if (ve instanceof NumericValueEval) {
}
}
}
-
+
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;
}
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);
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;
*/
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;
+ }
}
*/
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;
+ }
}
*/
package org.apache.poi.hssf.record.formula.functions;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
public class Averagea extends DefaultFunctionImpl {
-
}
/*
- * 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;
+ }
+
}
*/
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;
+ }
+
}
*/
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;
+ }
}
*/
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<iSize; i++) {
+ ValueEval ve = singleOperandEvaluate(operands[i], srcCellRow, srcCellCol);
+ if (ve instanceof StringValueEval) {
+ StringValueEval sve = (StringValueEval) ve;
+ sb.append(sve.getStringValue());
+ }
+ else if (ve instanceof BlankEval) {}
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ }
+ }
+
+ if (retval == null) {
+ retval = new StringEval(sb.toString());
+ }
+
+ return retval;
+ }
}
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 Cos 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
d = Math.cos(d);
retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
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 Cosh 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
- double ePowX = Math.pow(E, d);
- double ePowNegX = Math.pow(E, -d);
- d = (ePowX + ePowNegX) / 2;
+ d = MathX.cosh(d);
retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
}
return retval;
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 Degrees 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;
*/
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 Devsq extends DefaultFunctionImpl {
+public class Devsq 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.devsq(values);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
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 Dollar 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
}
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 Even 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;
*/
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.BoolEval;
+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 Exact extends DefaultFunctionImpl {
+public class Exact extends TextFunction {
+
+
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ String s0 = null;
+ String s1 = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 2:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
+ if (ve instanceof StringValueEval) {
+ StringValueEval sve = (StringValueEval) ve;
+ s0 = sve.getStringValue();
+ }
+ else if (ve instanceof BlankEval) {
+ s0 = StringEval.EMPTY_INSTANCE.getStringValue();
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ }
+ if (retval == null) {
+ ve = singleOperandEvaluate(operands[1], srcCellRow, srcCellCol);
+ if (ve instanceof StringValueEval) {
+ StringValueEval sve = (StringValueEval) ve;
+ s1 = sve.getStringValue();
+ }
+ else if (ve instanceof BlankEval) {
+ s1 = StringEval.EMPTY_INSTANCE.getStringValue();
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ }
+ }
+ }
+
+ if (retval == null) {
+ boolean b = s0.equals(s1);
+ retval = b ? BoolEval.TRUE : BoolEval.FALSE;
+ }
+
+ return retval;
+ }
}
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 Exp 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
d = Math.pow(E, d);
retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
/*
- * Created on May 15, 2005
+ * Created on May 22, 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 Fact extends DefaultFunctionImpl {
+public class Fact extends NumericFunction {
+
+ 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);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ if (d < Integer.MAX_VALUE && d >= 0) {
+ d = MathX.factorial((int) d);
+ retval = (Double.isNaN(d))
+ ? (ValueEval) ErrorEval.VALUE_INVALID
+ : (Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+ return retval;
+ }
}
*/
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 Floor extends DefaultFunctionImpl {
+public class Floor 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.floor(d0, d1);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+ return retval;
+ }
}
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 Int 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
if (d < 0) {
d = Math.round(d-0.5);
}
- retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval((long) d);
+ retval = (Double.isNaN(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval((long) d);
}
return retval;
}
*/
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.BoolEval;
+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.RefEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
-public class IsError extends DefaultFunctionImpl {
+public class IsError implements Function {
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ boolean b = false;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ if (operands[0] instanceof ErrorEval) {
+ b = true;
+ }
+ else if (operands[0] instanceof AreaEval) {
+ AreaEval ae = (AreaEval) operands[0];
+ if (ae.contains(srcCellRow, srcCellCol)) { // circular ref!
+ retval = ErrorEval.CIRCULAR_REF_ERROR;
+ }
+ else if (ae.isRow()) {
+ if (ae.containsColumn(srcCellCol)) {
+ ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCellCol);
+ if (ve instanceof RefEval)
+ b = ((RefEval) ve).getInnerValueEval() instanceof ErrorEval;
+ else
+ b = (ve instanceof ErrorEval);
+ }
+ else {
+ b = true;
+ }
+ }
+ else if (ae.isColumn()) {
+ if (ae.containsRow(srcCellRow)) {
+ ValueEval ve = ae.getValueAt(srcCellRow, ae.getFirstColumn());
+ if (ve instanceof RefEval)
+ b = ((RefEval) ve).getInnerValueEval() instanceof ErrorEval;
+ else
+ b = (ve instanceof ErrorEval);
+ }
+ else {
+ b = true;
+ }
+ }
+ else {
+ b = true;
+ }
+ }
+ else if (operands[0] instanceof RefEval) {
+ b = ((RefEval) operands[0]).getInnerValueEval() instanceof ErrorEval;
+ }
+ else {
+ b = false;
+ }
+ }
+
+ if (retval == null) {
+ retval = b
+ ? BoolEval.TRUE
+ : BoolEval.FALSE;
+ }
+ return retval;
+ }
}
*/
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.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+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.RefEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
-public class Isblank extends DefaultFunctionImpl {
+public class Isblank implements Function {
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ boolean b = false;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ if (operands[0] instanceof BlankEval) {
+ b = true;
+ }
+ else if (operands[0] instanceof AreaEval) {
+ AreaEval ae = (AreaEval) operands[0];
+ if (ae.contains(srcCellRow, srcCellCol)) { // circular ref!
+ retval = ErrorEval.CIRCULAR_REF_ERROR;
+ }
+ else if (ae.isRow()) {
+ if (ae.containsColumn(srcCellCol)) {
+ ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCellCol);
+ b = (ve instanceof BlankEval);
+ }
+ else {
+ b = false;
+ }
+ }
+ else if (ae.isColumn()) {
+ if (ae.containsRow(srcCellRow)) {
+ ValueEval ve = ae.getValueAt(srcCellRow, ae.getFirstColumn());
+ b = (ve instanceof BlankEval);
+ }
+ else {
+ b = false;
+ }
+ }
+ else {
+ b = false;
+ }
+ }
+ else if (operands[0] instanceof RefEval) {
+ RefEval re = (RefEval) operands[0];
+ b = (!re.isEvaluated()) && re.getInnerValueEval() instanceof BlankEval;
+ }
+ else {
+ b = false;
+ }
+ }
+
+ if (retval == null) {
+ retval = b
+ ? BoolEval.TRUE
+ : BoolEval.FALSE;
+ }
+ return retval;
+ }
}
*/
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 Large extends DefaultFunctionImpl {
+public class Large 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
+ //| ValueEvalToNumericXlator.REF_BLANK_IS_PARSED
+ //| ValueEvalToNumericXlator.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[] ops = getNumberArray(operands, srcCellRow, srcCellCol);
+ if (ops == null || ops.length < 2) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ else {
+ double[] values = new double[ops.length-1];
+ int k = (int) ops[ops.length-1];
+ System.arraycopy(ops, 0, values, 0, values.length);
+ double d = StatsLib.kthLargest(values, k);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
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.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.RefEval;
+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 Len extends DefaultFunctionImpl {
+public class Len extends TextFunction {
+
+
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ String s = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
+ if (ve instanceof StringValueEval) {
+ StringValueEval sve = (StringValueEval) ve;
+ s = sve.getStringValue();
+ }
+ else if (ve instanceof RefEval) {
+ RefEval re = (RefEval) ve;
+ ValueEval ive = re.getInnerValueEval();
+ if (ive instanceof BlankEval) {
+ s = re.isEvaluated() ? "0" : null;
+ }
+ else if (ive instanceof StringValueEval) {
+ s = ((StringValueEval) ive).getStringValue();
+ }
+ else if (ive instanceof BlankEval) {}
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else if (ve instanceof BlankEval) {}
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ }
+ }
+
+ if (retval == null) {
+ s = (s == null) ? EMPTY_STRING : s;
+ retval = new NumberEval(s.length());
+ }
+
+ return retval;
+ }
+
+
+ protected ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol) {
+ ValueEval retval;
+ if (eval instanceof AreaEval) {
+ AreaEval ae = (AreaEval) eval;
+ if (ae.contains(srcRow, srcCol)) { // circular ref!
+ retval = ErrorEval.CIRCULAR_REF_ERROR;
+ }
+ else if (ae.isRow()) {
+ if (ae.containsColumn(srcCol)) {
+ ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
+ retval = attemptXlateToText(ve);
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else if (ae.isColumn()) {
+ if (ae.containsRow(srcRow)) {
+ ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
+ retval = attemptXlateToText(ve);
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else {
+ retval = attemptXlateToText((ValueEval) eval);
+ }
+ return retval;
+ }
+
+ /**
+ * converts from Different ValueEval types to StringEval.
+ * Note: AreaEvals are not handled, if arg is an AreaEval,
+ * the returned value is ErrorEval.VALUE_INVALID
+ * @param ve
+ * @return
+ */
+ protected ValueEval attemptXlateToText(ValueEval ve) {
+ ValueEval retval;
+ if (ve instanceof StringValueEval || ve instanceof RefEval) {
+ retval = ve;
+ }
+ else if (ve instanceof BlankEval) {
+ retval = ve;
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ return retval;
+ }
}
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *
+ *
*/
public class Ln 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
d = Math.log(d);
retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
* Log: LOG(number,[base])
*/
public class Log 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
- ));
-
- private static final double DEFAULT_BASE = 10;
- protected ValueEvalToNumericXlator getXlator() {
- return NUM_XLATOR;
- }
+ private static final double DEFAULT_BASE = 10;
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
double d = 0;
double base = DEFAULT_BASE;
double num = 0;
ValueEval retval = null;
-
+
switch (operands.length) {
default:
+ retval = ErrorEval.VALUE_INVALID;
break;
- case 2: // second arg is base
+ case 2: // second arg is base
ValueEval ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
if (ve instanceof NumericValueEval) {
NumericValueEval ne = (NumericValueEval) ve;
else {
retval = ErrorEval.NUM_ERROR;
}
-
+
case 1: // first arg is number
if (retval == null) {
ValueEval vev = singleOperandEvaluate(operands[0], srcRow, srcCol);
}
}
}
-
+
if (retval == null) {
- d = (base == E)
+ d = (base == E)
? Math.log(num)
: Math.log(num) / Math.log(base);
retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
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 Log10 extends NumericFunction {
private static final double LOG_10_TO_BASE_e = Math.log(10);
-
- 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
d = Math.log(d) / LOG_10_TO_BASE_e;
- retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
}
return retval;
}
*/
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 Lower extends DefaultFunctionImpl {
+public class Lower extends TextFunction {
+
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ String s = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
+ if (ve instanceof StringValueEval) {
+ StringValueEval sve = (StringValueEval) ve;
+ s = sve.getStringValue();
+ }
+ else if (ve instanceof BlankEval) {}
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ }
+ }
+
+ if (retval == null) {
+ s = (s == null) ? EMPTY_STRING : s;
+ retval = new StringEval(s.toLowerCase());
+ }
+
+ return retval;
+ }
}
*/
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 Max extends DefaultFunctionImpl {
+public class Max extends MultiOperandNumericFunction {
+ private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
+ new ValueEvalToNumericXlator((short) (
+ 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
+ ));
+
+ 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 = values.length > 0 ? MathX.max(values) : 0;
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
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 Maxa extends DefaultFunctionImpl {
+public class Maxa extends MultiOperandNumericFunction {
+ private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
+ new ValueEvalToNumericXlator((short) (
+ 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.BLANK_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BLANK_IS_PARSED
+ ));
+
+ 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 = values.length > 0 ? MathX.max(values) : 0;
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
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 Median extends DefaultFunctionImpl {
+public class Median 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
+ //| ValueEvalToNumericXlator.REF_BLANK_IS_PARSED
+ //| ValueEvalToNumericXlator.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.median(values);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
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 Min extends DefaultFunctionImpl {
+public class Min extends MultiOperandNumericFunction {
+ private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
+ new ValueEvalToNumericXlator((short) (
+ 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
+ ));
+
+ 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 = values.length > 0 ? MathX.min(values) : 0;
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
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 Mina extends DefaultFunctionImpl {
+public class Mina extends MultiOperandNumericFunction {
+ private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
+ new ValueEvalToNumericXlator((short) (
+ 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.REF_BLANK_IS_PARSED
+ | ValueEvalToNumericXlator.BLANK_IS_PARSED
+ ));
+
+ 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 = values.length > 0 ? MathX.min(values) : 0;
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
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 Mod extends DefaultFunctionImpl {
+public class Mod 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 (d1 == 0) {
+ retval = ErrorEval.DIV_ZERO;
+ }
+ else {
+ double d = MathX.mod(d0, d1);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+ }
+ return retval;
+ }
}
*/
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 Mode extends DefaultFunctionImpl {
+public class Mode 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
+ //| ValueEvalToNumericXlator.REF_BLANK_IS_PARSED
+ //| ValueEvalToNumericXlator.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.mode(values);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
protected static final double E = Math.E;
protected static final double PI = Math.PI;
+
+ private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
+ new ValueEvalToNumericXlator((short) (
+ 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
+ ));
+
+ private static final int DEFAULT_MAX_NUM_OPERANDS = 30;
- protected abstract ValueEvalToNumericXlator getXlator();
+ /**
+ * this is the default impl of the factory(ish) method getXlator.
+ * Subclasses can override this method
+ * if they desire to return a different ValueEvalToNumericXlator instance
+ * than the default.
+ */
+ protected ValueEvalToNumericXlator getXlator() {
+ return DEFAULT_NUM_XLATOR;
+ }
protected ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol) {
ValueEval retval;
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 Odd 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;
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 Power 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;
*/
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 Product extends DefaultFunctionImpl {
+public class Product extends MultiOperandNumericFunction {
+ private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
+ new ValueEvalToNumericXlator((short) (
+ 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
+ ));
+
+ 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.product(values);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
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 Radians 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;
*/
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
*
*/
-public class Round extends DefaultFunctionImpl {
+public class Round 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;
+ if (d0 > Integer.MAX_VALUE) {
+ d = (Double.isNaN(d0) || Double.isInfinite(d0))
+ ? Double.NaN
+ : 0;
+ }
+ else {
+ d = MathX.round(d0, (int) d1);
+ }
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
}
*/
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
*
*/
-public class Rounddown extends DefaultFunctionImpl {
+public class Rounddown 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;
+ if (d0 > Integer.MAX_VALUE) {
+ d = (Double.isInfinite(d0))
+ ? Double.NaN
+ : 0;
+ }
+ else {
+ d = MathX.roundDown(d0, (int) d1);
+ }
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
}
*/
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
*
*/
-public class Roundup extends DefaultFunctionImpl {
+public class Roundup 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;
+ if (d0 > Integer.MAX_VALUE) {
+ d = (Double.isNaN(d0))
+ ? Double.NaN
+ : 0;
+ }
+ else {
+ d = MathX.roundUp(d0, (int) d1);
+ }
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+ return retval;
+ }
}
*/
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 Row extends DefaultFunctionImpl {
+public class Row implements Function {
+ public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ int rnum = -1;
+
+ switch (evals.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ case 1:
+ if (evals[0] instanceof AreaEval) {
+ AreaEval ae = (AreaEval) evals[0];
+ rnum = ae.getFirstRow();
+ }
+ else if (evals[0] instanceof RefEval) {
+ RefEval re = (RefEval) evals[0];
+ rnum = re.getRow();
+ }
+ else { // anything else is not valid argument
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ break;
+ case 0:
+ rnum = srcCellRow;
+ }
+
+ if (retval == null) {
+ retval = (rnum >= 0)
+ ? new NumberEval(rnum + 1) // +1 since excel rownums are 1 based
+ : (ValueEval) ErrorEval.VALUE_INVALID;
+ }
+
+ return retval;
+ }
+
}
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
*/
public class Sign 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;
if (retval == null) {
retval = (Double.isNaN(d) || Double.isInfinite(d))
? (ValueEval) ErrorEval.VALUE_INVALID
- : (d == 0)
- ? new NumberEval(0)
- : (d < 0)
- ? new NumberEval(-1)
- : new NumberEval(1);
+ : new NumberEval(MathX.sign(d));
}
return retval;
}
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 Sin 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
d = Math.sin(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;
}
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 Sinh 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
- double ePowX = Math.pow(E, d);
- double ePowNegX = Math.pow(E, -d);
- d = (ePowX - ePowNegX) / 2;
- retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ d = MathX.sinh(d);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
}
return retval;
}
*/
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 Small extends DefaultFunctionImpl {
+public class Small 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
+ //| ValueEvalToNumericXlator.REF_BLANK_IS_PARSED
+ //| ValueEvalToNumericXlator.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[] ops = getNumberArray(operands, srcCellRow, srcCellCol);
+ if (ops == null || ops.length < 2) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ else {
+ double[] values = new double[ops.length-1];
+ int k = (int) ops[ops.length-1];
+ System.arraycopy(ops, 0, values, 0, values.length);
+ double d = StatsLib.kthSmallest(values, k);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
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 Sqrt 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
d = Math.sqrt(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;
}
*/
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 Stdev extends DefaultFunctionImpl {
+public class Stdev 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.stdev(values);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
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 Sum extends DefaultFunctionImpl {
+public class Sum extends MultiOperandNumericFunction {
+ private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
+ new ValueEvalToNumericXlator((short) (
+ 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
+ ));
+
+ 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 = values.length > 0 ? MathX.sum(values) : 0;
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
package org.apache.poi.hssf.record.formula.functions;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
public class Sumproduct extends DefaultFunctionImpl {
-
}
*/
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 Sumsq extends DefaultFunctionImpl {
+public class Sumsq extends MultiOperandNumericFunction {
+ private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
+ new ValueEvalToNumericXlator((short) (
+ // 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.REF_BLANK_IS_PARSED
+ | ValueEvalToNumericXlator.BLANK_IS_PARSED
+ ));
+
+ 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.sumsq(values);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
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;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
-public class Sumx2my2 extends DefaultFunctionImpl {
+public class Sumx2my2 extends XYNumericFunction {
+
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ double[][] values = null;
+
+ int checkLen = 0; // check to see that all array lengths are equal
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 2:
+ values = getValues(operands, srcCellRow, srcCellCol);
+ if (values==null
+ || values[X] == null || values[Y] == null
+ || values[X].length == 0 || values[Y].length == 0
+ || values[X].length != values[Y].length) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+
+ if (retval == null) {
+ double d = MathX.sumx2my2(values[X], values[Y]);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
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;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
-public class Sumx2py2 extends DefaultFunctionImpl {
+public class Sumx2py2 extends XYNumericFunction {
+
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ double[][] values = null;
+
+ int checkLen = 0; // check to see that all array lengths are equal
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 2:
+ values = getValues(operands, srcCellRow, srcCellCol);
+ if (values==null
+ || values[X] == null || values[Y] == null
+ || values[X].length == 0 || values[Y].length == 0
+ || values[X].length != values[Y].length) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+
+ if (retval == null) {
+ double d = MathX.sumx2py2(values[X], values[Y]);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
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;
+
/**
- * @author
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
-public class Sumxmy2 extends DefaultFunctionImpl {
+public class Sumxmy2 extends XYNumericFunction {
+
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ double[][] values = null;
+
+ int checkLen = 0; // check to see that all array lengths are equal
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 2:
+ values = getValues(operands, srcCellRow, srcCellCol);
+ if (values==null
+ || values[X] == null || values[Y] == null
+ || values[X].length == 0 || values[Y].length == 0
+ || values[X].length != values[Y].length) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+
+ if (retval == null) {
+ double d = MathX.sumxmy2(values[X], values[Y]);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
+ }
+
+ return retval;
+ }
}
*/
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.StringEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
/**
* @author
*
*/
-public class T extends DefaultFunctionImpl {
+public class T implements Function {
+
+
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ if (operands[0] instanceof StringEval
+ || operands[0] instanceof ErrorEval) {
+ retval = (ValueEval) operands[0];
+ }
+ else if (operands[0] instanceof ErrorEval) {
+ retval = StringEval.EMPTY_INSTANCE;
+ }
+ }
+ return retval;
+ }
}
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 Tan 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
d = Math.tan(d);
- retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ retval = (Double.isNaN(d))
+ ? (ValueEval) ErrorEval.VALUE_INVALID
+ : new NumberEval(d);
}
return retval;
}
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 Tanh 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);
retval = ErrorEval.NUM_ERROR;
}
}
-
+
if (retval == null) {
- double ePowX = Math.pow(E, d);
- double ePowNegX = Math.pow(E, -d);
- d = (ePowX - ePowNegX) / (ePowX + ePowNegX);
- retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ d = MathX.tanh(d);
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.NUM_ERROR
+ : new NumberEval(d);
}
return retval;
}
*/
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 Upper extends DefaultFunctionImpl {
+public class Upper extends TextFunction {
+
+ public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+ ValueEval retval = null;
+ String s = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
+ if (ve instanceof StringValueEval) {
+ StringValueEval sve = (StringValueEval) ve;
+ s = sve.getStringValue();
+ }
+ else if (ve instanceof BlankEval) {}
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ }
+ }
+
+ if (retval == null) {
+ s = (s == null) ? EMPTY_STRING : s;
+ retval = new StringEval(s.toUpperCase());
+ }
+
+ return retval;
+ }
}
protected static ValueEval internalEvaluate(HSSFCell srcCell, HSSFRow srcRow, HSSFSheet sheet, HSSFWorkbook workbook) {
int srcRowNum = srcRow.getRowNum();
short srcColNum = srcCell.getCellNum();
-
FormulaParser parser = new FormulaParser(srcCell.getCellFormula(), workbook.getWorkbook());
parser.parse();
Ptg[] ptgs = parser.getRPNPtg();
// storing the ops in reverse order since they are popping
for (int j = numops - 1; j >= 0; j--) {
Eval p = (Eval) stack.pop();
- if (p instanceof ErrorEval) { // fast fail
- return (ErrorEval) p;
- }
ops[j] = p;
}
Eval opresult = operation.evaluate(ops, srcRowNum, srcColNum);
retval = new StringEval(cell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
- retval = (ValueEval) internalEvaluate(cell, row, sheet, workbook);
+ retval = internalEvaluate(cell, row, sheet, workbook);
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
retval = cell.getBooleanCellValue() ? BoolEval.TRUE : BoolEval.FALSE;
*/
package org.apache.poi.hssf.record.formula.eval;
-import java.io.File;
import java.io.FileInputStream;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
+import org.apache.poi.hssf.record.formula.functions.TestMathX;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFRow;
assertEquals(msg, HSSFCell.CELL_TYPE_ERROR, actual.getCellType()); // TODO: check if exact error matches
break;
case HSSFCell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
- throw new AssertionFailedError("Cannot expect formula as result of formula evaluation");
+ throw new AssertionFailedError("Cannot expect formula as result of formula evaluation: " + msg);
case HSSFCell.CELL_TYPE_NUMERIC:
assertEquals(msg, HSSFCell.CELL_TYPE_NUMERIC, actual.getCellType());
- double delta = Math.abs(expected.getNumericCellValue()-actual.getNumberValue());
- double pctExpected = Math.abs(0.00001*expected.getNumericCellValue());
- assertTrue(msg, delta <= pctExpected);
+ TestMathX.assertEquals(msg, expected.getNumericCellValue(), actual.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
+// double delta = Math.abs(expected.getNumericCellValue()-actual.getNumberValue());
+// double pctExpected = Math.abs(0.00001*expected.getNumericCellValue());
+// assertTrue(msg, delta <= pctExpected);
break;
case HSSFCell.CELL_TYPE_STRING:
assertEquals(msg, HSSFCell.CELL_TYPE_STRING, actual.getCellType());
HSSFCell c = null;
for (short colnum=getBeginCol(); colnum < endcolnum; colnum++) {
+ try {
c = r.getCell(colnum);
- if (c==null || c.getCellType() == HSSFCell.CELL_TYPE_BLANK)
+ if (c==null || c.getCellType() != HSSFCell.CELL_TYPE_FORMULA)
continue;
- assertEquals("Sanity check input cell type ", HSSFCell.CELL_TYPE_FORMULA, c.getCellType());
-
HSSFFormulaEvaluator.CellValue actualValue = evaluator.evaluate(c);
HSSFCell expectedValueCell = getExpectedValueCell(s, r, c);
assertEquals("Formula: " + c.getCellFormula()
+ " @ " + getBeginRow() + ":" + colnum,
expectedValueCell, actualValue);
+ } catch (RuntimeException re) {
+ throw new RuntimeException("CELL["+getBeginRow()+","+colnum+"]: "+re.getMessage(), re);
+ }
}
}
s = "D"+Integer.toString(i).trim();
suite.addTest(new GenericFormulaTestCase(s));
}
+// suite.addTest(new GenericFormulaTestCase("D1164"));
return suite;
}
}