Package org.apache.poi.ss.formula.eval

Examples of org.apache.poi.ss.formula.eval.NumberEval


    if(mp == null) {
      // If the criteria arg is a reference to a blank cell, countif always returns zero.
      return NumberEval.ZERO;
    }
    double result = countMatchingCellsInArea(arg0, mp);
    return new NumberEval(result);
  }
View Full Code Here


    AreaEval range;
    ValueEval[] values;

    values = new ValueEval[] {
        new NumberEval(0),
        new StringEval("")// note - does not match blank
        BoolEval.TRUE,
        BoolEval.FALSE,
        ErrorEval.DIV_ZERO,
        BlankEval.instance,
    };
    range = EvalFactory.createAreaEval("A1:B3", values);
    confirmCountBlank(1, range);

    values = new ValueEval[] {
        new NumberEval(0),
        new StringEval("")// note - does not match blank
        BlankEval.instance,
        BoolEval.FALSE,
        BoolEval.TRUE,
        BlankEval.instance,
View Full Code Here

  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);
  }
View Full Code Here

    AreaEval range;
    ValueEval[] values;

    // when criteria is a boolean value
    values = new ValueEval[] {
        new NumberEval(0),
        new StringEval("TRUE")// note - does not match boolean 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"));
View Full Code Here

    range = EvalFactory.createAreaEval("A1:A6", values);
    confirmCountIf(2, range, new StringEval("<>a*b"));


    values = new ValueEval[] {
        new NumberEval(222),
        new NumberEval(222),
        new NumberEval(111),
        new StringEval("aa"),
        new StringEval("111"),
    };

    range = EvalFactory.createAreaEval("A1:A5", values);
View Full Code Here

   * special case where the criteria argument is a cell reference
   */
  public void testCountIfWithCriteriaReference() {

    ValueEval[] values = {
        new NumberEval(22),
        new NumberEval(25),
        new NumberEval(21),
        new NumberEval(25),
        new NumberEval(25),
        new NumberEval(25),
    };
    AreaEval arg0 = EvalFactory.createAreaEval("C1:C6", values);

    ValueEval criteriaArg = EvalFactory.createRefEval("A1", new NumberEval(25));
    ValueEval[] args=  { arg0, criteriaArg, };

    double actual = NumericFunctionInvoker.invoke(new Countif(), args);
    assertEquals(4, actual, 0D);
  }
View Full Code Here

   * the criteria arg is mostly handled by {@link OperandResolver#getSingleValue(org.apache.poi.ss.formula.eval.ValueEval, int, int)}}
   */
  public void testCountifAreaCriteria() {
    int srcColIx = 2; // anything but column A

    ValueEval v0 = new NumberEval(2.0);
    ValueEval v1 = new StringEval("abc");
    ValueEval v2 = ErrorEval.DIV_ZERO;

    AreaEval ev = EvalFactory.createAreaEval("A10:A12", new ValueEval[] { v0, v1, v2, });

View Full Code Here

    confirmPredicate(false, mp, "a*a");
    confirmPredicate(true, mp, "a*c");
  }

  private static void confirmPredicate(boolean expectedResult, I_MatchPredicate matchPredicate, int value) {
    assertEquals(expectedResult, matchPredicate.matches(new NumberEval(value)));
  }
View Full Code Here

  }

  public void testSimpleNumber() {

    ValueEval[] values = {
      new NumberEval(4),
      new NumberEval(5),
      new NumberEval(10),
      new NumberEval(10),
      new NumberEval(25),
    };

    AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);

    confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
    confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new NumberEval(10), ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(new NumberEval(10), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new NumberEval(20), ae, MATCH_LARGEST_LTE));
    assertEquals(ErrorEval.NA, invokeMatch(new NumberEval(20), ae, MATCH_EXACT));
  }
View Full Code Here

  }

  public void testReversedNumber() {

    ValueEval[] values = {
      new NumberEval(25),
      new NumberEval(10),
      new NumberEval(10),
      new NumberEval(10),
      new NumberEval(4),
    };

    AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);

    confirmInt(2, invokeMatch(new NumberEval(10), ae, MATCH_SMALLEST_GTE));
    confirmInt(2, invokeMatch(new NumberEval(10), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new NumberEval(9), ae, MATCH_SMALLEST_GTE));
    confirmInt(1, invokeMatch(new NumberEval(20), ae, MATCH_SMALLEST_GTE));
    assertEquals(ErrorEval.NA, invokeMatch(new NumberEval(20), ae, MATCH_EXACT));
    assertEquals(ErrorEval.NA, invokeMatch(new NumberEval(26), ae, MATCH_SMALLEST_GTE));
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.formula.eval.NumberEval

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.