Search in sources :

Example 21 with StringEval

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

the class TestCountFuncs method testCountifEmptyStringCriteria.

public void testCountifEmptyStringCriteria() {
    I_MatchPredicate mp;
    // pred '=' matches blank cell but not empty string
    mp = createCriteriaPredicate(new StringEval("="));
    confirmPredicate(false, mp, "");
    confirmPredicate(true, mp, NULL);
    // pred '' matches both blank cell but not empty string
    mp = createCriteriaPredicate(new StringEval(""));
    confirmPredicate(true, mp, "");
    confirmPredicate(true, mp, NULL);
    // pred '<>' matches empty string but not blank cell
    mp = createCriteriaPredicate(new StringEval("<>"));
    confirmPredicate(false, mp, NULL);
    confirmPredicate(true, mp, "");
}
Also used : I_MatchPredicate(org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate) StringEval(org.apache.poi.ss.formula.eval.StringEval)

Example 22 with StringEval

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

the class TestCountFuncs method testCountifErrorCriteria.

/**
	 * the criteria arg value can be an error code (the error does not
	 * propagate to the COUNTIF result).
	 */
public void testCountifErrorCriteria() {
    I_MatchPredicate mp;
    mp = createCriteriaPredicate(new StringEval("#REF!"));
    confirmPredicate(false, mp, 4);
    confirmPredicate(false, mp, "#REF!");
    confirmPredicate(true, mp, ErrorEval.REF_INVALID);
    mp = createCriteriaPredicate(new StringEval("<#VALUE!"));
    confirmPredicate(false, mp, 4);
    confirmPredicate(false, mp, "#DIV/0!");
    confirmPredicate(false, mp, "#REF!");
    confirmPredicate(true, mp, ErrorEval.DIV_ZERO);
    confirmPredicate(false, mp, ErrorEval.REF_INVALID);
    // not quite an error literal, should be treated as plain text
    mp = createCriteriaPredicate(new StringEval("<=#REF!a"));
    confirmPredicate(false, mp, 4);
    confirmPredicate(true, mp, "#DIV/0!");
    confirmPredicate(true, mp, "#REF!");
    confirmPredicate(false, mp, ErrorEval.DIV_ZERO);
    confirmPredicate(false, mp, ErrorEval.REF_INVALID);
}
Also used : I_MatchPredicate(org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate) StringEval(org.apache.poi.ss.formula.eval.StringEval)

Example 23 with StringEval

use of org.apache.poi.ss.formula.eval.StringEval 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)

Example 24 with StringEval

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

the class TestWorkdayFunction method testReturnWorkdaysWithDaysTruncated.

@Test
public void testReturnWorkdaysWithDaysTruncated() {
    Calendar expCal = LocaleUtil.getLocaleCalendar(2009, 3, 30);
    Date expDate = expCal.getTime();
    ValueEval[] ve = { new StringEval(STARTING_DATE), new NumberEval(151.99999) };
    double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
    Date actDate = DateUtil.getJavaDate(numberValue);
    assertEquals(expDate, actDate);
}
Also used : Calendar(java.util.Calendar) StringEval(org.apache.poi.ss.formula.eval.StringEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) Date(java.util.Date) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 25 with StringEval

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

the class TestWorkdayFunction method testReturnRetroativeWorkday.

@Test
public void testReturnRetroativeWorkday() {
    Calendar expCal = LocaleUtil.getLocaleCalendar(2008, 8, 23);
    Date expDate = expCal.getTime();
    ValueEval[] ve = { new StringEval(STARTING_DATE), new NumberEval(-5), new StringEval(RETROATIVE_HOLIDAY) };
    double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
    Date actDate = DateUtil.getJavaDate(numberValue);
    assertEquals(expDate, actDate);
}
Also used : Calendar(java.util.Calendar) StringEval(org.apache.poi.ss.formula.eval.StringEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) Date(java.util.Date) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Aggregations

StringEval (org.apache.poi.ss.formula.eval.StringEval)58 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)48 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)29 Test (org.junit.Test)18 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)13 Calendar (java.util.Calendar)10 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)10 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)9 Date (java.util.Date)8 I_MatchPredicate (org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate)7 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)5 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)3 RefEval (org.apache.poi.ss.formula.eval.RefEval)3 BigDecimal (java.math.BigDecimal)1 DateFormatSymbols (java.text.DateFormatSymbols)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 NumberFormat (java.text.NumberFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1