diff options
Diffstat (limited to 'src/java/org/apache')
50 files changed, 200 insertions, 329 deletions
diff --git a/src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java b/src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java index 96a43170e7..af56041521 100644 --- a/src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java +++ b/src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java @@ -20,7 +20,6 @@ package org.apache.poi.hssf.record.formula.atp; import java.util.HashMap; import java.util.Map; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.functions.FreeRefFunction; import org.apache.poi.ss.formula.EvaluationWorkbook; diff --git a/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java b/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java index 5928fe40fe..5d04de0fc3 100644 --- a/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java +++ b/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java @@ -20,7 +20,63 @@ package org.apache.poi.hssf.record.formula.eval; import org.apache.poi.hssf.record.formula.AbstractFunctionPtg; import org.apache.poi.hssf.record.formula.function.FunctionMetadata; import org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry; -import org.apache.poi.hssf.record.formula.functions.*; +import org.apache.poi.hssf.record.formula.functions.AggregateFunction; +import org.apache.poi.hssf.record.formula.functions.And; +import org.apache.poi.hssf.record.formula.functions.CalendarFieldFunction; +import org.apache.poi.hssf.record.formula.functions.Choose; +import org.apache.poi.hssf.record.formula.functions.Column; +import org.apache.poi.hssf.record.formula.functions.Columns; +import org.apache.poi.hssf.record.formula.functions.Count; +import org.apache.poi.hssf.record.formula.functions.Counta; +import org.apache.poi.hssf.record.formula.functions.Countif; +import org.apache.poi.hssf.record.formula.functions.DateFunc; +import org.apache.poi.hssf.record.formula.functions.Errortype; +import org.apache.poi.hssf.record.formula.functions.Even; +import org.apache.poi.hssf.record.formula.functions.False; +import org.apache.poi.hssf.record.formula.functions.FinanceFunction; +import org.apache.poi.hssf.record.formula.functions.Find; +import org.apache.poi.hssf.record.formula.functions.FreeRefFunction; +import org.apache.poi.hssf.record.formula.functions.Function; +import org.apache.poi.hssf.record.formula.functions.Hlookup; +import org.apache.poi.hssf.record.formula.functions.Hyperlink; +import org.apache.poi.hssf.record.formula.functions.If; +import org.apache.poi.hssf.record.formula.functions.Index; +import org.apache.poi.hssf.record.formula.functions.Indirect; +import org.apache.poi.hssf.record.formula.functions.IsError; +import org.apache.poi.hssf.record.formula.functions.IsNa; +import org.apache.poi.hssf.record.formula.functions.Isblank; +import org.apache.poi.hssf.record.formula.functions.Isref; +import org.apache.poi.hssf.record.formula.functions.LogicalFunction; +import org.apache.poi.hssf.record.formula.functions.Lookup; +import org.apache.poi.hssf.record.formula.functions.Match; +import org.apache.poi.hssf.record.formula.functions.MinaMaxa; +import org.apache.poi.hssf.record.formula.functions.Mode; +import org.apache.poi.hssf.record.formula.functions.Na; +import org.apache.poi.hssf.record.formula.functions.Not; +import org.apache.poi.hssf.record.formula.functions.NotImplementedFunction; +import org.apache.poi.hssf.record.formula.functions.Now; +import org.apache.poi.hssf.record.formula.functions.NumericFunction; +import org.apache.poi.hssf.record.formula.functions.Odd; +import org.apache.poi.hssf.record.formula.functions.Offset; +import org.apache.poi.hssf.record.formula.functions.Or; +import org.apache.poi.hssf.record.formula.functions.Pi; +import org.apache.poi.hssf.record.formula.functions.Rand; +import org.apache.poi.hssf.record.formula.functions.Replace; +import org.apache.poi.hssf.record.formula.functions.Row; +import org.apache.poi.hssf.record.formula.functions.Rows; +import org.apache.poi.hssf.record.formula.functions.Substitute; +import org.apache.poi.hssf.record.formula.functions.Sumif; +import org.apache.poi.hssf.record.formula.functions.Sumproduct; +import org.apache.poi.hssf.record.formula.functions.Sumx2my2; +import org.apache.poi.hssf.record.formula.functions.Sumx2py2; +import org.apache.poi.hssf.record.formula.functions.Sumxmy2; +import org.apache.poi.hssf.record.formula.functions.T; +import org.apache.poi.hssf.record.formula.functions.TextFunction; +import org.apache.poi.hssf.record.formula.functions.Time; +import org.apache.poi.hssf.record.formula.functions.Today; +import org.apache.poi.hssf.record.formula.functions.True; +import org.apache.poi.hssf.record.formula.functions.Value; +import org.apache.poi.hssf.record.formula.functions.Vlookup; import org.apache.poi.ss.formula.eval.NotImplementedException; /** @@ -151,8 +207,8 @@ public final class FunctionEval implements OperationEval { retval[124] = new Find(); - retval[127] = new Istext(); - retval[128] = new Isnumber(); + retval[127] = LogicalFunction.IsText; + retval[128] = LogicalFunction.IsNumber; retval[129] = new Isblank(); retval[130] = new T(); @@ -163,9 +219,9 @@ public final class FunctionEval implements OperationEval { retval[183] = AggregateFunction.PRODUCT; retval[184] = NumericFunction.FACT; - retval[190] = new Isnontext(); + retval[190] = LogicalFunction.IsNonText; - retval[198] = new Islogical(); + retval[198] = LogicalFunction.IsLogical; retval[212] = NumericFunction.ROUNDUP; retval[213] = NumericFunction.ROUNDDOWN; @@ -248,7 +304,7 @@ public final class FunctionEval implements OperationEval { if (f == null) { throw new NotImplementedException("FuncIx=" + getFunctionIndex()); } - return (ValueEval) f.evaluate(operands, srcRow, srcCol); + return f.evaluate(operands, srcRow, srcCol); } public int getNumberOfOperands() { diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/BooleanFunction.java b/src/java/org/apache/poi/hssf/record/formula/functions/BooleanFunction.java index 4995599ea5..76be216f2f 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/BooleanFunction.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/BooleanFunction.java @@ -39,7 +39,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; */ public abstract class BooleanFunction implements Function { - public final Eval evaluate(Eval[] args, int srcRow, short srcCol) { + public final ValueEval evaluate(ValueEval[] args, int srcRow, short srcCol) { if (args.length < 1) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/CalendarFieldFunction.java b/src/java/org/apache/poi/hssf/record/formula/functions/CalendarFieldFunction.java index ce6c2b4285..90e8c16675 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/CalendarFieldFunction.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/CalendarFieldFunction.java @@ -22,7 +22,6 @@ import java.util.Date; import java.util.GregorianCalendar; 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.EvaluationException; import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.OperandResolver; @@ -49,7 +48,7 @@ public final class CalendarFieldFunction implements Function { _needsOneBaseAdjustment = needsOneBaseAdjustment; } - public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] operands, int srcCellRow, short srcCellCol) { if (operands.length != 1) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Choose.java b/src/java/org/apache/poi/hssf/record/formula/functions/Choose.java index dbe0aa7a9b..e7a827f4bd 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Choose.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Choose.java @@ -18,7 +18,6 @@ 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.EvaluationException; import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.ValueEval; @@ -29,7 +28,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; */ public final class Choose implements Function { - public Eval evaluate(Eval[] args, int srcRowIndex, short srcColumnIndex) { + public ValueEval evaluate(ValueEval[] args, int srcRowIndex, short srcColumnIndex) { if (args.length < 2) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Column.java b/src/java/org/apache/poi/hssf/record/formula/functions/Column.java index 5b04836123..e329abe3de 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Column.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Column.java @@ -19,13 +19,12 @@ package org.apache.poi.hssf.record.formula.functions; import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.ValueEval; public final class Column implements Function { - public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] evals, int srcCellRow, short srcCellCol) { ValueEval retval = null; int cnum = -1; diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Columns.java b/src/java/org/apache/poi/hssf/record/formula/functions/Columns.java index 2a57bedb2d..2871c63410 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Columns.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Columns.java @@ -22,6 +22,7 @@ import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.RefEval; +import org.apache.poi.hssf.record.formula.eval.ValueEval; /** * Implementation for Excel COLUMNS function. @@ -30,7 +31,7 @@ import org.apache.poi.hssf.record.formula.eval.RefEval; */ public final class Columns implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { switch(args.length) { case 1: // expected diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Count.java b/src/java/org/apache/poi/hssf/record/formula/functions/Count.java index 4b8b217f4d..827fc0449f 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Count.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Count.java @@ -21,6 +21,7 @@ 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.MissingArgEval; import org.apache.poi.hssf.record.formula.eval.NumberEval; +import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate; /** @@ -36,7 +37,7 @@ import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate; */ public final class Count implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { int nArgs = args.length; if (nArgs < 1) { // too few arguments diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Counta.java b/src/java/org/apache/poi/hssf/record/formula/functions/Counta.java index 7ce7eadcb5..609301db6d 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Counta.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Counta.java @@ -21,6 +21,7 @@ import org.apache.poi.hssf.record.formula.eval.BlankEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.NumberEval; +import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate; /** @@ -34,7 +35,7 @@ import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate; */ public final class Counta implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { int nArgs = args.length; if (nArgs < 1) { // too few arguments diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java b/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java index 5b9debc28d..e1de081d8b 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java @@ -29,6 +29,7 @@ import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.OperandResolver; 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; import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate; import org.apache.poi.ss.usermodel.ErrorConstants; @@ -400,7 +401,7 @@ public final class Countif implements Function { } } - public Eval evaluate(Eval[] args, int srcRowIndex, short srcColumnIndex) { + public ValueEval evaluate(ValueEval[] args, int srcRowIndex, short srcColumnIndex) { switch(args.length) { case 2: // expected diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Errortype.java b/src/java/org/apache/poi/hssf/record/formula/functions/Errortype.java index 0240f817e7..a2a2572587 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Errortype.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Errortype.java @@ -18,10 +18,10 @@ 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.EvaluationException; import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.OperandResolver; +import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.usermodel.HSSFErrorConstants; /** @@ -52,7 +52,7 @@ import org.apache.poi.hssf.usermodel.HSSFErrorConstants; */ public final class Errortype implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { try { OperandResolver.getSingleValue(args[0], srcCellRow, srcCellCol); diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/False.java b/src/java/org/apache/poi/hssf/record/formula/functions/False.java index b94686bb9e..c5ddc266ac 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/False.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/False.java @@ -19,7 +19,6 @@ package org.apache.poi.hssf.record.formula.functions; import org.apache.poi.hssf.record.formula.eval.BoolEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.ValueEval; /** @@ -28,7 +27,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; */ public final class False implements Function { - public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { + public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) { ValueEval retval; switch (operands.length) { default: diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Function.java b/src/java/org/apache/poi/hssf/record/formula/functions/Function.java index 90e6afe05f..1aff51cf4f 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Function.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Function.java @@ -19,7 +19,6 @@ package org.apache.poi.hssf.record.formula.functions; import org.apache.poi.hssf.record.formula.eval.BlankEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.MissingArgEval; import org.apache.poi.hssf.record.formula.eval.ValueEval; @@ -31,16 +30,14 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; public interface Function { /** - * @param args the evaluated function arguments. Elements of this array typically implement - * {@link ValueEval}. Empty values are represented with {@link BlankEval} or {@link - * MissingArgEval}, never <code>null</code>. + * @param args the evaluated function arguments. Empty values are represented with + * {@link BlankEval} or {@link MissingArgEval}, never <code>null</code>. * @param srcRowIndex row index of the cell containing the formula under evaluation * @param srcColumnIndex column index of the cell containing the formula under evaluation * @return The evaluated result, possibly an {@link ErrorEval}, never <code>null</code>. * <b>Note</b> - Excel uses the error code <i>#NUM!</i> instead of IEEE <i>NaN</i>, so when * numeric functions evaluate to {@link Double#NaN} be sure to translate the result to {@link * ErrorEval#NUM_ERROR}. - * */ - Eval evaluate(Eval[] args, int srcRowIndex, short srcColumnIndex); + ValueEval evaluate(ValueEval[] args, int srcRowIndex, short srcColumnIndex); } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Hlookup.java b/src/java/org/apache/poi/hssf/record/formula/functions/Hlookup.java index 8230fb01f9..35a0b3ae34 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Hlookup.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Hlookup.java @@ -42,7 +42,7 @@ import org.apache.poi.hssf.record.formula.functions.LookupUtils.ValueVector; */ public final class Hlookup implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { Eval arg3 = null; switch(args.length) { case 4: diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Hyperlink.java b/src/java/org/apache/poi/hssf/record/formula/functions/Hyperlink.java index ecfdebf26f..19659081ec 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Hyperlink.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Hyperlink.java @@ -18,10 +18,10 @@ 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.EvaluationException; import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.StringEval; +import org.apache.poi.hssf.record.formula.eval.ValueEval; /** * Implementation of Excel HYPERLINK function.<p/> @@ -41,7 +41,7 @@ import org.apache.poi.hssf.record.formula.eval.StringEval; */ public final class Hyperlink implements Function { - public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { + public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) { int lastArgIx = operands.length - 1; if (lastArgIx < 0 || lastArgIx > 1) { return ErrorEval.VALUE_INVALID; diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/If.java b/src/java/org/apache/poi/hssf/record/formula/functions/If.java index 450a96834b..f8d3c03ee3 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/If.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/If.java @@ -19,7 +19,6 @@ package org.apache.poi.hssf.record.formula.functions; import org.apache.poi.hssf.record.formula.eval.BoolEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.ValueEval; @@ -30,8 +29,8 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; */ public final class If implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { - Eval falseResult; + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { + ValueEval falseResult; switch (args.length) { case 3: falseResult = args[2]; @@ -54,7 +53,7 @@ public final class If implements Function { return falseResult; } - private static boolean evaluateFirstArg(Eval arg, int srcCellRow, short srcCellCol) + private static boolean evaluateFirstArg(ValueEval arg, int srcCellRow, short srcCellCol) throws EvaluationException { ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol); Boolean b = OperandResolver.coerceValueToBoolean(ve, false); diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Index.java b/src/java/org/apache/poi/hssf/record/formula/functions/Index.java index b4eca2b9b5..acdd6adde8 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Index.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Index.java @@ -47,7 +47,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; */ public final class Index implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { int nArgs = args.length; if(nArgs < 2) { // too few arguments diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java b/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java index 818a463d95..55919a3a84 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java @@ -20,7 +20,6 @@ package org.apache.poi.hssf.record.formula.functions; import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.BoolEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.ValueEval; @@ -30,7 +29,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; */ public final class IsError implements Function { - public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] operands, int srcCellRow, short srcCellCol) { ValueEval retval = null; boolean b = false; diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/IsNa.java b/src/java/org/apache/poi/hssf/record/formula/functions/IsNa.java index 0c9cf4f200..d8f9ac9ecb 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/IsNa.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/IsNa.java @@ -22,6 +22,7 @@ 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.EvaluationException; import org.apache.poi.hssf.record.formula.eval.OperandResolver; +import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.ss.usermodel.ErrorConstants; /** @@ -38,7 +39,7 @@ import org.apache.poi.ss.usermodel.ErrorConstants; */ public final class IsNa implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { if(args.length != 1) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Isblank.java b/src/java/org/apache/poi/hssf/record/formula/functions/Isblank.java index 655d296c39..51e8ee441f 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Isblank.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Isblank.java @@ -31,7 +31,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; */ public final class Isblank implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { if(args.length != 1) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Islogical.java b/src/java/org/apache/poi/hssf/record/formula/functions/Islogical.java deleted file mode 100644 index 666c89ee04..0000000000 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Islogical.java +++ /dev/null @@ -1,53 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hssf.record.formula.functions; - -import org.apache.poi.hssf.record.formula.eval.BoolEval; -import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; -import org.apache.poi.hssf.record.formula.eval.RefEval; - -/** - * @author Amol S. Deshmukh < amolweb at ya hoo dot com > - * - */ -public final class Islogical extends LogicalFunction { - - public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) { - Eval retval = BoolEval.FALSE; - - switch (operands.length) { - default: - retval = ErrorEval.VALUE_INVALID; - break; - case 1: - Eval eval = operands[0]; - if (eval instanceof BoolEval) { - retval = BoolEval.TRUE; - } - else if (eval instanceof RefEval) { - Eval xlatedEval = xlateRefEval((RefEval) eval); - if (xlatedEval instanceof BoolEval) { - retval = BoolEval.TRUE; - } - } - } - - return retval; - } -} diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Isnontext.java b/src/java/org/apache/poi/hssf/record/formula/functions/Isnontext.java deleted file mode 100644 index e62dc69019..0000000000 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Isnontext.java +++ /dev/null @@ -1,53 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hssf.record.formula.functions; - -import org.apache.poi.hssf.record.formula.eval.BoolEval; -import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; -import org.apache.poi.hssf.record.formula.eval.RefEval; -import org.apache.poi.hssf.record.formula.eval.StringEval; - -/** - * @author Amol S. Deshmukh < amolweb at ya hoo dot com > - * - */ -public final class Isnontext extends LogicalFunction { - public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) { - Eval retval = BoolEval.TRUE; - - switch (operands.length) { - default: - retval = ErrorEval.VALUE_INVALID; - break; - case 1: - Eval eval = operands[0]; - if (eval instanceof StringEval) { - retval = BoolEval.FALSE; - } - else if (eval instanceof RefEval) { - Eval xlatedEval = xlateRefEval((RefEval) eval); - if (xlatedEval instanceof StringEval) { - retval = BoolEval.FALSE; - } - } - } - - return retval; - } -} diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Isnumber.java b/src/java/org/apache/poi/hssf/record/formula/functions/Isnumber.java deleted file mode 100644 index f00fd05c24..0000000000 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Isnumber.java +++ /dev/null @@ -1,53 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hssf.record.formula.functions; - -import org.apache.poi.hssf.record.formula.eval.BoolEval; -import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; -import org.apache.poi.hssf.record.formula.eval.NumberEval; -import org.apache.poi.hssf.record.formula.eval.RefEval; - -/** - * @author Amol S. Deshmukh < amolweb at ya hoo dot com > - * - */ -public final class Isnumber extends LogicalFunction { - public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) { - Eval retval = BoolEval.FALSE; - - switch (operands.length) { - default: - retval = ErrorEval.VALUE_INVALID; - break; - case 1: - Eval eval = operands[0]; - if (eval instanceof NumberEval) { - retval = BoolEval.TRUE; - } - else if (eval instanceof RefEval) { - Eval xlatedEval = xlateRefEval((RefEval) eval); - if (xlatedEval instanceof NumberEval) { - retval = BoolEval.TRUE; - } - } - } - - return retval; - } -} diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Isref.java b/src/java/org/apache/poi/hssf/record/formula/functions/Isref.java index 565d5e4989..f5d8ac7e38 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Isref.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Isref.java @@ -22,26 +22,22 @@ import org.apache.poi.hssf.record.formula.eval.BoolEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.RefEval; +import org.apache.poi.hssf.record.formula.eval.ValueEval; /** * @author Amol S. Deshmukh < amolweb at ya hoo dot com > - * */ public final class Isref implements Function { - public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) { - Eval retval = BoolEval.FALSE; + public ValueEval evaluate(ValueEval[] operands, int srcCellRow, short srcCellCol) { + if (operands.length != 1) { + return ErrorEval.VALUE_INVALID; + } - switch (operands.length) { - default: - retval = ErrorEval.VALUE_INVALID; - break; - case 1: - Eval eval = operands[0]; - if (eval instanceof RefEval || eval instanceof AreaEval) { - retval = BoolEval.TRUE; - } - } + Eval eval = operands[0]; + if (eval instanceof RefEval || eval instanceof AreaEval) { + return BoolEval.TRUE; + } - return retval; - } + return BoolEval.FALSE; + } } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Istext.java b/src/java/org/apache/poi/hssf/record/formula/functions/Istext.java deleted file mode 100644 index f669d7f497..0000000000 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Istext.java +++ /dev/null @@ -1,53 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hssf.record.formula.functions; - -import org.apache.poi.hssf.record.formula.eval.BoolEval; -import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; -import org.apache.poi.hssf.record.formula.eval.RefEval; -import org.apache.poi.hssf.record.formula.eval.StringEval; - -/** - * @author Amol S. Deshmukh < amolweb at ya hoo dot com > - * - */ -public final class Istext extends LogicalFunction { - public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) { - Eval retval = BoolEval.FALSE; - - switch (operands.length) { - default: - retval = ErrorEval.VALUE_INVALID; - break; - case 1: - Eval eval = operands[0]; - if (eval instanceof StringEval) { - retval = BoolEval.TRUE; - } - else if (eval instanceof RefEval) { - Eval xlatedEval = xlateRefEval((RefEval) eval); - if (xlatedEval instanceof StringEval) { - retval = BoolEval.TRUE; - } - } - } - - return retval; - } -} diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/LogicalFunction.java b/src/java/org/apache/poi/hssf/record/formula/functions/LogicalFunction.java index ae5a0ebf6b..fadad2ca7c 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/LogicalFunction.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/LogicalFunction.java @@ -17,28 +17,76 @@ package org.apache.poi.hssf.record.formula.functions; +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.EvaluationException; +import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.OperandResolver; 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 Amol S. Deshmukh < amolweb at ya hoo dot com > - * */ public abstract class LogicalFunction implements Function { - /** - * recursively evaluate any RefEvals - * TODO - use {@link OperandResolver} - */ - protected ValueEval xlateRefEval(RefEval reval) { - ValueEval retval = reval.getInnerValueEval(); + /** + * recursively evaluate any RefEvals TODO - use {@link OperandResolver} + */ + private static ValueEval xlateRefEval(RefEval reval) { + ValueEval retval = reval.getInnerValueEval(); - if (retval instanceof RefEval) { - RefEval re = (RefEval) retval; - retval = xlateRefEval(re); - } + if (retval instanceof RefEval) { + RefEval re = (RefEval) retval; + retval = xlateRefEval(re); + } - return retval; - } + return retval; + } + + public final ValueEval evaluate(ValueEval[] operands, int srcCellRow, short srcCellCol) { + if (operands.length != 1) { + return ErrorEval.VALUE_INVALID; + } + ValueEval ve; + try { + ve = OperandResolver.getSingleValue(operands[0], srcCellRow, srcCellCol); + } catch (EvaluationException e) { + if (false) { + // Note - it is more usual to propagate error codes straight to the result like this: + return e.getErrorEval(); + // but logical functions behave a little differently + } + // this will usually cause a 'FALSE' result except for ISNONTEXT() + ve = e.getErrorEval(); + } + if (ve instanceof RefEval) { + ve = xlateRefEval((RefEval) ve); + } + return BoolEval.valueOf(evaluate(ve)); + + } + protected abstract boolean evaluate(ValueEval arg); + + public static final Function IsLogical = new LogicalFunction() { + protected boolean evaluate(ValueEval arg) { + return arg instanceof BoolEval; + } + }; + public static final Function IsNonText = new LogicalFunction() { + protected boolean evaluate(ValueEval arg) { + return !(arg instanceof StringEval); + } + }; + public static final Function IsNumber = new LogicalFunction() { + protected boolean evaluate(ValueEval arg) { + return arg instanceof NumberEval; + } + }; + public static final Function IsText = new LogicalFunction() { + protected boolean evaluate(ValueEval arg) { + return arg instanceof StringEval; + } + }; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Lookup.java b/src/java/org/apache/poi/hssf/record/formula/functions/Lookup.java index 0cbae7fb88..7bb3326d4e 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Lookup.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Lookup.java @@ -19,7 +19,6 @@ 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.EvaluationException; import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.ValueEval; @@ -41,7 +40,7 @@ import org.apache.poi.hssf.record.formula.functions.LookupUtils.ValueVector; */ public final class Lookup implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { switch(args.length) { case 3: break; diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Match.java b/src/java/org/apache/poi/hssf/record/formula/functions/Match.java index 7a8cc6cc24..9f61937440 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Match.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Match.java @@ -67,7 +67,7 @@ import org.apache.poi.hssf.record.formula.functions.LookupUtils.ValueVector; public final class Match implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { double match_type = 1; // default diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Mode.java b/src/java/org/apache/poi/hssf/record/formula/functions/Mode.java index 767e980c1c..4c6295615d 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Mode.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Mode.java @@ -74,7 +74,7 @@ public final class Mode implements Function { } - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { double result; try { List<Double> temp = new ArrayList<Double>(); diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/MultiOperandNumericFunction.java b/src/java/org/apache/poi/hssf/record/formula/functions/MultiOperandNumericFunction.java index 30b72ee74f..67bfaa038b 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/MultiOperandNumericFunction.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/MultiOperandNumericFunction.java @@ -83,7 +83,7 @@ public abstract class MultiOperandNumericFunction implements Function { private static final int DEFAULT_MAX_NUM_OPERANDS = 30; - public final Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public final ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { double d; try { diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Na.java b/src/java/org/apache/poi/hssf/record/formula/functions/Na.java index 720b0c661f..d24a5994a9 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Na.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Na.java @@ -18,7 +18,7 @@ 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.ValueEval; /** * Implementation of Excel function NA() @@ -27,7 +27,7 @@ import org.apache.poi.hssf.record.formula.eval.Eval; */ public final class Na implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { return ErrorEval.NA; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Not.java b/src/java/org/apache/poi/hssf/record/formula/functions/Not.java index 46d1e7142a..4e89ac3096 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Not.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Not.java @@ -19,7 +19,6 @@ package org.apache.poi.hssf.record.formula.functions; import org.apache.poi.hssf.record.formula.eval.BoolEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.ValueEval; @@ -33,7 +32,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; */ public final class Not implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { if (args.length != 1) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/NotImplementedFunction.java b/src/java/org/apache/poi/hssf/record/formula/functions/NotImplementedFunction.java index 9c685d0f51..e243e87289 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/NotImplementedFunction.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/NotImplementedFunction.java @@ -17,7 +17,7 @@ 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.ValueEval; import org.apache.poi.ss.formula.eval.NotImplementedException; /** @@ -38,7 +38,7 @@ public final class NotImplementedFunction implements Function { _functionName = name; } - public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { + public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) { throw new NotImplementedException(_functionName); } public String getFunctionName() { diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Now.java b/src/java/org/apache/poi/hssf/record/formula/functions/Now.java index 528d7f98ab..cb9687654b 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Now.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Now.java @@ -20,8 +20,8 @@ package org.apache.poi.hssf.record.formula.functions; import java.util.Date; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.NumberEval; +import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.usermodel.HSSFDateUtil; /** @@ -31,7 +31,7 @@ import org.apache.poi.hssf.usermodel.HSSFDateUtil; */ public final class Now implements Function { - public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] evals, int srcCellRow, short srcCellCol) { if (evals.length > 0) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/NumericFunction.java b/src/java/org/apache/poi/hssf/record/formula/functions/NumericFunction.java index 136cf36630..310be7bb15 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/NumericFunction.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/NumericFunction.java @@ -46,7 +46,7 @@ public abstract class NumericFunction implements Function { } } - public final Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public final ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { double result; try { result = eval(args, srcCellRow, srcCellCol); diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Offset.java b/src/java/org/apache/poi/hssf/record/formula/functions/Offset.java index 0fda540e3a..c83e1b8f57 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Offset.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Offset.java @@ -164,7 +164,7 @@ public final class Offset implements Function { } } - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { if(args.length < 3 || args.length > 5) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Pi.java b/src/java/org/apache/poi/hssf/record/formula/functions/Pi.java index d69015b148..3282c7d786 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Pi.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Pi.java @@ -18,7 +18,6 @@ package org.apache.poi.hssf.record.formula.functions; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.ValueEval; @@ -30,7 +29,7 @@ public final class Pi implements Function { private static final NumberEval PI_EVAL = new NumberEval(Math.PI); - public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { + public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) { ValueEval retval; switch (operands.length) { default: diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Rand.java b/src/java/org/apache/poi/hssf/record/formula/functions/Rand.java index c9940fffed..5f5173e856 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Rand.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Rand.java @@ -18,7 +18,6 @@ package org.apache.poi.hssf.record.formula.functions; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.ValueEval; @@ -28,7 +27,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; */ public final class Rand implements Function { - public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { + public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) { ValueEval retval; switch (operands.length) { default: diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Row.java b/src/java/org/apache/poi/hssf/record/formula/functions/Row.java index ac16401262..59c1203b75 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Row.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Row.java @@ -19,14 +19,13 @@ package org.apache.poi.hssf.record.formula.functions; import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.ValueEval; public final class Row implements Function { - public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] evals, int srcCellRow, short srcCellCol) { ValueEval retval = null; int rnum = -1; diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Rows.java b/src/java/org/apache/poi/hssf/record/formula/functions/Rows.java index 9f331f47d7..7272a07c5d 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Rows.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Rows.java @@ -22,6 +22,7 @@ import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.RefEval; +import org.apache.poi.hssf.record.formula.eval.ValueEval; /** * Implementation for Excel ROWS function. @@ -30,7 +31,7 @@ import org.apache.poi.hssf.record.formula.eval.RefEval; */ public final class Rows implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { switch(args.length) { case 1: // expected diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Sumif.java b/src/java/org/apache/poi/hssf/record/formula/functions/Sumif.java index 8eb2565d89..97ba463d92 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Sumif.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Sumif.java @@ -41,7 +41,7 @@ import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate; */ public final class Sumif implements Function { - public Eval evaluate(Eval[] args, int srcRowIndex, short srcColumnIndex) { + public ValueEval evaluate(ValueEval[] args, int srcRowIndex, short srcColumnIndex) { if (args.length < 2) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Sumproduct.java b/src/java/org/apache/poi/hssf/record/formula/functions/Sumproduct.java index 572c67f926..bc743e7197 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Sumproduct.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Sumproduct.java @@ -20,7 +20,6 @@ package org.apache.poi.hssf.record.formula.functions; import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.BlankEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumericValueEval; @@ -54,14 +53,14 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; public final class Sumproduct implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { int maxN = args.length; if(maxN < 1) { return ErrorEval.VALUE_INVALID; } - Eval firstArg = args[0]; + ValueEval firstArg = args[0]; try { if(firstArg instanceof NumericValueEval) { return evaluateSingleProduct(args); @@ -83,7 +82,7 @@ public final class Sumproduct implements Function { + firstArg.getClass().getName() + ")"); } - private static Eval evaluateSingleProduct(Eval[] evalArgs) throws EvaluationException { + private static ValueEval evaluateSingleProduct(ValueEval[] evalArgs) throws EvaluationException { int maxN = evalArgs.length; double term = 1D; @@ -94,9 +93,9 @@ public final class Sumproduct implements Function { return new NumberEval(term); } - private static double getScalarValue(Eval arg) throws EvaluationException { + private static double getScalarValue(ValueEval arg) throws EvaluationException { - Eval eval; + ValueEval eval; if (arg instanceof RefEval) { RefEval re = (RefEval) arg; eval = re.getInnerValueEval(); @@ -116,15 +115,10 @@ public final class Sumproduct implements Function { eval = ae.getRelativeValue(0, 0); } - if (!(eval instanceof ValueEval)) { - throw new RuntimeException("Unexpected value eval class (" - + eval.getClass().getName() + ")"); - } - - return getProductTerm((ValueEval) eval, true); + return getProductTerm(eval, true); } - private static Eval evaluateAreaSumProduct(Eval[] evalArgs) throws EvaluationException { + private static ValueEval evaluateAreaSumProduct(ValueEval[] evalArgs) throws EvaluationException { int maxN = evalArgs.length; AreaEval[] args = new AreaEval[maxN]; try { diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/T.java b/src/java/org/apache/poi/hssf/record/formula/functions/T.java index 9d764c33bc..6f13d4c5ee 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/T.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/T.java @@ -18,20 +18,20 @@ 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.RefEval; import org.apache.poi.hssf.record.formula.eval.StringEval; +import org.apache.poi.hssf.record.formula.eval.ValueEval; public final class T implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { switch (args.length) { default: return ErrorEval.VALUE_INVALID; case 1: break; } - Eval arg = args[0]; + ValueEval arg = args[0]; if (arg instanceof RefEval) { RefEval re = (RefEval) arg; arg = re.getInnerValueEval(); diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/TextFunction.java b/src/java/org/apache/poi/hssf/record/formula/functions/TextFunction.java index 5fd758962d..ff55e1921f 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/TextFunction.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/TextFunction.java @@ -43,7 +43,7 @@ public abstract class TextFunction implements Function { return OperandResolver.coerceValueToInt(ve); } - public final Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public final ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { try { return evaluateFunc(args, srcCellRow, srcCellCol); } catch (EvaluationException e) { diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Time.java b/src/java/org/apache/poi/hssf/record/formula/functions/Time.java index 1ddb8516ff..6d1ef146ca 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Time.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Time.java @@ -38,7 +38,7 @@ public final class Time implements Function { private static final int SECONDS_PER_DAY = HOURS_PER_DAY * SECONDS_PER_HOUR; - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { if (args.length != 3) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Today.java b/src/java/org/apache/poi/hssf/record/formula/functions/Today.java index b71fce4611..434653c12c 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Today.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Today.java @@ -21,8 +21,8 @@ import java.util.Calendar; import java.util.GregorianCalendar; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.NumberEval; +import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.usermodel.HSSFDateUtil; /** @@ -32,7 +32,7 @@ import org.apache.poi.hssf.usermodel.HSSFDateUtil; */ public final class Today implements Function { - public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] evals, int srcCellRow, short srcCellCol) { if (evals.length > 0) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/True.java b/src/java/org/apache/poi/hssf/record/formula/functions/True.java index 429cc5f0d5..9a80c8d479 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/True.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/True.java @@ -19,7 +19,6 @@ package org.apache.poi.hssf.record.formula.functions; import org.apache.poi.hssf.record.formula.eval.BoolEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; -import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.ValueEval; /** @@ -28,7 +27,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; */ public final class True implements Function { - public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { + public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) { ValueEval retval; switch (operands.length) { default: diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Value.java b/src/java/org/apache/poi/hssf/record/formula/functions/Value.java index 0dbfdb52de..cfa6dff4c9 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Value.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Value.java @@ -18,7 +18,6 @@ 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.EvaluationException; import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.OperandResolver; @@ -42,7 +41,7 @@ public final class Value implements Function { private static final int MIN_DISTANCE_BETWEEN_THOUSANDS_SEPARATOR = 4; private static final Double ZERO = new Double(0.0); - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { if (args.length != 1) { return ErrorEval.VALUE_INVALID; } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Vlookup.java b/src/java/org/apache/poi/hssf/record/formula/functions/Vlookup.java index 27d16ee867..9887f69c33 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Vlookup.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Vlookup.java @@ -42,7 +42,7 @@ import org.apache.poi.hssf.record.formula.functions.LookupUtils.ValueVector; */ public final class Vlookup implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { Eval arg3 = null; switch(args.length) { case 4: diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/XYNumericFunction.java b/src/java/org/apache/poi/hssf/record/formula/functions/XYNumericFunction.java index 5c80068fff..c43cca0adf 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/XYNumericFunction.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/XYNumericFunction.java @@ -97,7 +97,7 @@ public abstract class XYNumericFunction implements Function { */ protected abstract Accumulator createAccumulator(); - public final Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + public final ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) { if (args.length != 2) { return ErrorEval.VALUE_INVALID; } |