Package org.apache.poi.hssf.record.formula.eval

Examples of org.apache.poi.hssf.record.formula.eval.StringEval


      // All errors get translated to #REF!
      throw EvaluationException.invalidRef();
    }
    int oneBasedIndex;
    if(veRowColIndexArg instanceof StringEval) {
      StringEval se = (StringEval) veRowColIndexArg;
      String strVal = se.getStringValue();
      Double dVal = OperandResolver.parseDouble(strVal);
      if(dVal == null) {
        // String does not resolve to a number. Raise #REF! error.
        throw EvaluationException.invalidRef();
        // This includes text booleans "TRUE" and "FALSE".  They are not valid.
View Full Code Here


    protected StringLookupComparer(StringEval se) {
      super(se);
      _value = se.getStringValue();
    }
    protected CompareResult compareSameType(ValueEval other) {
      StringEval se = (StringEval) other;
      return CompareResult.valueOf(_value.compareToIgnoreCase(se.getStringValue()));
    }
View Full Code Here

          default:
            // never matches (also inconsistent with above three cases).
            // for example '>5' does not match '6',
            return false;
        }
        StringEval se = (StringEval)x;
        Double val = OperandResolver.parseDouble(se.getStringValue());
        if(val == null) {
          // x is text that is not a number
          return false;
        }
        return _value == val.doubleValue();
View Full Code Here

        if (true) { // change to false to observe more intuitive behaviour
          // Note - Unlike with numbers, it seems that COUNTIF never matches
          // boolean values when the target(x) is a string
          return false;
        }
        StringEval se = (StringEval)x;
        Boolean val = parseBoolean(se.getStringValue());
        if(val == null) {
          // x is text that is not a boolean
          return false;
        }
        testValue = boolToInt(val.booleanValue());
View Full Code Here

    if (ve instanceof NumericValueEval) {
      return ((NumericValueEval) ve).getNumberValue();
    }
    if (ve instanceof StringEval) {
      StringEval se = (StringEval) ve;
      Double d = OperandResolver.parseDouble(se.getStringValue());
      if(d == null) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      return d.doubleValue();
    }
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

    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 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

TOP

Related Classes of org.apache.poi.hssf.record.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.