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 940b2820d..7b17996dc 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 @@ -55,14 +55,14 @@ public final class FunctionEval { Function[] retval = new Function[368]; retval[0] = new Count(); - retval[ID.IF] = new If(); + retval[ID.IF] = new IfFunc(); retval[2] = LogicalFunction.ISNA; retval[3] = LogicalFunction.ISERROR; retval[ID.SUM] = AggregateFunction.SUM; retval[5] = AggregateFunction.AVERAGE; retval[6] = AggregateFunction.MIN; retval[7] = AggregateFunction.MAX; - retval[8] = new Row(); // ROW + retval[8] = new RowFunc(); // ROW retval[9] = new Column(); retval[10] = new Na(); retval[11] = new Npv(); @@ -103,7 +103,7 @@ public final class FunctionEval { retval[63] = NumericFunction.RAND; retval[64] = new Match(); retval[65] = DateFunc.instance; - retval[66] = new Time(); + retval[66] = new TimeFunc(); retval[67] = CalendarFieldFunction.DAY; retval[68] = CalendarFieldFunction.MONTH; retval[69] = CalendarFieldFunction.YEAR; diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/DateFunc.java b/src/java/org/apache/poi/hssf/record/formula/functions/DateFunc.java index ca6df7ae2..0422168fd 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/DateFunc.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/DateFunc.java @@ -28,6 +28,8 @@ import org.apache.poi.hssf.usermodel.HSSFDateUtil; /** + * Implementation for the Excel function DATE + * * @author Pavel Krupets (pkrupets at palmtreebusiness dot com) */ public final class DateFunc extends Fixed3ArgFunction { @@ -52,16 +54,17 @@ public final class DateFunc extends Fixed3ArgFunction { return new NumberEval(result); } - private static double evaluate(int year, int month, int day) throws EvaluationException { + private static double evaluate(int year, int month, int pDay) throws EvaluationException { - if (year < 0 || month < 0 || day < 0) { + if (year < 0 || month < 0 || pDay < 0) { throw new EvaluationException(ErrorEval.VALUE_INVALID); } - if (year == 1900 && month == Calendar.FEBRUARY && day == 29) { + if (year == 1900 && month == Calendar.FEBRUARY && pDay == 29) { return 60.0; } + int day = pDay; if (year == 1900) { if ((month == Calendar.JANUARY && day >= 60) || (month == Calendar.FEBRUARY && day >= 30)) { diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/If.java b/src/java/org/apache/poi/hssf/record/formula/functions/IfFunc.java similarity index 96% rename from src/java/org/apache/poi/hssf/record/formula/functions/If.java rename to src/java/org/apache/poi/hssf/record/formula/functions/IfFunc.java index 7dfbf0d55..77e304044 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/If.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/IfFunc.java @@ -25,9 +25,11 @@ import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.ValueEval; /** + * Implementation for the Excel function IF + * * @author Amol S. Deshmukh < amolweb at ya hoo dot com > */ -public final class If extends Var2or3ArgFunction { +public final class IfFunc extends Var2or3ArgFunction { public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) { boolean b; diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Row.java b/src/java/org/apache/poi/hssf/record/formula/functions/RowFunc.java similarity index 93% rename from src/java/org/apache/poi/hssf/record/formula/functions/Row.java rename to src/java/org/apache/poi/hssf/record/formula/functions/RowFunc.java index 718ab7c27..ea1aa3252 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Row.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/RowFunc.java @@ -23,7 +23,12 @@ 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 Function0Arg, Function1Arg { +/** + * Implementation for the Excel function ROW + * + * @author Josh Micich + */ +public final class RowFunc implements Function0Arg, Function1Arg { public ValueEval evaluate(int srcRowIndex, int srcColumnIndex) { return new NumberEval(srcRowIndex+1); @@ -51,5 +56,4 @@ public final class Row implements Function0Arg, Function1Arg { } return ErrorEval.VALUE_INVALID; } - } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Time.java b/src/java/org/apache/poi/hssf/record/formula/functions/TimeFunc.java similarity index 96% rename from src/java/org/apache/poi/hssf/record/formula/functions/Time.java rename to src/java/org/apache/poi/hssf/record/formula/functions/TimeFunc.java index 85f474028..44f9a2be1 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Time.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/TimeFunc.java @@ -25,11 +25,13 @@ import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.ValueEval; /** + * Implementation for the Excel function TIME + * * @author Steven Butler (sebutler @ gmail dot com) * - * Based on POI org.apache.hssf.record.formula.DateFunc.java + * Based on POI {@link DateFunc} */ -public final class Time extends Fixed3ArgFunction { +public final class TimeFunc extends Fixed3ArgFunction { private static final int SECONDS_PER_MINUTE = 60; private static final int SECONDS_PER_HOUR = 3600; diff --git a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java index 0e6301625..199217eb8 100644 --- a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java @@ -63,7 +63,7 @@ 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.Choose; import org.apache.poi.hssf.record.formula.functions.FreeRefFunction; -import org.apache.poi.hssf.record.formula.functions.If; +import org.apache.poi.hssf.record.formula.functions.IfFunc; import org.apache.poi.hssf.record.formula.udf.UDFFinder; import org.apache.poi.hssf.util.CellReference; import org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment.WorkbookNotFoundException; @@ -373,7 +373,7 @@ public final class WorkbookEvaluator { ValueEval arg0 = stack.pop(); boolean evaluatedPredicate; try { - evaluatedPredicate = If.evaluateFirstArg(arg0, ec.getRowIndex(), ec.getColumnIndex()); + evaluatedPredicate = IfFunc.evaluateFirstArg(arg0, ec.getRowIndex(), ec.getColumnIndex()); } catch (EvaluationException e) { stack.push(e.getErrorEval()); int dist = attrPtg.getData(); diff --git a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestRowCol.java b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestRowCol.java index 1bec618aa..532e768eb 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestRowCol.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestRowCol.java @@ -43,7 +43,7 @@ public final class TestRowCol extends TestCase { } public void testRow() { - Function target = new Row(); + Function target = new RowFunc(); { ValueEval[] args = { EvalFactory.createRefEval("C5"), }; double actual = NumericFunctionInvoker.invoke(target, args); diff --git a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTime.java b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTime.java index a0522cc5a..bfd174739 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTime.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTime.java @@ -30,8 +30,8 @@ import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** - * Tests for {@link Time} - * + * Tests for {@link TimeFunc} + * * @author @author Steven Butler (sebutler @ gmail dot com) */ public final class TestTime extends TestCase { @@ -106,13 +106,13 @@ public final class TestTime extends TestCase { int expH = Integer.parseInt(parts[0]); int expM = Integer.parseInt(parts[1]); int expS = Integer.parseInt(parts[2]); - + double expectedValue = (expH*SECONDS_PER_HOUR + expM*SECONDS_PER_MINUTE + expS)/SECONDS_PER_DAY; cell11.setCellFormula(formulaText); cell11.setCellStyle(style); evaluator.clearAllCachedResultValues(); - + double actualValue = evaluator.evaluate(cell11).getNumberValue(); assertEquals(expectedValue, actualValue, 0.0);