Search in sources :

Example 66 with ValueEval

use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.

the class NumericFunctionInvoker method invokeInternal.

/**
	 * Formats nicer error messages for the junit output
	 */
private static double invokeInternal(Function target, ValueEval[] args, int srcCellRow, int srcCellCol) throws NumericEvalEx {
    ValueEval evalResult;
    try {
        evalResult = target.evaluate(args, srcCellRow, (short) srcCellCol);
    } catch (NotImplementedException e) {
        throw new NumericEvalEx("Not implemented:" + e.getMessage());
    }
    if (evalResult == null) {
        throw new NumericEvalEx("Result object was null");
    }
    if (evalResult instanceof ErrorEval) {
        ErrorEval ee = (ErrorEval) evalResult;
        throw new NumericEvalEx(formatErrorMessage(ee));
    }
    if (!(evalResult instanceof NumericValueEval)) {
        throw new NumericEvalEx("Result object type (" + evalResult.getClass().getName() + ") is invalid.  Expected implementor of (" + NumericValueEval.class.getName() + ")");
    }
    NumericValueEval result = (NumericValueEval) evalResult;
    return result.getNumberValue();
}
Also used : NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) NotImplementedException(org.apache.poi.ss.formula.eval.NotImplementedException) NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval)

Example 67 with ValueEval

use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.

the class TestAverage method testUnusualArgs.

/**
	 * Valid cases where values are not pure numbers
	 */
public void testUnusualArgs() {
    ValueEval[] values = { new NumberEval(1), new NumberEval(2), BoolEval.TRUE, BoolEval.FALSE };
    confirmAverage(values, 1.0);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 68 with ValueEval

use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.

the class TestComplex method confirmValueError.

private static void confirmValueError(String msg, String real_num, String i_num, String suffix, ErrorEval numError) {
    ValueEval result = invokeValue(real_num, i_num, suffix);
    assertEquals(ErrorEval.class, result.getClass());
    assertEquals(msg, numError, result);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval)

Example 69 with ValueEval

use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.

the class TestCountFuncs method testCountA.

public void testCountA() {
    ValueEval[] args;
    args = new ValueEval[] { new NumberEval(0) };
    confirmCountA(1, args);
    args = new ValueEval[] { new NumberEval(0), new NumberEval(0), new StringEval("") };
    confirmCountA(3, args);
    args = new ValueEval[] { EvalFactory.createAreaEval("D2:F5", new ValueEval[12]) };
    confirmCountA(12, args);
    args = new ValueEval[] { EvalFactory.createAreaEval("D1:F5", new ValueEval[15]), EvalFactory.createRefEval("A1"), EvalFactory.createAreaEval("A1:G6", new ValueEval[42]), new NumberEval(0) };
    confirmCountA(59, args);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 70 with ValueEval

use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.

the class TestCountFuncs method testCountIf.

public void testCountIf() {
    AreaEval range;
    ValueEval[] values;
    // when criteria is a boolean value
    values = new ValueEval[] { new NumberEval(0), // note - does not match boolean TRUE
    new StringEval("TRUE"), BoolEval.TRUE, BoolEval.FALSE, BoolEval.TRUE, BlankEval.instance };
    range = EvalFactory.createAreaEval("A1:B3", values);
    confirmCountIf(2, range, BoolEval.TRUE);
    // when criteria is numeric
    values = new ValueEval[] { new NumberEval(0), new StringEval("2"), new StringEval("2.001"), new NumberEval(2), new NumberEval(2), BoolEval.TRUE };
    range = EvalFactory.createAreaEval("A1:B3", values);
    confirmCountIf(3, range, new NumberEval(2));
    // note - same results when criteria is a string that parses as the number with the same value
    confirmCountIf(3, range, new StringEval("2.00"));
    // when criteria is an expression (starting with a comparison operator)
    confirmCountIf(2, range, new StringEval(">1"));
    // when criteria is an expression (starting with a comparison operator)
    confirmCountIf(2, range, new StringEval(">0.5"));
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Aggregations

ValueEval (org.apache.poi.ss.formula.eval.ValueEval)223 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)101 StringEval (org.apache.poi.ss.formula.eval.StringEval)48 Test (org.junit.Test)39 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)36 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)29 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)28 OperationEvaluationContext (org.apache.poi.ss.formula.OperationEvaluationContext)27 Calendar (java.util.Calendar)16 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)13 Date (java.util.Date)11 RefEval (org.apache.poi.ss.formula.eval.RefEval)9 TwoDEval (org.apache.poi.ss.formula.TwoDEval)7 BlankEval (org.apache.poi.ss.formula.eval.BlankEval)4 NotImplementedException (org.apache.poi.ss.formula.eval.NotImplementedException)4 StringValueEval (org.apache.poi.ss.formula.eval.StringValueEval)4 ValueVector (org.apache.poi.ss.formula.functions.LookupUtils.ValueVector)4 ArrayList (java.util.ArrayList)3 AssertionFailedError (junit.framework.AssertionFailedError)3 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)3