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

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


    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


    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]),
View Full Code Here

    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"));
    // when criteria is an expression (starting with a comparison operator)
    confirmCountIf(2, range, new StringEval(">0.5"));
  }
View Full Code Here

    // when criteria is an expression (starting with a comparison operator)
    confirmCountIf(2, range, new StringEval(">0.5"));
  }

  public void testCriteriaPredicateNe_Bug46647() {
    I_MatchPredicate mp = Countif.createCriteriaPredicate(new StringEval("<>aa"), 0, 0);
    StringEval seA = new StringEval("aa"); // this should not match the criteria '<>aa'
    StringEval seB = new StringEval("bb"); // this should match
    if (mp.matches(seA) && !mp.matches(seB)) {
      throw new AssertionFailedError("Identified bug 46647");
    }
    assertFalse(mp.matches(seA));
    assertTrue(mp.matches(seB));

    // general tests for not-equal (<>) operator
    AreaEval range;
    ValueEval[] values;

    values = new ValueEval[] {
        new StringEval("aa"),
        new StringEval("def"),
        new StringEval("aa"),
        new StringEval("ghi"),
        new StringEval("aa"),
        new StringEval("aa"),
    };

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

    values = new ValueEval[] {
        new StringEval("ab"),
        new StringEval("aabb"),
        new StringEval("aa"), // match
        new StringEval("abb"),
        new StringEval("aab"),
        new StringEval("ba"), // match
    };

    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);
    confirmCountIf(4, range, new StringEval("<>111"));
  }
View Full Code Here

    public void testCaseInsensitiveStringComparison() {
        AreaEval range;
        ValueEval[] values;

        values = new ValueEval[] {
                new StringEval("no"),
                new StringEval("NO"),
                new StringEval("No"),
                new StringEval("Yes")
        };

        range = EvalFactory.createAreaEval("A1:A4", values);
        confirmCountIf(3, range, new StringEval("no"));
        confirmCountIf(3, range, new StringEval("NO"));
        confirmCountIf(3, range, new StringEval("No"));
    }
View Full Code Here

   */
  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, });

    I_MatchPredicate mp;
View Full Code Here

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

  }

  public void testCountifComparisons() {
    I_MatchPredicate mp;

    mp = createCriteriaPredicate(new StringEval(">5"));
    confirmPredicate(false, mp, 4);
    confirmPredicate(false, mp, 5);
    confirmPredicate(true, mp, 6);

    mp = createCriteriaPredicate(new StringEval("<=5"));
    confirmPredicate(true, mp, 4);
    confirmPredicate(true, mp, 5);
    confirmPredicate(false, mp, 6);
    confirmPredicate(false, mp, "4.9");
    confirmPredicate(false, mp, "4.9t");
    confirmPredicate(false, mp, "5.1");
    confirmPredicate(false, mp, NULL);

    mp = createCriteriaPredicate(new StringEval("=abc"));
    confirmPredicate(true, mp, "abc");

    mp = createCriteriaPredicate(new StringEval("=42"));
    confirmPredicate(false, mp, 41);
    confirmPredicate(true, mp, 42);
    confirmPredicate(true, mp, "42");

    mp = createCriteriaPredicate(new StringEval(">abc"));
    confirmPredicate(false, mp, 4);
    confirmPredicate(false, mp, "abc");
    confirmPredicate(true, mp, "abd");

    mp = createCriteriaPredicate(new StringEval(">4t3"));
    confirmPredicate(false, mp, 4);
    confirmPredicate(false, mp, 500);
    confirmPredicate(true, mp, "500");
    confirmPredicate(true, mp, "4t4");
  }
View Full Code Here

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

  }

  public void testWildCards() {
    I_MatchPredicate mp;

    mp = createCriteriaPredicate(new StringEval("a*b"));
    confirmPredicate(false, mp, "abc");
    confirmPredicate(true, mp, "ab");
    confirmPredicate(true, mp, "axxb");
    confirmPredicate(false, mp, "xab");

    mp = createCriteriaPredicate(new StringEval("a?b"));
    confirmPredicate(false, mp, "abc");
    confirmPredicate(false, mp, "ab");
    confirmPredicate(false, mp, "axxb");
    confirmPredicate(false, mp, "xab");
    confirmPredicate(true, mp, "axb");

    mp = createCriteriaPredicate(new StringEval("a~?"));
    confirmPredicate(false, mp, "a~a");
    confirmPredicate(false, mp, "a~?");
    confirmPredicate(true, mp, "a?");

    mp = createCriteriaPredicate(new StringEval("~*a"));
    confirmPredicate(false, mp, "~aa");
    confirmPredicate(false, mp, "~*a");
    confirmPredicate(true, mp, "*a");

    mp = createCriteriaPredicate(new StringEval("12?12"));
    confirmPredicate(false, mp, 12812);
    confirmPredicate(true, mp, "12812");
    confirmPredicate(false, mp, "128812");
  }
View Full Code Here

TOP

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

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.