ASF Bugzilla – Attachment 14977 Details for
Bug 34828
[PATCH] FormulaEvaluator Partial Implementation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
PATCH on HEAD for FormulaEvaluator functionality
FormulaEvaluator_v0.00001.patch (text/plain), 143.92 KB, created by
Amol Deshmukh
on 2005-05-10 00:18:25 UTC
(
hide
)
Description:
PATCH on HEAD for FormulaEvaluator functionality
Filename:
MIME Type:
Creator:
Amol Deshmukh
Created:
2005-05-10 00:18:25 UTC
Size:
143.92 KB
patch
obsolete
>Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AddEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AddEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AddEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AddEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,70 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import java.lang.reflect.Constructor; >+ >+import org.apache.poi.hssf.record.formula.AddPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class AddEval implements OperationEval { >+ >+ private AddPtg delegate; >+ >+ public AddEval(Ptg ptg) { >+ delegate = (AddPtg) ptg; >+ } >+ >+ >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ Eval retval = null; >+ for (int i=0, iSize=getNumberOfOperands(); i<iSize; i++) { >+ if (operands[i] instanceof NumericValueEval) { >+ d += ((NumericValueEval) operands[i]).getNumberValue(); >+ } >+ else if (operands[i] instanceof RefEval) { >+ RefEval re = (RefEval) operands[i]; >+ ValueEval ve = (ValueEval) re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ d += ((NumericValueEval) ve).getNumberValue(); >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ break; >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ break; >+ } >+ } >+ if (retval == null) >+ retval = new NumberEval(d); >+ return retval; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area2DEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area2DEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area2DEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area2DEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,58 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.AreaPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class Area2DEval implements AreaEval { >+ >+ private AreaPtg delegate; >+ private ValueEval[] values; >+ >+ public Area2DEval(Ptg ptg, ValueEval[] values) { >+ this.delegate = (AreaPtg) ptg; >+ this.values = values; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getFirstCol() >+ */ >+ public short getFirstColumn() { >+ return delegate.getFirstColumn(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getFirstRow() >+ */ >+ public short getFirstRow() { >+ return delegate.getFirstRow(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getLastCol() >+ */ >+ public short getLastColumn() { >+ return delegate.getLastColumn(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getLastRow() >+ */ >+ public short getLastRow() { >+ return delegate.getLastRow(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getValues() >+ */ >+ public ValueEval[] getValues() { >+ return values; >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area3DEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area3DEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area3DEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area3DEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,73 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import java.lang.reflect.Constructor; >+ >+import org.apache.poi.hssf.record.formula.Area3DPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class Area3DEval implements AreaEval { >+ >+ private Area3DPtg delegate; >+ >+ private ValueEval[] values; >+ >+ public Area3DEval(Ptg ptg, ValueEval[] values) { >+ this.values = values; >+ this.delegate = (Area3DPtg) ptg; >+ } >+ >+ >+ public static void main(String[] args) throws Exception { >+ Class clazz = Area3DEval.class; >+ Constructor[] carr = clazz.getDeclaredConstructors(); >+ for (int i=0, iSize=carr.length; i<iSize; i++) { >+ Object[] o = carr[i].getParameterTypes(); >+ for (int j=0, jSize=o.length; j<jSize; j++) { >+ System.out.println(o[j]); >+ } >+ } >+ } >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getFirstCol() >+ */ >+ public short getFirstColumn() { >+ return delegate.getFirstColumn(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getFirstRow() >+ */ >+ public short getFirstRow() { >+ return delegate.getFirstRow(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getLastCol() >+ */ >+ public short getLastColumn() { >+ return delegate.getLastColumn(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getLastRow() >+ */ >+ public short getLastRow() { >+ return delegate.getLastRow(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getValues() >+ */ >+ public ValueEval[] getValues() { >+ return values; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AreaEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AreaEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AreaEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AreaEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,18 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public interface AreaEval extends Eval { >+ >+ public short getFirstRow(); >+ public short getLastRow(); >+ public short getFirstColumn(); >+ public short getLastColumn(); >+ public ValueEval[] getValues(); >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/BoolEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/BoolEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/BoolEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/BoolEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,37 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.BoolPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class BoolEval implements NumericValueEval, StringValueEval { >+ >+ private boolean value; >+ >+ public BoolEval(Ptg ptg) { >+ this.value = ((BoolPtg) ptg).getValue(); >+ } >+ >+ public BoolEval(boolean value) { >+ this.value = value; >+ } >+ >+ public boolean getBooleanValue() { >+ return value; >+ } >+ >+ public double getNumberValue() { >+ return value ? (short) 1 : (short) 0; >+ } >+ >+ public String getStringValue() { >+ return value ? "1" : "0"; >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ConcatEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ConcatEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ConcatEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ConcatEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,54 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.ConcatPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class ConcatEval implements OperationEval { >+ >+ private ConcatPtg delegate; >+ >+ public ConcatEval(Ptg ptg) { >+ this.delegate = (ConcatPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ Eval retval = null; >+ if (operands.length == getNumberOfOperands()) { >+ StringBuffer sb = new StringBuffer(); >+ for (int i=0, iSize=operands.length; i<iSize; i++) { >+ if (operands[i] instanceof StringValueEval) { >+ sb.append(operands[i]); >+ } >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_UNKNOWN; >+ } >+ return retval; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/DivideEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/DivideEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/DivideEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/DivideEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,82 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.DividePtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class DivideEval implements OperationEval { >+ >+ private DividePtg delegate; >+ >+ public DivideEval(Ptg ptg) { >+ this.delegate = (DividePtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d0 = 0; >+ double d1 = 0; >+ ValueEval retval = null; >+ if (operands.length == 2) { >+ if (operands[0] != null) { >+ if (operands[0] instanceof NumericValueEval) { >+ d0 = ((NumericValueEval) operands[0]).getNumberValue(); >+ } >+ else if (operands[0] instanceof StringValueEval) { >+ retval = ErrorEval.ERROR_502; >+ } >+ else if (operands[0] instanceof ErrorEval) { >+ retval = (ErrorEval) operands[0]; >+ } >+ else { >+ retval = ErrorEval.INVALID_VALUE; >+ } >+ } >+ if (retval == null && operands[1] != null) { >+ if (operands[1] instanceof NumericValueEval) { >+ d1 = ((NumericValueEval) operands[1]).getNumberValue(); >+ } >+ else if (operands[1] instanceof StringValueEval) { >+ retval = ErrorEval.ERROR_502; >+ } >+ else if (operands[0] instanceof ErrorEval) { >+ ErrorEval e = (ErrorEval) operands[0]; >+ retval = e; >+ } >+ else { >+ retval = ErrorEval.INVALID_VALUE; >+ } >+ } >+ if (retval != null) >+ retval = new NumberEval(d0/d1); >+ } >+ else { >+ retval = ErrorEval.ERROR_UNKNOWN; >+ } >+ return retval; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/EqualEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/EqualEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/EqualEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/EqualEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,43 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.EqualPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class EqualEval implements OperationEval { >+ >+ private EqualPtg delegate; >+ >+ public EqualEval(Ptg ptg) { >+ this.delegate = (EqualPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ErrorEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ErrorEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ErrorEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ErrorEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,64 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+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 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 INVALID_NAME = ERROR_525; >+ public static final ErrorEval INVALID_VALUE = ERROR_519; >+ >+ >+ // Non std error codes >+ public static final ErrorEval ERROR_UNKNOWN = new ErrorEval(-20); >+ public static final ErrorEval FUNCTION_NOT_IMPLEMENTED = new ErrorEval(-30); >+ >+ >+ private ErrorEval(int errorCode) { >+ this.errorCode = errorCode; >+ } >+ >+ public int getErrorCode() { >+ return errorCode; >+ } >+ >+ public String getStringValue() { >+ return "Err:"+Integer.toString(errorCode); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Eval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Eval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Eval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Eval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,14 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public interface Eval { >+ >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FuncVarEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FuncVarEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FuncVarEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FuncVarEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,56 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.AbstractFunctionPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+import org.apache.poi.hssf.record.formula.functions.Function; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class FuncVarEval extends FunctionEval { >+ >+ private AbstractFunctionPtg delegate; >+ >+ public FuncVarEval(Ptg funcPtg) { >+ delegate = (AbstractFunctionPtg) funcPtg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ Eval retval = null; >+ Function f = getFunction(); >+ if (f!=null) >+ retval = f.evaluate(operands); >+ else >+ retval = ErrorEval.FUNCTION_NOT_IMPLEMENTED; >+ return retval; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.FunctionEval#getFunctionIndex() >+ */ >+ public short getFunctionIndex() { >+ return delegate.getFunctionIndex(); >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FunctionEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FunctionEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FunctionEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FunctionEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,377 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.functions.*; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public abstract class FunctionEval implements OperationEval { >+ protected static Function[] functions = produceFunctions(); >+ public Function getFunction() { >+ short fidx = getFunctionIndex(); >+ return functions[fidx]; >+ } >+ public abstract short getFunctionIndex(); >+ >+ private static Function[] produceFunctions() { >+ Function[] retval = new Function[368]; >+ retval[0] = new Count(); // COUNT >+ retval[1] = null; // specialflag >+ retval[2] = new IsNa(); // ISNA >+ retval[3] = new IsError(); // ISERROR >+ retval[4] = new Sum(); // SUM >+ retval[5] = new Average(); // AVERAGE >+ retval[6] = new Min(); // MIN >+ retval[7] = new Max(); // MAX >+ retval[8] = new Row(); // ROW >+ retval[9] = new Column(); // COLUMN >+ retval[10] = new Na(); // NA >+ retval[11] = new Npv(); // NPV >+ retval[12] = new Stdev(); // STDEV >+ retval[13] = new Dollar(); // DOLLAR >+ retval[14] = new Fixed(); // FIXED >+ retval[15] = new Sin(); // SIN >+ retval[16] = new Cos(); // COS >+ retval[17] = new Tan(); // TAN >+ retval[18] = new Atan(); // ATAN >+ retval[19] = new Pi(); // PI >+ retval[20] = new Sqrt(); // SQRT >+ retval[21] = new Exp(); // EXP >+ retval[22] = new Ln(); // LN >+ retval[23] = new Log10(); // LOG10 >+ retval[24] = new Abs(); // ABS >+ retval[25] = new Int(); // INT >+ retval[26] = new Sign(); // SIGN >+ retval[27] = new Round(); // ROUND >+ retval[28] = null; // LOOKUP >+ retval[29] = null; // INDEX >+ retval[30] = null; // REPT >+ retval[31] = null; // MID >+ retval[32] = null; // LEN >+ retval[33] = null; // VALUE >+ retval[34] = null; // TRUE >+ retval[35] = null; // FALSE >+ retval[36] = null; // AND >+ retval[37] = null; // OR >+ retval[38] = null; // NOT >+ retval[39] = null; // MOD >+ retval[40] = null; // DCOUNT >+ retval[41] = null; // DSUM >+ retval[42] = null; // DAVERAGE >+ retval[43] = null; // DMIN >+ retval[44] = null; // DMAX >+ retval[45] = null; // DSTDEV >+ retval[46] = null; // VAR >+ retval[47] = null; // DVAR >+ retval[48] = null; // TEXT >+ retval[49] = null; // LINEST >+ retval[50] = null; // TREND >+ retval[51] = null; // LOGEST >+ retval[52] = null; // GROWTH >+ retval[53] = null; // GOTO >+ retval[54] = null; // HALT >+ retval[55] = null; // PV >+ retval[56] = null; // FV >+ retval[57] = null; // NPER >+ retval[58] = null; // PMT >+ retval[59] = null; // RATE >+ retval[60] = null; // MIRR >+ retval[61] = null; // IRR >+ retval[62] = null; // RAND >+ retval[63] = null; // MATCH >+ retval[64] = null; // DATE >+ retval[65] = null; // TIME >+ retval[66] = null; // DAY >+ retval[67] = null; // MONTH >+ retval[68] = null; // YEAR >+ retval[69] = null; // WEEKDAY >+ retval[70] = null; // HOUR >+ retval[71] = null; // MINUTE >+ retval[72] = null; // SECOND >+ retval[73] = null; // NOW >+ retval[74] = null; // AREAS >+ retval[75] = null; // ROWS >+ retval[76] = null; // COLUMNS >+ retval[77] = null; // OFFSET >+ retval[78] = null; // ABSREF >+ retval[79] = null; // RELREF >+ retval[80] = null; // ARGUMENT >+ retval[81] = null; // SEARCH >+ retval[82] = null; // TRANSPOSE >+ retval[83] = null; // ERROR >+ retval[84] = null; // STEP >+ retval[85] = null; // TYPE >+ retval[86] = null; // ECHO >+ retval[87] = null; // SETNAME >+ retval[88] = null; // CALLER >+ retval[89] = null; // DEREF >+ retval[90] = null; // WINDOWS >+ retval[91] = null; // SERIES >+ retval[92] = null; // DOCUMENTS >+ retval[93] = null; // ACTIVECELL >+ retval[94] = null; // SELECTION >+ retval[95] = null; // RESULT >+ retval[96] = null; // ATAN2 >+ retval[97] = null; // ASIN >+ retval[98] = null; // ACOS >+ retval[99] = null; // CHOOSE >+ retval[100] = null; // HLOOKUP >+ retval[101] = null; // VLOOKUP >+ retval[102] = null; // LINKS >+ retval[103] = null; // INPUT >+ retval[104] = null; // ISREF >+ retval[105] = null; // GETFORMULA >+ retval[106] = null; // GETNAME >+ retval[107] = null; // SETVALUE >+ retval[108] = null; // LOG >+ retval[109] = null; // EXEC >+ retval[110] = null; // CHAR >+ retval[111] = null; // LOWER >+ retval[112] = null; // UPPER >+ retval[113] = null; // PROPER >+ retval[114] = null; // LEFT >+ retval[115] = null; // RIGHT >+ retval[116] = null; // EXACT >+ retval[117] = null; // TRIM >+ retval[118] = null; // REPLACE >+ retval[119] = null; // SUBSTITUTE >+ retval[120] = null; // CODE >+ retval[121] = null; // NAMES >+ retval[122] = null; // DIRECTORY >+ retval[123] = null; // FIND >+ retval[124] = null; // CELL >+ retval[125] = null; // ISERR >+ retval[126] = null; // ISTEXT >+ retval[127] = null; // ISNUMBER >+ retval[128] = null; // ISBLANK >+ retval[129] = null; // T >+ retval[130] = null; // N >+ retval[131] = null; // FOPEN >+ retval[132] = null; // FCLOSE >+ retval[133] = null; // FSIZE >+ retval[134] = null; // FREADLN >+ retval[135] = null; // FREAD >+ retval[136] = null; // FWRITELN >+ retval[137] = null; // FWRITE >+ retval[138] = null; // FPOS >+ retval[139] = null; // DATEVALUE >+ retval[140] = null; // TIMEVALUE >+ retval[141] = null; // SLN >+ retval[142] = null; // SYD >+ retval[143] = null; // DDB >+ retval[144] = null; // GETDEF >+ retval[145] = null; // REFTEXT >+ retval[146] = null; // TEXTREF >+ retval[147] = null; // INDIRECT >+ retval[148] = null; // REGISTER >+ retval[149] = null; // CALL >+ retval[150] = null; // ADDBAR >+ retval[151] = null; // ADDMENU >+ retval[152] = null; // ADDCOMMAND >+ retval[153] = null; // ENABLECOMMAND >+ retval[154] = null; // CHECKCOMMAND >+ retval[155] = null; // RENAMECOMMAND >+ retval[156] = null; // SHOWBAR >+ retval[157] = null; // DELETEMENU >+ retval[158] = null; // DELETECOMMAND >+ retval[159] = null; // GETCHARTITEM >+ retval[160] = null; // DIALOGBOX >+ retval[161] = null; // CLEAN >+ retval[162] = null; // MDETERM >+ retval[163] = null; // MINVERSE >+ retval[164] = null; // MMULT >+ retval[165] = null; // FILES >+ retval[166] = null; // IPMT >+ retval[167] = null; // PPMT >+ retval[168] = null; // COUNTA >+ retval[169] = null; // CANCELKEY >+ retval[170] = null; // INITIATE >+ retval[171] = null; // REQUEST >+ retval[172] = null; // POKE >+ retval[173] = null; // EXECUTE >+ retval[174] = null; // TERMINATE >+ retval[175] = null; // RESTART >+ retval[176] = null; // HELP >+ retval[177] = null; // GETBAR >+ retval[178] = null; // PRODUCT >+ retval[179] = null; // FACT >+ retval[180] = null; // GETCELL >+ retval[181] = null; // GETWORKSPACE >+ retval[182] = null; // GETWINDOW >+ retval[183] = null; // GETDOCUMENT >+ retval[184] = null; // DPRODUCT >+ retval[185] = null; // ISNONTEXT >+ retval[186] = null; // GETNOTE >+ retval[187] = null; // NOTE >+ retval[188] = null; // STDEVP >+ retval[189] = null; // VARP >+ retval[190] = null; // DSTDEVP >+ retval[191] = null; // DVARP >+ retval[192] = null; // TRUNC >+ retval[193] = null; // ISLOGICAL >+ retval[194] = null; // DCOUNTA >+ retval[195] = null; // DELETEBAR >+ retval[196] = null; // UNREGISTER >+ retval[197] = null; // USDOLLAR >+ retval[198] = null; // FINDB >+ retval[199] = null; // SEARCHB >+ retval[200] = null; // REPLACEB >+ retval[201] = null; // LEFTB >+ retval[202] = null; // RIGHTB >+ retval[203] = null; // MIDB >+ retval[204] = null; // LENB >+ retval[205] = null; // ROUNDUP >+ retval[206] = null; // ROUNDDOWN >+ retval[207] = null; // ASC >+ retval[208] = null; // DBCS >+ retval[209] = null; // RANK >+ retval[210] = null; // ADDRESS >+ retval[211] = null; // DAYS360 >+ retval[212] = null; // TODAY >+ retval[213] = null; // VDB >+ retval[214] = null; // MEDIAN >+ retval[215] = null; // SUMPRODUCT >+ retval[216] = null; // SINH >+ retval[217] = null; // COSH >+ retval[218] = null; // TANH >+ retval[219] = null; // ASINH >+ retval[220] = null; // ACOSH >+ retval[221] = null; // ATANH >+ retval[222] = null; // DGET >+ retval[223] = null; // CREATEOBJECT >+ retval[224] = null; // VOLATILE >+ retval[225] = null; // LASTERROR >+ retval[226] = null; // CUSTOMUNDO >+ retval[227] = null; // CUSTOMREPEAT >+ retval[228] = null; // FORMULACONVERT >+ retval[229] = null; // GETLINKINFO >+ retval[230] = null; // TEXTBOX >+ retval[231] = null; // INFO >+ retval[232] = null; // GROUP >+ retval[233] = null; // GETOBJECT >+ retval[234] = null; // DB >+ retval[235] = null; // PAUSE >+ retval[236] = null; // RESUME >+ retval[237] = null; // FREQUENCY >+ retval[238] = null; // ADDTOOLBAR >+ retval[239] = null; // DELETETOOLBAR >+ retval[240] = null; // externalflag >+ retval[241] = null; // RESETTOOLBAR >+ retval[242] = null; // EVALUATE >+ retval[243] = null; // GETTOOLBAR >+ retval[244] = null; // GETTOOL >+ retval[245] = null; // SPELLINGCHECK >+ retval[246] = null; // ERRORTYPE >+ retval[247] = null; // APPTITLE >+ retval[248] = null; // WINDOWTITLE >+ retval[249] = null; // SAVETOOLBAR >+ retval[250] = null; // ENABLETOOL >+ retval[251] = null; // PRESSTOOL >+ retval[252] = null; // REGISTERID >+ retval[253] = null; // GETWORKBOOK >+ retval[254] = null; // AVEDEV >+ retval[255] = null; // BETADIST >+ retval[256] = null; // GAMMALN >+ retval[257] = null; // BETAINV >+ retval[258] = null; // BINOMDIST >+ retval[259] = null; // CHIDIST >+ retval[260] = null; // CHIINV >+ retval[261] = null; // COMBIN >+ retval[262] = null; // CONFIDENCE >+ retval[263] = null; // CRITBINOM >+ retval[264] = null; // EVEN >+ retval[265] = null; // EXPONDIST >+ retval[266] = null; // FDIST >+ retval[267] = null; // FINV >+ retval[268] = null; // FISHER >+ retval[269] = null; // FISHERINV >+ retval[270] = null; // FLOOR >+ retval[271] = null; // GAMMADIST >+ retval[272] = null; // GAMMAINV >+ retval[273] = null; // CEILING >+ retval[274] = null; // HYPGEOMDIST >+ retval[275] = null; // LOGNORMDIST >+ retval[276] = null; // LOGINV >+ retval[277] = null; // NEGBINOMDIST >+ retval[278] = null; // NORMDIST >+ retval[279] = null; // NORMSDIST >+ retval[280] = null; // NORMINV >+ retval[281] = null; // NORMSINV >+ retval[282] = null; // STANDARDIZE >+ retval[283] = null; // ODD >+ retval[284] = null; // PERMUT >+ retval[285] = null; // POISSON >+ retval[286] = null; // TDIST >+ retval[287] = null; // WEIBULL >+ retval[288] = null; // SUMXMY2 >+ retval[289] = null; // SUMX2MY2 >+ retval[290] = null; // SUMX2PY2 >+ retval[291] = null; // CHITEST >+ retval[292] = null; // CORREL >+ retval[293] = null; // COVAR >+ retval[294] = null; // FORECAST >+ retval[295] = null; // FTEST >+ retval[296] = null; // INTERCEPT >+ retval[297] = null; // PEARSON >+ retval[298] = null; // RSQ >+ retval[299] = null; // STEYX >+ retval[300] = null; // SLOPE >+ retval[301] = null; // TTEST >+ retval[302] = null; // PROB >+ retval[303] = null; // DEVSQ >+ retval[304] = null; // GEOMEAN >+ retval[305] = null; // HARMEAN >+ retval[306] = null; // SUMSQ >+ retval[307] = null; // KURT >+ retval[308] = null; // SKEW >+ retval[309] = null; // ZTEST >+ retval[310] = null; // LARGE >+ retval[311] = null; // SMALL >+ retval[312] = null; // QUARTILE >+ retval[313] = null; // PERCENTILE >+ retval[314] = null; // PERCENTRANK >+ retval[315] = null; // MODE >+ retval[316] = null; // TRIMMEAN >+ retval[317] = null; // TINV >+ retval[318] = null; // MOVIECOMMAND >+ retval[319] = null; // GETMOVIE >+ retval[320] = null; // CONCATENATE >+ retval[321] = null; // POWER >+ retval[322] = null; // PIVOTADDDATA >+ retval[323] = null; // GETPIVOTTABLE >+ retval[324] = null; // GETPIVOTFIELD >+ retval[325] = null; // GETPIVOTITEM >+ retval[326] = null; // RADIANS >+ retval[327] = null; // DEGREES >+ retval[328] = null; // SUBTOTAL >+ retval[329] = null; // SUMIF >+ retval[330] = null; // COUNTIF >+ retval[331] = null; // COUNTBLANK >+ retval[332] = null; // SCENARIOGET >+ retval[333] = null; // OPTIONSLISTSGET >+ retval[334] = null; // ISPMT >+ retval[335] = null; // DATEDIF >+ retval[336] = null; // DATESTRING >+ retval[337] = null; // NUMBERSTRING >+ retval[338] = null; // ROMAN >+ retval[339] = null; // OPENDIALOG >+ retval[340] = null; // SAVEDIALOG >+ retval[341] = null; // VIEWGET >+ retval[342] = null; // GETPIVOTDATA >+ retval[343] = null; // HYPERLINK >+ retval[344] = null; // PHONETIC >+ retval[345] = null; // AVERAGEA >+ retval[346] = null; // MAXA >+ retval[347] = null; // MINA >+ retval[348] = null; // STDEVPA >+ retval[349] = null; // VARPA >+ retval[350] = null; // STDEVA >+ retval[351] = null; // VARA >+ return retval; >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterEqualEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterEqualEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterEqualEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterEqualEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,50 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.GreaterEqualPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class GreaterEqualEval implements OperationEval { >+ >+ private GreaterEqualPtg delegate; >+ >+ public GreaterEqualEval(Ptg ptg) { >+ this.delegate = (GreaterEqualPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ boolean b = false; >+ double d0 = 0; >+ double d1 = 0; >+ if (operands[0] instanceof NumericValueEval) { >+ >+ } >+ >+ return new BoolEval(b); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterThanEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterThanEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterThanEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterThanEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.GreaterThanPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class GreaterThanEval implements OperationEval { >+ >+ private GreaterThanPtg delegate; >+ >+ public GreaterThanEval(Ptg ptg) { >+ this.delegate = (GreaterThanPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessEqualEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessEqualEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessEqualEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessEqualEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.LessEqualPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class LessEqualEval implements OperationEval { >+ >+ private LessEqualPtg delegate; >+ >+ public LessEqualEval(Ptg ptg) { >+ this.delegate = (LessEqualPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessThanEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessThanEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessThanEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessThanEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.LessThanPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class LessThanEval implements OperationEval { >+ >+ private LessThanPtg delegate; >+ >+ public LessThanEval(Ptg ptg) { >+ this.delegate = (LessThanPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/MultiplyEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/MultiplyEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/MultiplyEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/MultiplyEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,67 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.MultiplyPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class MultiplyEval implements OperationEval { >+ >+ private MultiplyPtg delegate; >+ >+ public MultiplyEval(Ptg ptg) { >+ this.delegate = (MultiplyPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ Eval retval = null; >+ for (int i=0, iSize=getNumberOfOperands(); i<iSize; i++) { >+ if (operands[i] instanceof NumericValueEval) { >+ d *= ((NumericValueEval) operands[i]).getNumberValue(); >+ } >+ else if (operands[i] instanceof RefEval) { >+ RefEval re = (RefEval) operands[i]; >+ ValueEval ve = (ValueEval) re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ d *= ((NumericValueEval) ve).getNumberValue(); >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ break; >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ break; >+ } >+ } >+ if (retval == null) >+ retval = new NumberEval(d); >+ return retval; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NotEqualEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NotEqualEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NotEqualEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NotEqualEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.NotEqualPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class NotEqualEval implements OperationEval { >+ >+ private NotEqualPtg delegate; >+ >+ public NotEqualEval(Ptg ptg) { >+ this.delegate = (NotEqualPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumberEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumberEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumberEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumberEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.IntPtg; >+import org.apache.poi.hssf.record.formula.NumberPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class NumberEval implements NumericValueEval, StringValueEval { >+ >+ private double value; >+ >+ >+ public NumberEval(Ptg ptg) { >+ if (ptg instanceof IntPtg) { >+ this.value = ((IntPtg) ptg).getValue(); >+ } >+ else if (ptg instanceof NumberPtg) { >+ this.value = ((NumberPtg) ptg).getValue(); >+ } >+ } >+ >+ public NumberEval(double value) { >+ this.value = value; >+ } >+ >+ public double getNumberValue() { >+ return value; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.StringValueEval#getStringValue() >+ */ >+ public String getStringValue() { >+ return String.valueOf(value); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumericValueEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumericValueEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumericValueEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumericValueEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,14 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public interface NumericValueEval extends ValueEval { >+ >+ public abstract double getNumberValue(); >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/OperationEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/OperationEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/OperationEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/OperationEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,18 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public interface OperationEval extends Eval { >+ >+ public abstract Eval evaluate(Eval[] evals); >+ >+ public abstract int getNumberOfOperands(); >+ >+ public abstract int getType(); >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/PowerEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/PowerEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/PowerEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/PowerEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.PowerPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class PowerEval implements OperationEval { >+ >+ private PowerPtg delegate; >+ >+ public PowerEval(Ptg ptg) { >+ this.delegate = (PowerPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref2DEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref2DEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref2DEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref2DEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/* >+ * Created on May 9, 2005 >+ * >+ * TODO To change the template for this generated file go to >+ * Window - Preferences - Java - Code Style - Code Templates >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.Ptg; >+import org.apache.poi.hssf.record.formula.ReferencePtg; >+ >+/** >+ * @author adeshmukh >+ * >+ * TODO To change the template for this generated type comment go to >+ * Window - Preferences - Java - Code Style - Code Templates >+ */ >+public class Ref2DEval implements RefEval { >+ >+ private ValueEval value; >+ >+ private ReferencePtg delegate; >+ >+ public Ref2DEval(Ptg ptg, ValueEval value) { >+ this.value = value; >+ this.delegate = (ReferencePtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.RefEval#getInnerValueEval() >+ */ >+ public ValueEval getInnerValueEval() { >+ return value; >+ } >+ >+ public short getRow() { >+ return delegate.getRow(); >+ } >+ >+ public short getColumn() { >+ return delegate.getColumn(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref3DEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref3DEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref3DEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref3DEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/* >+ * Created on May 9, 2005 >+ * >+ * TODO To change the template for this generated file go to >+ * Window - Preferences - Java - Code Style - Code Templates >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.Ptg; >+import org.apache.poi.hssf.record.formula.Ref3DPtg; >+ >+/** >+ * @author adeshmukh >+ * >+ * TODO To change the template for this generated type comment go to >+ * Window - Preferences - Java - Code Style - Code Templates >+ */ >+public class Ref3DEval implements RefEval { >+ >+ private ValueEval value; >+ >+ private Ref3DPtg delegate; >+ >+ public Ref3DEval(Ptg ptg, ValueEval value) { >+ this.value = value; >+ this.delegate = (Ref3DPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.RefEval#getInnerValueEval() >+ */ >+ public ValueEval getInnerValueEval() { >+ return value; >+ } >+ >+ public short getRow() { >+ return delegate.getRow(); >+ } >+ >+ public short getColumn() { >+ return delegate.getColumn(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RefEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RefEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RefEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RefEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,29 @@ >+/* >+ * Created on May 9, 2005 >+ * >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+ >+/** >+ * @author Amol S Deshmukh < amolweb at ya hoo dot com > >+ * >+ * RefEval is the super interface for Ref2D and Ref3DEval. >+ * Basically a RefEval impl should contain reference to >+ * the original ReferencePtg or Ref3DPtg as well as the >+ * final "value" resulting from the evaluation of the cell >+ * reference. Thus if the HSSFCell has type CELL_TYPE_NUMERIC, >+ * the contained value object should be of type NumberEval; >+ * if cell type is CELL_TYPE_STRING, contained value object >+ * should be of type StringEval >+ */ >+public interface RefEval extends ValueEval { >+ >+ public ValueEval getInnerValueEval(); >+ >+ public short getColumn(); >+ >+ public short getRow(); >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,29 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.Ptg; >+import org.apache.poi.hssf.record.formula.StringPtg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class StringEval implements StringValueEval { >+ >+ private String value; >+ >+ public StringEval(Ptg ptg) { >+ this.value = ((StringPtg) ptg).getValue(); >+ } >+ >+ public StringEval(String value) { >+ this.value = value; >+ } >+ >+ public String getStringValue() { >+ return value; >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringValueEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringValueEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringValueEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringValueEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,15 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public interface StringValueEval extends ValueEval { >+ >+ public String getStringValue(); >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/SubtractEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/SubtractEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/SubtractEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/SubtractEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,82 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.Ptg; >+import org.apache.poi.hssf.record.formula.SubtractPtg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class SubtractEval implements OperationEval { >+ >+ private SubtractPtg delegate; >+ >+ public SubtractEval(Ptg ptg) { >+ delegate = (SubtractPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d0 = 0; >+ double d1 = 0; >+ Eval retval = null; >+ >+ if (operands[0] instanceof NumericValueEval) { >+ d0 = ((NumberEval) operands[0]).getNumberValue(); >+ } >+ else if (operands[0] instanceof RefEval) { >+ RefEval re = (RefEval) operands[0]; >+ ValueEval ve = (ValueEval) re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ d0 = ((NumberEval) ve).getNumberValue(); >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ } >+ >+ if (operands[1] instanceof NumericValueEval) { >+ d1 = ((NumberEval) operands[1]).getNumberValue(); >+ } >+ else if (operands[1] instanceof RefEval) { >+ RefEval re = (RefEval) operands[1]; >+ ValueEval ve = (ValueEval) re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ d1 = ((NumberEval) ve).getNumberValue(); >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ } >+ >+ if (retval == null) >+ retval = new NumberEval(d0-d1); >+ return retval; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryMinusEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryMinusEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryMinusEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryMinusEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,65 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.Ptg; >+import org.apache.poi.hssf.record.formula.UnaryMinusPtg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class UnaryMinusEval implements OperationEval { >+ >+ private UnaryMinusPtg delegate; >+ >+ public UnaryMinusEval(Ptg ptg) { >+ this.delegate = (UnaryMinusPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ ValueEval retval = null; >+ double d = 0; >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval nve = (NumericValueEval) operands[0]; >+ d = nve.getNumberValue(); >+ } >+ else if (operands[0] instanceof RefEval) { >+ RefEval re = (RefEval) operands[0]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ NumericValueEval nve = (NumericValueEval) ve; >+ d = nve.getNumberValue(); >+ } >+ } >+ else { >+ retval = ErrorEval.INVALID_VALUE; >+ } >+ >+ if (retval == null) { >+ retval = new NumberEval(-d); >+ } >+ >+ return retval; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryPlusEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryPlusEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryPlusEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryPlusEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,43 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+import org.apache.poi.hssf.record.formula.Ptg; >+import org.apache.poi.hssf.record.formula.UnaryPlusPtg; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class UnaryPlusEval implements OperationEval { >+ >+ private UnaryPlusPtg delegate; >+ >+ public UnaryPlusEval(Ptg ptg) { >+ this.delegate = (UnaryPlusPtg) ptg; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ return operands[0]; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands() >+ */ >+ public int getNumberOfOperands() { >+ return delegate.getNumberOfOperands(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType() >+ */ >+ public int getType() { >+ return delegate.getType(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ValueEval.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ValueEval.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ValueEval.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ValueEval.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,13 @@ >+/* >+ * Created on May 8, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.eval; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public interface ValueEval extends Eval { >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Abs.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Abs.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Abs.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Abs.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,56 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public class Abs extends DefaultFunctionImpl { >+ >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ ValueEval retval = null; >+ if (operands.length == 1) { >+ if (operands[0] !=null && operands[0] instanceof NumericValueEval) { >+ d = Math.abs(((NumericValueEval) operands[0]).getNumberValue()); >+ } >+ else if (operands[0] instanceof AreaEval) { >+ AreaEval ae = (AreaEval) operands[0]; >+ ValueEval v = ae.getValues()[0]; >+ if (v != null && v instanceof NumericValueEval) { >+ d = Math.abs(((NumericValueEval) v).getNumberValue()); >+ } >+ } >+ else if (operands[0] instanceof ErrorEval) { >+ ErrorEval e = (ErrorEval) operands[0]; >+ retval = e; >+ } >+ if (retval != null) >+ retval = new NumberEval(d); >+ } >+ else { >+ retval = ErrorEval.ERROR_508; >+ } >+ if (retval != null) { >+ retval = (Double.isNaN(d)) >+ ? (ValueEval) ErrorEval.ERROR_502 >+ : new NumberEval(d); >+ } >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,22 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.functions; >+ >+import org.apache.poi.hssf.record.formula.eval.Eval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Atan extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.DefaultFunctionImplEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ return super.evaluate(operands); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Average.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Average.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Average.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Average.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,75 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Average extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ int count = 0; >+ ValueEval retval = null; >+ for (int i=0, iSize=operands.length; i<iSize; i++) { >+ if (operands[i] == null) >+ continue; >+ if (operands[i] instanceof AreaEval) { >+ AreaEval ap = (AreaEval) operands[i]; >+ Object[] values = ap.getValues(); >+ for (int j=0, jSize=values.length; j<jSize; j++) { >+ if (values[j]==null) >+ continue; >+ if (values[j] instanceof NumericValueEval) { >+ d += ((NumericValueEval) values[j]).getNumberValue(); >+ count++; >+ } >+ else if (values[j] instanceof RefEval) { >+ RefEval re = (RefEval) values[j]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve!=null && ve instanceof NumericValueEval) { >+ d += ((NumericValueEval) ve).getNumberValue(); >+ count++; >+ } >+ } >+ } >+ } >+ else if (operands[i] instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) operands[i]; >+ d += np.getNumberValue(); >+ count++; >+ } >+ else if (operands[i] instanceof RefEval) { >+ RefEval re = (RefEval) operands[i]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ NumericValueEval ne = (NumericValueEval) ve; >+ d += ne.getNumberValue(); >+ count++; >+ } >+ } >+ } >+ >+ if (retval == null) { >+ retval = (Double.isNaN(d)) >+ ? (ValueEval) ErrorEval.ERROR_502 >+ : new NumberEval(d/count); >+ } >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Column.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Column.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Column.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Column.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,33 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.RefEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Column extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ Eval retval = null; >+ if (operands[0] instanceof RefEval) { >+ RefEval rp = (RefEval) operands[0]; >+ retval = new NumberEval(rp.getColumn()+1); >+ } >+ else { >+ retval = ErrorEval.ERROR_504; >+ } >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Cos.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Cos.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Cos.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Cos.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,55 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Cos extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ ValueEval retval = null; >+ double d = 0; >+ if (operands.length == 1) { >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) operands[0]; >+ d = Math.cos(np.getNumberValue()); >+ } >+ else if (operands[0] instanceof RefEval) { >+ RefEval re = (RefEval) operands[0]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve!=null && ve instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) ve; >+ d = Math.cos(np.getNumberValue()); >+ } >+ } >+ else if (operands[0] instanceof AreaEval) { >+ retval = ErrorEval.INVALID_VALUE; >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_508; >+ } >+ if (retval == null) >+ retval = new NumberEval(d); >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Count.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Count.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Count.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Count.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,63 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.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.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Count extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ int count = 0; >+ for (int i=0, iSize=operands.length; i<iSize; i++) { >+ if (operands[i] instanceof AreaEval) { >+ AreaEval ap = (AreaEval) operands[i]; >+ ValueEval[] values = ap.getValues(); >+ for (int j=0, jSize=values.length; j<jSize; j++) { >+ if (values[j]==null) >+ continue; >+ if ((values[j] instanceof NumericValueEval)) { >+ count++; >+ } >+ else if (values[j] instanceof RefEval){ >+ RefEval re = (RefEval) values[j]; >+ ValueEval ve = re.getInnerValueEval(); >+ if ((values[j] instanceof NumericValueEval)) { >+ count++; >+ } >+ } >+ } >+ } >+ else if (operands[i] instanceof NumericValueEval) { >+ count++; >+ } >+ else if (operands[i] instanceof RefEval){ >+ RefEval re = (RefEval) operands[i]; >+ ValueEval ve = re.getInnerValueEval(); >+ if ((operands[i] instanceof NumericValueEval)) { >+ count++; >+ } >+ } >+ } >+ >+ // TODO: --Note-- >+ // Count behaves (slightly) differently in Oo and Excel. >+ // Oo counts boolean values (whether true or false), Excel >+ // ignores booleans. Strings are ignored by both Oo and Excel. >+ return new NumberEval(count); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/DefaultFunctionImpl.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/DefaultFunctionImpl.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/DefaultFunctionImpl.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/DefaultFunctionImpl.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,21 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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; >+ >+/** >+ * >+ * @author amolweb < amolweb at ya hoo dot com > >+ */ >+public abstract class DefaultFunctionImpl implements Function { >+ >+ public Eval evaluate(Eval[] operands) { >+ return ErrorEval.FUNCTION_NOT_IMPLEMENTED; >+ } >+ >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dollar.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dollar.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dollar.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dollar.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,77 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+import org.apache.poi.hssf.record.formula.eval.StringEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Dollar extends DefaultFunctionImpl { >+ //private static final DecimalFormat DOLLAR_FORMAT = new DecimalFormat("$#,##0.0#"); >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ ValueEval retval = null; >+ if (operands[0] != null) { >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) operands[0]; >+ d = np.getNumberValue(); >+ } >+ else if (operands[0] instanceof RefEval) { >+ RefEval re = (RefEval) operands[0]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve!=null && ve instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) ve; >+ d = np.getNumberValue(); >+ } >+ } >+ else if (operands[0] instanceof AreaEval) { >+ retval = ErrorEval.INVALID_VALUE; >+ } >+ else if (operands[0] instanceof StringEval) { >+ StringEval se = (StringEval) operands[0]; >+ String s = se.getStringValue(); >+ try { >+ d = Double.parseDouble(s); >+ } catch (NumberFormatException nfe) { >+ retval = ErrorEval.INVALID_VALUE; >+ } >+ } >+ else { >+ d=Math.tan(0); >+ } >+ } >+ if (retval == null) { >+ retval = new NumberEval(d); >+ } >+ >+ // TODO: this is a little tricky function to implement: >+ // because while display value is a dollar format string, >+ // the type is treated as numeric when used in formulas. >+ // For now, the returned type is kept "NumberEval" >+ // since it will cause it to work better with other >+ // formulas. >+ // MoreImportantly, OpenOffice and Excel differ in their >+ // implementation of DOLLAR, Oo treats DOLLAr eval as >+ // String, Excel treats it as Number - This class >+ // treats it as a number but/hence does not do the >+ // formatting that DOLLAR should: In programs, this >+ // impl should be more useful. >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Exp.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Exp.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Exp.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Exp.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,36 @@ >+/* >+ * Created on May 6, 2005 >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Exp extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ ValueEval retval = null; >+ if (operands!=null) { >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) operands[0]; >+ d = Math.pow(Math.E, np.getNumberValue()); >+ } >+ else { >+ retval = ErrorEval.INVALID_VALUE; >+ } >+ } >+ if (retval == null) >+ retval = new NumberEval(d); >+ return retval; >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Fixed.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Fixed.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Fixed.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Fixed.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,127 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.functions; >+ >+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; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * <pre> >+ * Function spec: >+ * 1. numargs= 1-3 >+ * 2. args= 1: number; 2: decimal places; 3: show thousands separator? >+ * </pre> >+ */ >+public class Fixed extends DefaultFunctionImpl { >+ >+ private static final boolean DEFAULT_SHOW_THOUSANDS_SEP = true; >+ private static final int DEFAULT_NUM_DIGITS_AFTER_DECIMALS = 2; >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d; >+ boolean showThousandsSep = DEFAULT_SHOW_THOUSANDS_SEP; >+ int numdecimals=DEFAULT_NUM_DIGITS_AFTER_DECIMALS; >+ >+ switch (operands.length) { >+ case 3: >+ if (operands[2] instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) operands[2]; >+ showThousandsSep = np.getNumberValue() != 0; >+ } >+ else { >+ showThousandsSep = false; >+ } >+ case 2: >+ if (operands[1] instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) operands[1]; >+ numdecimals = (int) np.getNumberValue(); >+ } >+ else { >+ numdecimals = 0; >+ } >+ default: // 1 operand >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) operands[0]; >+ d = np.getNumberValue(); >+ } >+ else { >+ d = 0; >+ } >+ } >+ >+ // String str = formatDecimal(d, numdecimals, showThousandsSep); >+ // return new StringPtg(str); >+ // TODO: this is a little tricky function to implement: >+ // because while display value is a fixed format string, >+ // the type is treated as numeric when used in formulas. >+ // For now, the returned type is kept "NumberEval" >+ // since it will cause it to work better with other >+ // formulas. >+ // MoreImportantly, OpenOffice and Excel differ in their >+ // implementation of FIXED, Oo treats FIXED eval as >+ // String, Excel treats it as Number - This class >+ // treats it as a number but/hence does not do the >+ // formatting that FIXED should: In programs, this >+ // impl should be more useful. >+ // To switch to strictly Oo implementation, uncomment the >+ // 2 lines above this_TODO and remove the lines below >+ // this_TODO. >+ >+ return new NumberEval(d); >+ } >+ >+ /** >+ * return string representation of double with specified formatting options >+ * @param d >+ * @param numdecimals >+ * @param showT >+ * @return >+ */ >+ static final String formatDecimal(double d, int numdecimals, boolean showT) { >+ StringBuffer sb = new StringBuffer(50); // 50 => optimze for speed for common values >+ long integral = (long) d; >+ double fraction = d-integral; >+ >+ if (showT) { >+ String sintegral = String.valueOf(integral); >+ for (int i=sintegral.length()-1, j=1; i>=0; i--, j++) { >+ char c = sintegral.charAt(i); >+ sb.append(c); >+ if (j%3==0 && i!=0) sb.append(','); >+ } >+ sb.reverse(); >+ } >+ else { >+ sb.append(integral); >+ } >+ sb.append(ensureLength(fraction, numdecimals)); >+ return sb.toString(); >+ } >+ >+ // TODO: optimize this function >+ /** >+ * returns a truncated or padded String representation of >+ * double fraction. double fraction MUST be >0 && <1. >+ */ >+ static final String ensureLength(double fraction, int numdecimals) { >+ StringBuffer sb = new StringBuffer(); >+ if (numdecimals != 0) { >+ int ifraction = (int) (fraction * Math.pow(10, numdecimals)); >+ String sfraction = String.valueOf(ifraction); >+ >+ sb.append('.').append(ifraction); >+ for (int i=numdecimals-sfraction.length(); i>0; i--) { >+ sb.append('0'); >+ } >+ } >+ return sb.toString(); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Function.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Function.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Function.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Function.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,18 @@ >+/* >+ * Created on May 9, 2005 >+ * >+ * TODO To change the template for this generated file go to >+ * Window - Preferences - Java - Code Style - Code Templates >+ */ >+package org.apache.poi.hssf.record.formula.functions; >+ >+import org.apache.poi.hssf.record.formula.eval.Eval; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+public interface Function { >+ >+ public Eval evaluate(Eval[] operands); >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Int.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Int.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Int.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Int.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,52 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+import org.apache.poi.hssf.record.formula.eval.StringEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Int extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ ValueEval retval = null; >+ if (operands.length == 1) { >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval ne = (NumericValueEval) operands[0]; >+ d = ne.getNumberValue(); >+ } >+ else if (operands[0] instanceof RefEval) { >+ >+ } >+ else if (operands[0] instanceof StringEval) { >+ retval = ErrorEval.ERROR_502; >+ } >+ } >+ else if (operands.length > 1) { >+ retval = ErrorEval.ERROR_508; >+ } >+ else { >+ retval = ErrorEval.ERROR_511; >+ } >+ if (retval == null) { >+ retval = new NumberEval(d); >+ } >+ >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/IsError.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/IsError.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/IsError.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/IsError.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,26 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class IsError extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ boolean b = (operands[0] instanceof ErrorEval) || (operands[0] instanceof AreaEval); >+ return new BoolEval(b); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/IsNa.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/IsNa.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/IsNa.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/IsNa.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,25 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ * TODO To change the template for this generated file go to >+ * Window - Preferences - Java - Code Style - Code Templates >+ */ >+package org.apache.poi.hssf.record.formula.functions; >+ >+import org.apache.poi.hssf.record.formula.eval.Eval; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ * Window - Preferences - Java - Code Style - Code Templates >+ */ >+public class IsNa extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ return super.evaluate(operands); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Ln.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Ln.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Ln.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Ln.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,61 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Ln extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ ValueEval retval = null; >+ switch (operands.length) { >+ case 1: >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval ne = (NumericValueEval) operands[0]; >+ d = Math.log(ne.getNumberValue()); >+ } >+ else if (operands[0] instanceof RefEval) { >+ RefEval re = (RefEval) operands[0]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ NumericValueEval ne = (NumericValueEval) ve; >+ d = Math.log(ne.getNumberValue()); >+ } >+ } >+ else if (operands[0] instanceof AreaEval) { >+ retval = ErrorEval.INVALID_VALUE; >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ } >+ break; >+ case 0: >+ retval = ErrorEval.ERROR_502; >+ break; >+ default: >+ retval = ErrorEval.ERROR_508; >+ } >+ if (retval == null) { >+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.ERROR_503 : new NumberEval(d); >+ } >+ >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Log10.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Log10.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Log10.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Log10.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,63 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Log10 extends DefaultFunctionImpl { >+ private static final double LOG_10_TO_BASE_e = Math.log(10); >+ >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ ValueEval retval = null; >+ switch (operands.length) { >+ case 1: >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval ne = (NumericValueEval) operands[0]; >+ d = Math.log(ne.getNumberValue()); >+ } >+ else if (operands[0] instanceof RefEval) { >+ RefEval re = (RefEval) operands[0]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ NumericValueEval ne = (NumericValueEval) operands[0]; >+ d = Math.log(ne.getNumberValue()); >+ } >+ } >+ else if (operands[0] instanceof AreaEval) { >+ retval = ErrorEval.INVALID_VALUE; >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ } >+ break; >+ case 0: >+ retval = ErrorEval.ERROR_502; >+ break; >+ default: >+ retval = ErrorEval.ERROR_508; >+ } >+ if (retval != null) { >+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.ERROR_503 : new NumberEval(d/LOG_10_TO_BASE_e); >+ } >+ >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Max.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Max.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Max.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Max.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,54 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.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.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Max extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ for (int i=0, iSize=operands.length; i<iSize; i++) { >+ if (operands[i] instanceof AreaEval) { >+ AreaEval ap = (AreaEval) operands[i]; >+ ValueEval[] values = ap.getValues(); >+ for (int j=0, jSize=values.length; j<jSize; j++) { >+ if (values[j]!=null) { >+ if (values[j] instanceof NumericValueEval) { >+ d = Math.max(((NumericValueEval) values[j]).getNumberValue(), d); >+ } >+ else if (values[j] instanceof RefEval) { >+ ValueEval ve = ((RefEval) values[j]).getInnerValueEval(); >+ if (ve!=null) >+ d = Math.max(((NumericValueEval) ve).getNumberValue(), d); >+ } >+ } >+ } >+ } >+ else if (operands[i] instanceof NumericValueEval) { >+ d = Math.max(((NumericValueEval) operands[i]).getNumberValue(), d); >+ } >+ else if (operands[i] instanceof RefEval) { >+ ValueEval ve = ((RefEval) operands[i]).getInnerValueEval(); >+ if (ve!=null) >+ d = Math.max(((NumericValueEval) ve).getNumberValue(), d); >+ } >+ } >+ >+ return new NumberEval(d); >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Min.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Min.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Min.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Min.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,54 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.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.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Min extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ for (int i=0, iSize=operands.length; i<iSize; i++) { >+ if (operands[i] instanceof AreaEval) { >+ AreaEval ap = (AreaEval) operands[i]; >+ ValueEval[] values = ap.getValues(); >+ for (int j=0, jSize=values.length; j<jSize; j++) { >+ if (values[j]!=null) { >+ if (values[j] instanceof NumericValueEval) { >+ d = Math.min(((NumericValueEval) values[j]).getNumberValue(), d); >+ } >+ else if (values[j] instanceof RefEval) { >+ ValueEval ve = ((RefEval) values[j]).getInnerValueEval(); >+ if (ve!=null) >+ d = Math.min(((NumericValueEval) ve).getNumberValue(), d); >+ } >+ } >+ } >+ } >+ else if (operands[i] instanceof NumericValueEval) { >+ d = Math.min(((NumericValueEval) operands[i]).getNumberValue(), d); >+ } >+ else if (operands[i] instanceof RefEval) { >+ ValueEval ve = ((RefEval) operands[i]).getInnerValueEval(); >+ if (ve!=null) >+ d = Math.min(((NumericValueEval) ve).getNumberValue(), d); >+ } >+ } >+ >+ return new NumberEval(d); >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Na.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Na.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Na.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Na.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,24 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.functions; >+ >+import org.apache.poi.hssf.record.formula.eval.Eval; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+ >+public class Na extends DefaultFunctionImpl { >+ >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ return super.evaluate(operands); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Npv.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Npv.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Npv.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Npv.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,91 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > >+ * >+ */ >+ >+public class Npv extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Eval[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ double rate = 0; >+ ValueEval retval = null; >+ >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) operands[0]; >+ rate = np.getNumberValue(); >+ } >+ else if (operands[0] instanceof RefEval) { >+ RefEval re = (RefEval) operands[0]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) ve; >+ rate = np.getNumberValue(); >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_503; >+ } >+ double denomVal = rate+1; >+ >+ if (retval == null) { >+ for (int i=1, k=1, iSize=operands.length; i<iSize; i++) { >+ if (operands[i] instanceof AreaEval) { >+ AreaEval ap = (AreaEval) operands[i]; >+ Object[] values = ap.getValues(); >+ for (int j=0, jSize=values.length; j<jSize; j++) { >+ if (values[j]==null || !(values[j] instanceof Number)) >+ continue; >+ double value = ((Number) values[j]).doubleValue(); >+ d += value / denomVal; >+ denomVal = (rate+1) * denomVal; >+ } >+ } >+ else if (operands[i] instanceof NumericValueEval) { >+ NumberEval np = (NumberEval) operands[i]; >+ double value = np.getNumberValue(); >+ d += value / denomVal; >+ denomVal = (rate+1) * denomVal; >+ } >+ else if (operands[i] instanceof RefEval) { >+ RefEval re = (RefEval) operands[i]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ NumberEval np = (NumberEval) ve; >+ double value = np.getNumberValue(); >+ d += value / denomVal; >+ denomVal = (rate+1) * denomVal; >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_503; >+ } >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_503; >+ } >+ >+ if (retval == null) >+ retval = new NumberEval(d); >+ >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Pi.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Pi.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Pi.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Pi.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,25 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.functions; >+ >+import org.apache.poi.hssf.record.formula.eval.Eval; >+import org.apache.poi.hssf.record.formula.eval.NumberEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Pi extends DefaultFunctionImpl { >+ >+ private static final NumberEval PI_EVAL = new NumberEval(Math.PI); >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ return PI_EVAL; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Round.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Round.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Round.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Round.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,74 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Round extends DefaultFunctionImpl { >+ >+ private static final short DEFAULT_ACCURACY = 0; >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ short accuracy = DEFAULT_ACCURACY; >+ double d = 0; >+ ValueEval retval = null; >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval bp = (NumericValueEval) operands[0]; >+ d = bp.getNumberValue(); >+ } >+ else if (operands[0] instanceof RefEval) { >+ RefEval re = (RefEval) operands[0]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ NumericValueEval n = (NumericValueEval) ve; >+ d = n.getNumberValue(); >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ } >+ >+ if (operands.length == 2) { >+ if (operands[1] instanceof NumericValueEval) { >+ NumericValueEval bp = (NumericValueEval) operands[0]; >+ accuracy = (short) bp.getNumberValue(); >+ } >+ else if (operands[1] instanceof RefEval) { >+ RefEval re = (RefEval) operands[1]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ NumericValueEval n = (NumericValueEval) ve; >+ accuracy = (short) n.getNumberValue(); >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ } >+ } >+ else if (operands.length > 2) { >+ retval = ErrorEval.ERROR_504; >+ } >+ if (retval == null) { >+ double power = Math.pow(10, accuracy); >+ d *= power; >+ d = Math.round(d); >+ retval = new NumberEval(d/power); >+ } >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Row.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Row.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Row.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Row.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,33 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.RefEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Row extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ Eval retval = null; >+ if (operands[0] instanceof RefEval) { >+ RefEval rp = (RefEval) operands[0]; >+ retval = new NumberEval(rp.getRow()+1); >+ } >+ else { >+ retval = ErrorEval.ERROR_504; >+ } >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sign.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sign.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sign.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sign.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.functions; >+ >+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 amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Sign extends DefaultFunctionImpl { >+ >+ private static final NumberEval NEG_SIGN_EVAL = new NumberEval(-1); >+ private static final NumberEval POS_SIGN_EVAL = new NumberEval(1); >+ private static final NumberEval ZERO_SIGN_EVAL = new NumberEval(0); >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ ValueEval retval = null; >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval nve = (NumericValueEval) operands[0]; >+ d = nve.getNumberValue(); >+ } >+ if (d == 0) { >+ retval = ZERO_SIGN_EVAL; >+ } >+ else if (d < 0) { >+ retval = NEG_SIGN_EVAL; >+ } >+ else if (d > 0) { >+ retval = POS_SIGN_EVAL; >+ } >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sin.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sin.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sin.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sin.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,55 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Sin extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ ValueEval retval = null; >+ double d = 0; >+ if (operands.length == 1) { >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) operands[0]; >+ d = Math.sin(np.getNumberValue()); >+ } >+ else if (operands[0] instanceof RefEval) { >+ RefEval re = (RefEval) operands[0]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve!=null && ve instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) ve; >+ d = Math.sin(np.getNumberValue()); >+ } >+ } >+ else if (operands[0] instanceof AreaEval) { >+ retval = ErrorEval.INVALID_VALUE; >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_508; >+ } >+ if (retval == null) >+ retval = new NumberEval(d); >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sqrt.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sqrt.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sqrt.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sqrt.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,56 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Sqrt extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ ValueEval retval = null; >+ double d = 0; >+ if (operands.length == 1) { >+ if (operands[0] instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) operands[0]; >+ d = Math.sqrt(np.getNumberValue()); >+ } >+ else if (operands[0] instanceof RefEval) { >+ RefEval re = (RefEval) operands[0]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve!=null && ve instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) ve; >+ d = Math.sqrt(np.getNumberValue()); >+ } >+ } >+ else if (operands[0] instanceof AreaEval) { >+ retval = ErrorEval.INVALID_VALUE; >+ } >+ else { >+ retval = ErrorEval.ERROR_502; >+ } >+ } >+ else { >+ retval = ErrorEval.ERROR_508; >+ } >+ if (retval != null) { >+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.ERROR_502 : new NumberEval(d); >+ } >+ return retval; >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Stdev.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Stdev.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Stdev.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Stdev.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,79 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.functions; >+ >+import org.apache.poi.hssf.record.formula.eval.Eval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Stdev extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ return super.evaluate(operands); >+// double mean = 0; >+// int count = 0; >+// double numerator = 0; >+// >+// for (int i=0, iSize=operands.length; i<iSize; i++) { >+// if (operands[i] instanceof AreaPtg) { >+// AreaPtg ap = (AreaPtg) operands[i]; >+// Object[] values = ap.getValues(); >+// for (int j=0, jSize=values.length; j<jSize; j++) { >+// if (values[j]!=null && !(values[j] instanceof Number)) { >+// mean += ((Number) values[j]).doubleValue(); >+// count++; >+// } >+// else if (values[j] instanceof Boolean) { >+// mean += ((Boolean) values[j]).booleanValue() ? 1 : 0; >+// count++; >+// } >+// } >+// } >+// else if (operands[i] instanceof IntPtg) { >+// IntPtg ip = (IntPtg) operands[i]; >+// mean += ip.getValue(); >+// count++; >+// } >+// else if (operands[i] instanceof NumberPtg) { >+// NumberPtg np = (NumberPtg) operands[i]; >+// mean += np.getValue(); >+// count++; >+// } >+// } >+// mean /= count; >+// >+// for (int i=0, iSize=operands.length; i<iSize; i++) { >+// if (operands[i] instanceof AreaPtg) { >+// AreaPtg ap = (AreaPtg) operands[i]; >+// Object[] values = ap.getValues(); >+// for (int j=0, jSize=values.length; j<jSize; j++) { >+// if (values[j]==null || !(values[j] instanceof Number)) >+// continue; >+// double d = (((Number) values[j]).doubleValue() - mean); >+// numerator += d*d; >+// } >+// } >+// else if (operands[i] instanceof IntPtg) { >+// IntPtg ip = (IntPtg) operands[i]; >+// double d = (ip.getValue() - mean); >+// numerator += d*d; >+// } >+// else if (operands[i] instanceof NumberPtg) { >+// NumberPtg np = (NumberPtg) operands[i]; >+// double d = (np.getValue() - mean); >+// numerator += d*d; >+// } >+// } >+// >+// >+// return new NumberPtg(Math.sqrt(mean/(count-1))); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sum.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sum.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sum.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sum.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,68 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+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.NumericValueEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Sum extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ double d = 0; >+ ValueEval retval = null; >+ for (int i=0, iSize=operands.length; i<iSize; i++) { >+ if (operands[i] == null) >+ continue; >+ if (operands[i] instanceof AreaEval) { >+ AreaEval ap = (AreaEval) operands[i]; >+ Object[] values = ap.getValues(); >+ for (int j=0, jSize=values.length; j<jSize; j++) { >+ if (values[j]==null) >+ continue; >+ if (values[j] instanceof NumericValueEval) { >+ d += ((NumericValueEval) values[j]).getNumberValue(); >+ } >+ else if (values[j] instanceof RefEval) { >+ RefEval re = (RefEval) values[j]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve!=null && ve instanceof NumericValueEval) { >+ d += ((NumericValueEval) ve).getNumberValue(); >+ } >+ } >+ } >+ } >+ else if (operands[i] instanceof NumericValueEval) { >+ NumericValueEval np = (NumericValueEval) operands[i]; >+ d += np.getNumberValue(); >+ } >+ else if (operands[i] instanceof RefEval) { >+ RefEval re = (RefEval) operands[i]; >+ ValueEval ve = re.getInnerValueEval(); >+ if (ve instanceof NumericValueEval) { >+ NumericValueEval ne = (NumericValueEval) ve; >+ d += ne.getNumberValue(); >+ } >+ } >+ } >+ >+ if (retval == null) { >+ retval = (Double.isNaN(d)) >+ ? (ValueEval) ErrorEval.ERROR_502 >+ : new NumberEval(d); >+ } >+ return retval; } >+} >Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Tan.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Tan.java >diff -N src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Tan.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Tan.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,45 @@ >+/* >+ * Created on May 6, 2005 >+ * >+ */ >+package org.apache.poi.hssf.record.formula.functions; >+ >+import org.apache.poi.hssf.record.formula.eval.Eval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ */ >+public class Tan extends DefaultFunctionImpl { >+ >+ /* (non-Javadoc) >+ * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[]) >+ */ >+ public Eval evaluate(Eval[] operands) { >+ return super.evaluate(operands); >+// double d; >+// if (operands[0] instanceof IntPtg) { >+// IntPtg np = (IntPtg) operands[0]; >+// d = Math.tan(np.getValue()); >+// } >+// else if (operands[0] instanceof NumberPtg) { >+// NumberPtg np = (NumberPtg) operands[0]; >+// d = Math.tan(np.getValue()); >+// } >+// else if (operands[0] instanceof AreaPtg) { >+// d=Double.NaN; // TODO: Fix this: check with excel, Oo does weird things with Area refs >+// } >+// else if (operands[0] instanceof BoolPtg) { >+// BoolPtg bp = (BoolPtg) operands[0]; >+// d=bp.getValue() ? Math.tan(1) : Math.tan(0); >+// } >+// else if (operands[0] instanceof StringPtg) { >+// d=Math.tan(0); >+// } >+// else { >+// d=Math.tan(0); >+// } >+// return new NumberPtg(d); >+ } >+ >+} >Index: src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java >=================================================================== >RCS file: src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java >diff -N src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,480 @@ >+/* >+ * Created on May 5, 2005 >+ * >+ */ >+package org.apache.poi.hssf.usermodel; >+import java.io.FileInputStream; >+import java.lang.reflect.Constructor; >+import java.util.HashMap; >+import java.util.Map; >+import java.util.Stack; >+ >+import org.apache.poi.hssf.model.FormulaParser; >+import org.apache.poi.hssf.record.formula.AddPtg; >+import org.apache.poi.hssf.record.formula.Area3DPtg; >+import org.apache.poi.hssf.record.formula.AreaPtg; >+import org.apache.poi.hssf.record.formula.AttrPtg; >+import org.apache.poi.hssf.record.formula.BoolPtg; >+import org.apache.poi.hssf.record.formula.ConcatPtg; >+import org.apache.poi.hssf.record.formula.ControlPtg; >+import org.apache.poi.hssf.record.formula.DividePtg; >+import org.apache.poi.hssf.record.formula.EqualPtg; >+import org.apache.poi.hssf.record.formula.FuncPtg; >+import org.apache.poi.hssf.record.formula.FuncVarPtg; >+import org.apache.poi.hssf.record.formula.GreaterEqualPtg; >+import org.apache.poi.hssf.record.formula.GreaterThanPtg; >+import org.apache.poi.hssf.record.formula.IntPtg; >+import org.apache.poi.hssf.record.formula.LessEqualPtg; >+import org.apache.poi.hssf.record.formula.LessThanPtg; >+import org.apache.poi.hssf.record.formula.MemErrPtg; >+import org.apache.poi.hssf.record.formula.MissingArgPtg; >+import org.apache.poi.hssf.record.formula.MultiplyPtg; >+import org.apache.poi.hssf.record.formula.NamePtg; >+import org.apache.poi.hssf.record.formula.NameXPtg; >+import org.apache.poi.hssf.record.formula.NotEqualPtg; >+import org.apache.poi.hssf.record.formula.NumberPtg; >+import org.apache.poi.hssf.record.formula.OperationPtg; >+import org.apache.poi.hssf.record.formula.ParenthesisPtg; >+import org.apache.poi.hssf.record.formula.PowerPtg; >+import org.apache.poi.hssf.record.formula.Ptg; >+import org.apache.poi.hssf.record.formula.Ref3DPtg; >+import org.apache.poi.hssf.record.formula.ReferencePtg; >+import org.apache.poi.hssf.record.formula.StringPtg; >+import org.apache.poi.hssf.record.formula.SubtractPtg; >+import org.apache.poi.hssf.record.formula.UnaryMinusPtg; >+import org.apache.poi.hssf.record.formula.UnaryPlusPtg; >+import org.apache.poi.hssf.record.formula.UnionPtg; >+import org.apache.poi.hssf.record.formula.UnknownPtg; >+import org.apache.poi.hssf.record.formula.eval.AddEval; >+import org.apache.poi.hssf.record.formula.eval.Area2DEval; >+import org.apache.poi.hssf.record.formula.eval.Area3DEval; >+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.ConcatEval; >+import org.apache.poi.hssf.record.formula.eval.DivideEval; >+import org.apache.poi.hssf.record.formula.eval.EqualEval; >+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.FuncVarEval; >+import org.apache.poi.hssf.record.formula.eval.GreaterEqualEval; >+import org.apache.poi.hssf.record.formula.eval.GreaterThanEval; >+import org.apache.poi.hssf.record.formula.eval.LessEqualEval; >+import org.apache.poi.hssf.record.formula.eval.LessThanEval; >+import org.apache.poi.hssf.record.formula.eval.MultiplyEval; >+import org.apache.poi.hssf.record.formula.eval.NotEqualEval; >+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.OperationEval; >+import org.apache.poi.hssf.record.formula.eval.PowerEval; >+import org.apache.poi.hssf.record.formula.eval.Ref2DEval; >+import org.apache.poi.hssf.record.formula.eval.Ref3DEval; >+import org.apache.poi.hssf.record.formula.eval.RefEval; >+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.SubtractEval; >+import org.apache.poi.hssf.record.formula.eval.UnaryMinusEval; >+import org.apache.poi.hssf.record.formula.eval.UnaryPlusEval; >+import org.apache.poi.hssf.record.formula.eval.ValueEval; >+ >+/** >+ * @author amolweb < amolweb at ya hoo dot com > >+ * >+ * Limitations: >+ * Unfortunately, cyclic references will cause stackoverflow exception >+ */ >+public class HSSFFormulaEvaluator { >+ >+ // params to lookup the right constructor using reflection >+ private static final Class[] OPERATION_CONTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class}; >+ private static final Class[] VALUE_CONTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class}; >+ private static final Class[] AREA_CONSTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class, ValueEval[].class}; >+ private static final Class[] AREA3D_CONSTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class, ValueEval[].class}; >+ private static final Class[] REFERENCE_CONSTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class, ValueEval.class}; >+ private static final Class[] REF3D_CONSTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class, ValueEval.class}; >+ >+ // Maps for mapping *Eval to *Ptg >+ private static final Map VALUE_EVALS_MAP = new HashMap(); >+ private static final Map OPERATION_EVALS_MAP = new HashMap(); >+ >+ >+ /* >+ * If you dont like this map, join the club :) >+ * I did this becoz it was desired to keep the FormulaEvaluator >+ * separate from FormulaParser and related classes in the CVS-HEAD. >+ * So now we need some mapping between the Ptg tokens that >+ * the FormulaParser returns and the *Eval classes taht >+ * are used by the FormulaEvaluator - hence the following :) >+ */ >+static { >+ VALUE_EVALS_MAP.put(BoolPtg.class, BoolEval.class); >+ VALUE_EVALS_MAP.put(IntPtg.class, NumberEval.class); >+ VALUE_EVALS_MAP.put(NumberPtg.class, NumberEval.class); >+ VALUE_EVALS_MAP.put(StringPtg.class, StringEval.class); >+ >+ OPERATION_EVALS_MAP.put(AddPtg.class, AddEval.class); >+ OPERATION_EVALS_MAP.put(ConcatPtg.class, ConcatEval.class); >+ OPERATION_EVALS_MAP.put(DividePtg.class, DivideEval.class); >+ OPERATION_EVALS_MAP.put(EqualPtg.class, EqualEval.class); >+ //OPERATION_EVALS_MAP.put(ExpPtg.class, ExpEval.class); // TODO: check this >+ OPERATION_EVALS_MAP.put(FuncPtg.class, FuncVarEval.class); // TODO: check this >+ OPERATION_EVALS_MAP.put(FuncVarPtg.class, FuncVarEval.class); >+ OPERATION_EVALS_MAP.put(GreaterEqualPtg.class, GreaterEqualEval.class); >+ OPERATION_EVALS_MAP.put(GreaterThanPtg.class, GreaterThanEval.class); >+ OPERATION_EVALS_MAP.put(LessEqualPtg.class, LessEqualEval.class); >+ OPERATION_EVALS_MAP.put(LessThanPtg.class, LessThanEval.class); >+ OPERATION_EVALS_MAP.put(MultiplyPtg.class, MultiplyEval.class); >+ OPERATION_EVALS_MAP.put(NotEqualPtg.class, NotEqualEval.class); >+ OPERATION_EVALS_MAP.put(PowerPtg.class, PowerEval.class); >+ OPERATION_EVALS_MAP.put(SubtractPtg.class, SubtractEval.class); >+ OPERATION_EVALS_MAP.put(UnaryMinusPtg.class, UnaryMinusEval.class); >+ OPERATION_EVALS_MAP.put(UnaryPlusPtg.class, UnaryPlusEval.class); >+ >+ >+} >+ >+ >+ /** >+ * debug method >+ * @param formula >+ * @param sheet >+ * @param workbook >+ */ >+ static void inspectPtgs(String formula, HSSFSheet sheet, HSSFWorkbook workbook) { >+ FormulaParser fp = new FormulaParser(formula, workbook.getWorkbook()); >+ fp.parse(); >+ Ptg[] ptgs = fp.getRPNPtg(); >+ System.out.println("<ptg-group>"); >+ for (int i=0, iSize=ptgs.length; i<iSize; i++) { >+ System.out.println("<ptg>"); >+ System.out.println(ptgs[i]); >+ if (ptgs[i] instanceof OperationPtg) { >+ System.out.println("numoperands: " + ((OperationPtg) ptgs[i]).getNumberOfOperands()); >+ } >+ System.out.println("</ptg>"); >+ } >+ } >+ >+ /** >+ * returns the string value resulting from teh evaluation of the formula >+ * @param formula >+ * @param sheet >+ * @param workbook >+ * @return >+ */ >+ public static String evaluateToString(String formula, HSSFSheet sheet, HSSFWorkbook workbook) { >+ String retval = null; >+ Eval value = evaluate(formula, sheet, workbook); >+ if (value instanceof NumericValueEval) { >+ NumericValueEval ne = (NumericValueEval) value; >+ retval = String.valueOf(ne.getNumberValue()); >+ } >+ else if (value instanceof StringValueEval) { >+ StringValueEval se = (StringValueEval) value; >+ retval = se.getStringValue(); >+ } >+ else { >+ retval = value.getClass().getName(); >+ } >+ return retval; >+ } >+ >+ /** >+ * evaluates a formula!!! :) >+ * @param formula >+ * @param sheet >+ * @param workbook >+ * @return >+ */ >+ private static Eval evaluate(String formula, HSSFSheet sheet, HSSFWorkbook workbook) { >+ FormulaParser parser = new FormulaParser(formula, workbook.getWorkbook()); >+ parser.parse(); >+ Ptg[] ptgs = parser.getRPNPtg(); >+ // -- parsing over -- >+ >+ Stack stack = new Stack(); >+ for (int i=0, iSize=ptgs.length; i<iSize; i++) { >+ if (ptgs[i] instanceof ControlPtg) {continue;} >+ if (ptgs[i] instanceof MemErrPtg) {continue;} >+ if (ptgs[i] instanceof MissingArgPtg) {continue;} >+ if (ptgs[i] instanceof NamePtg) {continue;} >+ if (ptgs[i] instanceof NameXPtg) {continue;} >+ if (ptgs[i] instanceof UnknownPtg) {continue;} >+ >+ >+ if (ptgs[i] instanceof OperationPtg) { >+ OperationPtg optg = (OperationPtg) ptgs[i]; >+ >+ if (optg instanceof ParenthesisPtg) {continue;} >+ if (optg instanceof AttrPtg) {continue;} >+ if (optg instanceof UnionPtg) {continue;} >+ >+ OperationEval operation = (OperationEval) getOperationEvalForPtg(optg); >+ >+ int numops = operation.getNumberOfOperands(); >+ Eval[] ops = new Eval[numops]; >+ for (int j=numops-1; j>=0; j--) { // storing the ops in reverse order since they are popping ;) >+ Eval p = (Eval) stack.pop(); >+ ops[j] = p; >+ } >+ Eval opresult = operation.evaluate(ops); >+ stack.push(opresult); >+ } >+ else if (ptgs[i] instanceof ReferencePtg) { >+ ReferencePtg ptg = (ReferencePtg) ptgs[i]; >+ short colnum = ptg.getColumn(); >+ short rownum = ptg.getRow(); >+ HSSFRow row = sheet.getRow(rownum); >+ HSSFCell cell = (row!=null) ? row.getCell(colnum) : null; >+ pushRef2DEval(ptg, stack, cell, sheet, workbook); >+ } >+ else if (ptgs[i] instanceof Ref3DPtg) { >+ Ref3DPtg ptg = (Ref3DPtg) ptgs[i]; >+ short colnum = ptg.getColumn(); >+ short rownum = ptg.getRow(); >+ HSSFSheet xsheet = workbook.getSheetAt(ptg.getExternSheetIndex()); >+ HSSFRow row = sheet.getRow(rownum); >+ HSSFCell cell = (row!=null) ? row.getCell(colnum) : null; >+ pushRef3DEval(ptg, stack, cell, sheet, workbook); >+ } >+ else if (ptgs[i] instanceof AreaPtg) { >+ AreaPtg ap = (AreaPtg) ptgs[i]; >+ short row0 = ap.getFirstRow(); >+ short col0 = ap.getFirstColumn(); >+ short row1 = ap.getLastRow(); >+ short col1 = ap.getLastColumn(); >+ ValueEval[] values = new ValueEval[(row1-row0+1)*(col1-col0+1)]; >+ for (short x=row0; sheet!=null && x<row1+1; x++) { >+ HSSFRow row = sheet.getRow(x); >+ for (short y=col0; row!=null && y<col1+1; y++) { >+ values[(x-row0)*(col1-col0+1)+(y-col0)] = getEvalForCell(row.getCell(y), sheet, workbook); >+ } >+ } >+ AreaEval ae = new Area2DEval(ap, values); >+ stack.push(ae); >+ } >+ else if (ptgs[i] instanceof Area3DPtg) { >+ Area3DPtg a3dp = (Area3DPtg) ptgs[i]; >+ short row0 = a3dp.getFirstRow(); >+ short col0 = a3dp.getFirstColumn(); >+ short row1 = a3dp.getLastRow(); >+ short col1 = a3dp.getLastColumn(); >+ HSSFSheet xsheet = workbook.getSheetAt(a3dp.getExternSheetIndex()); >+ ValueEval[] values = new ValueEval[(row1-row0+1)*(col1-col0+1)]; >+ for (short x=row0; sheet!=null && x<row1+1; x++) { >+ HSSFRow row = sheet.getRow(x); >+ for (short y=col0; row!=null && y<col1+1; y++) { >+ values[(x-row0)*(col1-col0+1)+(y-col0)] = getEvalForCell(row.getCell(y), sheet, workbook); >+ } >+ } >+ AreaEval ae = new Area3DEval(a3dp, values); >+ stack.push(ae); >+ } >+ else { >+ Eval ptgEval = getEvalForPtg(ptgs[i]); >+ stack.push(ptgEval); >+ } >+ } >+ Eval value = ((Eval) stack.pop()); >+ if (value instanceof RefEval) { >+ RefEval rv = (RefEval) value; >+ value = rv.getInnerValueEval(); >+ } >+ return value; >+ } >+ >+ protected static Eval getOperationEvalForPtg(OperationPtg ptg) { >+ Eval retval = null; >+ >+ Class clazz = (Class) OPERATION_EVALS_MAP.get(ptg.getClass()); >+ try { >+ Constructor constructor = clazz.getConstructor(OPERATION_CONTRUCTOR_CLASS_ARRAY); >+ retval = (OperationEval) constructor.newInstance(new Ptg[]{ptg}); >+ } >+ catch (Exception e) {throw new RuntimeException("Fatal Error: ", e);} >+ return retval; >+ } >+ >+ >+ /** >+ * returns an appropriate Eval impl instance for the Ptg. >+ * The Ptg must be one of: >+ * Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, >+ * NumberPtg, StringPtg, BoolPtg >+ * <br/> >+ * special Note: OperationPtg subtypes cannot be passed here! >+ * @param ptg >+ * @return >+ */ >+ protected static Eval getEvalForPtg(Ptg ptg) { >+ Eval retval = null; >+ >+ Class clazz = (Class) VALUE_EVALS_MAP.get(ptg.getClass()); >+ try { >+ if (ptg instanceof Area3DPtg) { >+ Constructor constructor = clazz.getConstructor(AREA3D_CONSTRUCTOR_CLASS_ARRAY); >+ retval = (OperationEval) constructor.newInstance(new Ptg[]{ptg}); >+ } >+ else if (ptg instanceof AreaPtg) { >+ Constructor constructor = clazz.getConstructor(AREA3D_CONSTRUCTOR_CLASS_ARRAY); >+ retval = (OperationEval) constructor.newInstance(new Ptg[]{ptg}); >+ } >+ else if (ptg instanceof ReferencePtg) { >+ Constructor constructor = clazz.getConstructor(REFERENCE_CONSTRUCTOR_CLASS_ARRAY); >+ retval = (OperationEval) constructor.newInstance(new Ptg[]{ptg}); >+ } >+ else if (ptg instanceof Ref3DPtg) { >+ Constructor constructor = clazz.getConstructor(REF3D_CONSTRUCTOR_CLASS_ARRAY); >+ retval = (OperationEval) constructor.newInstance(new Ptg[]{ptg}); >+ } >+ else { >+ if (ptg instanceof IntPtg >+ || ptg instanceof NumberPtg >+ || ptg instanceof StringPtg >+ || ptg instanceof BoolPtg >+ ) { >+ Constructor constructor = clazz.getConstructor(VALUE_CONTRUCTOR_CLASS_ARRAY); >+ retval = (ValueEval) constructor.newInstance(new Ptg[]{ptg}); >+ } >+ } >+ } catch (Exception e) { >+ throw new RuntimeException("Fatal Error: ", e); >+ } >+ return retval; >+ >+ } >+ >+ /** >+ * Given a cell, find its type and from that create an appropriate ValueEval impl instance >+ * and return that. Since the cell could be an external reference, we need the sheet that >+ * this belongs to. >+ * @param cell >+ * @param sheet >+ * @param workbook >+ * @return >+ */ >+ protected static ValueEval getEvalForCell(HSSFCell cell, HSSFSheet sheet, HSSFWorkbook workbook) { >+ ValueEval retval = null; >+ if (cell != null) { >+ switch (cell.getCellType()) { >+ case HSSFCell.CELL_TYPE_NUMERIC: >+ retval = new NumberEval(cell.getNumericCellValue()); >+ break; >+ case HSSFCell.CELL_TYPE_STRING: >+ retval = new StringEval(cell.getStringCellValue()); >+ break; >+ case HSSFCell.CELL_TYPE_FORMULA: >+ retval = (ValueEval) evaluate(cell.getCellFormula(), sheet, workbook); >+ break; >+ case HSSFCell.CELL_TYPE_BOOLEAN: >+ retval = new BoolEval(cell.getBooleanCellValue()); >+ break; >+ case HSSFCell.CELL_TYPE_BLANK: >+ retval = new StringEval(""); >+ break; >+ case HSSFCell.CELL_TYPE_ERROR: >+ retval = ErrorEval.ERROR_UNKNOWN; // TODO: think about this... >+ break; >+ } >+ } >+ return retval; >+ } >+ >+ /** >+ * create a Ref2DEval for ReferencePtg and push it on the stack. >+ * @param ptg >+ * @param stack >+ * @param cell >+ * @param sheet >+ * @param workbook >+ */ >+ protected static void pushRef2DEval(ReferencePtg ptg, Stack stack, HSSFCell cell, HSSFSheet sheet, HSSFWorkbook workbook) { >+ if (cell!=null) >+ switch (cell.getCellType()) { >+ case HSSFCell.CELL_TYPE_NUMERIC: >+ stack.push(new Ref2DEval(ptg, new NumberEval(cell.getNumericCellValue()))); >+ break; >+ case HSSFCell.CELL_TYPE_STRING: >+ stack.push(new Ref2DEval(ptg, new StringEval(cell.getStringCellValue()))); >+ break; >+ case HSSFCell.CELL_TYPE_FORMULA: >+ stack.push(evaluate(cell.getCellFormula(), sheet, workbook)); >+ break; >+ case HSSFCell.CELL_TYPE_BOOLEAN: >+ stack.push(new Ref2DEval(ptg, new BoolEval(cell.getBooleanCellValue()))); >+ break; >+ case HSSFCell.CELL_TYPE_BLANK: >+ stack.push(new Ref2DEval(ptg, new StringEval(""))); >+ break; >+ case HSSFCell.CELL_TYPE_ERROR: >+ stack.push(new Ref2DEval(ptg, ErrorEval.ERROR_UNKNOWN)); // TODO: think about this... >+ break; >+ } >+ else { >+ stack.push(new Ref2DEval(ptg, new StringEval(""))); >+ } >+ } >+ >+ /** >+ * create a Ref3DEval for Ref3DPtg and push it on the stack. >+ * @param ptg >+ * @param stack >+ * @param cell >+ * @param sheet >+ * @param workbook >+ */ >+ protected static void pushRef3DEval(Ref3DPtg ptg, Stack stack, HSSFCell cell, HSSFSheet sheet, HSSFWorkbook workbook) { >+ if (cell!=null) >+ switch (cell.getCellType()) { >+ case HSSFCell.CELL_TYPE_NUMERIC: >+ stack.push(new Ref3DEval(ptg, new NumberEval(cell.getNumericCellValue()))); >+ break; >+ case HSSFCell.CELL_TYPE_STRING: >+ stack.push(new Ref3DEval(ptg, new StringEval(cell.getStringCellValue()))); >+ break; >+ case HSSFCell.CELL_TYPE_FORMULA: >+ stack.push(evaluate(cell.getCellFormula(), sheet, workbook)); >+ break; >+ case HSSFCell.CELL_TYPE_BOOLEAN: >+ stack.push(new Ref3DEval(ptg, new BoolEval(cell.getBooleanCellValue()))); >+ break; >+ case HSSFCell.CELL_TYPE_BLANK: >+ stack.push(new Ref3DEval(ptg, new StringEval(""))); >+ break; >+ case HSSFCell.CELL_TYPE_ERROR: >+ stack.push(new Ref3DEval(ptg, ErrorEval.ERROR_UNKNOWN)); // TODO: think about this... >+ break; >+ } >+ else { >+ stack.push(new Ref3DEval(ptg, new StringEval(""))); >+ } >+ } >+ >+ >+ >+ /** >+ * Manual testing... needs a c:/temp/test1.xls file to be present. >+ * @param args >+ * @throws Exception >+ */ >+ public static void main(String[] args) throws Exception { >+ String FILE_NAME = "c:/temp/test1.xls"; >+ >+ FileInputStream fis = new FileInputStream(FILE_NAME); >+ HSSFWorkbook wb = new HSSFWorkbook(fis); >+ fis.close(); >+ HSSFSheet sheet = wb.getSheetAt(0); >+ >+ for (int rn=1, rnSize=4; rn<=rnSize; rn++) { >+ HSSFRow row = sheet.getRow(rn); >+ for (int cn=5, cnSize=7; cn<=cnSize; cn++) { >+ HSSFCell cell = row.getCell((short) cn); >+ String formula = cell.getCellFormula(); >+ System.out.println("-----------------------------------------------------"); >+ //inspectPtgs(formula, sheet, wb); >+ System.out.println("["+rn+","+cn+"]: "+evaluateToString(formula, sheet, wb)); >+ System.out.println("-----------------------------------------------------"); >+ } >+ } >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 34828
:
14977
|
14979
|
14992
|
15012
|
15013
|
15014
|
15015
|
15039
|
15040
|
15056
|
15063
|
15073