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

Examples of org.apache.poi.ss.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


            _matchExact = matchExact;
            _isMatchFunction = isMatchFunction;
    }

    protected CompareResult compareSameType(ValueEval other) {
            StringEval se = (StringEval) other;

            String stringValue = se.getStringValue();
            if (_wildCardPattern != null) {
                Matcher matcher = _wildCardPattern.matcher(stringValue);
                boolean matches = matcher.matches();

                if (_isMatchFunction ||
View Full Code Here

    public static final String DEFAULT_SUFFIX = "i";
    public static final String SUPPORTED_SUFFIX = "j";

    public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval real_num, ValueEval i_num) {
        return this.evaluate(srcRowIndex, srcColumnIndex, real_num, i_num, new StringEval(DEFAULT_SUFFIX));
    }
View Full Code Here

            }

            strb.append(suffixValue);
        }

        return new StringEval(strb.toString());
    }
View Full Code Here

    if (eval instanceof BoolEval) {
      BoolEval be = (BoolEval) eval;
      return CellValue.valueOf(be.getBooleanValue());
    }
    if (eval instanceof StringEval) {
      StringEval ne = (StringEval) eval;
      return new CellValue(ne.getStringValue());
    }
    if (eval instanceof ErrorEval) {
      return CellValue.getError(((ErrorEval)eval).getErrorCode());
    }
    throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
View Full Code Here

*
* @author cedric dot walter @ gmail dot com
*/
public class TestQuotient extends TestCase {
    private static ValueEval invokeValue(String numerator, String denominator) {
        ValueEval[] args = new ValueEval[]{new StringEval(numerator), new StringEval(denominator)};
        return new Quotient().evaluate(args, -1, -1);
    }
View Full Code Here

  }

  public void testSimpleString() {
        // Arrange
    ValueEval[] values = {
      new StringEval("Albert"),
      new StringEval("Charles"),
      new StringEval("Ed"),
      new StringEval("Greg"),
      new StringEval("Ian"),
    };

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

    // Note String comparisons are case insensitive
    confirmInt(3, invokeMatch(new StringEval("Ed"), ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(new StringEval("eD"), ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(new StringEval("Ed"), ae, MATCH_EXACT));
    confirmInt(3, invokeMatch(new StringEval("ed"), ae, MATCH_EXACT));

    assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Hugh"), ae, MATCH_EXACT));
  }
View Full Code Here

  }

    public void testSimpleWildcardValuesString() {
        // Arrange
        ValueEval[] values = {
                new StringEval("Albert"),
                new StringEval("Charles"),
                new StringEval("Ed"),
                new StringEval("Greg"),
                new StringEval("Ian"),
        };

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

        // Note String comparisons are case insensitive
        confirmInt(3, invokeMatch(new StringEval("e*"), ae, MATCH_EXACT));
        confirmInt(3, invokeMatch(new StringEval("*d"), ae, MATCH_EXACT));

        confirmInt(1, invokeMatch(new StringEval("Al*"), ae, MATCH_EXACT));
        confirmInt(2, invokeMatch(new StringEval("Char*"), ae, MATCH_EXACT));

        confirmInt(4, invokeMatch(new StringEval("*eg"), ae, MATCH_EXACT));
        confirmInt(4, invokeMatch(new StringEval("G?eg"), ae, MATCH_EXACT));
        confirmInt(4, invokeMatch(new StringEval("??eg"), ae, MATCH_EXACT));
        confirmInt(4, invokeMatch(new StringEval("G*?eg"), ae, MATCH_EXACT));
        confirmInt(4, invokeMatch(new StringEval("Hugh"), ae, MATCH_LARGEST_LTE));

        confirmInt(5, invokeMatch(new StringEval("*Ian*"), ae, MATCH_EXACT));
        confirmInt(5, invokeMatch(new StringEval("*Ian*"), ae, MATCH_LARGEST_LTE));
    }
View Full Code Here

    }

    public void testTildeString() {

        ValueEval[] values = {
                new StringEval("what?"),
                new StringEval("all*")
        };

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

        confirmInt(1, invokeMatch(new StringEval("what~?"), ae, MATCH_EXACT));
        confirmInt(2, invokeMatch(new StringEval("all~*"), ae, MATCH_EXACT));
    }
View Full Code Here

    ValueEval[] values = {
        new NumberEval(4),
        BoolEval.FALSE,
        new NumberEval(5),
        new StringEval("Albert"),
        BoolEval.FALSE,
        BoolEval.TRUE,
        new NumberEval(10),
        new StringEval("Charles"),
        new StringEval("Ed"),
        new NumberEval(10),
        new NumberEval(25),
        BoolEval.TRUE,
        new StringEval("Ed"),
    };

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

    assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Aaron"), ae, MATCH_LARGEST_LTE));

    confirmInt(5, invokeMatch(BoolEval.FALSE, ae, MATCH_LARGEST_LTE));
    confirmInt(2, invokeMatch(BoolEval.FALSE, ae, MATCH_EXACT));
    confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_EXACT));

    confirmInt(8, invokeMatch(new StringEval("CHARLES"), ae, MATCH_EXACT));
        //wildcard values
        confirmInt(8, invokeMatch(new StringEval("CHAR*"), ae, MATCH_EXACT));
        confirmInt(8, invokeMatch(new StringEval("*CHARLES"), ae, MATCH_EXACT));

    confirmInt(4, invokeMatch(new StringEval("Ben"), ae, MATCH_LARGEST_LTE));

    confirmInt(13, invokeMatch(new StringEval("ED"), ae, MATCH_LARGEST_LTE));
    confirmInt(13, invokeMatch(new StringEval("ED*"), ae, MATCH_LARGEST_LTE));
    confirmInt(13, invokeMatch(new StringEval("*ED"), ae, MATCH_LARGEST_LTE));
    confirmInt(9, invokeMatch(new StringEval("ED"), ae, MATCH_EXACT));
    confirmInt(9, invokeMatch(new StringEval("ED*"), ae, MATCH_EXACT));

    confirmInt(13, invokeMatch(new StringEval("Hugh"), ae, MATCH_LARGEST_LTE));
    assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Hugh"), ae, MATCH_EXACT));

    confirmInt(11, invokeMatch(new NumberEval(30), ae, MATCH_LARGEST_LTE));
    confirmInt(12, invokeMatch(BoolEval.TRUE, ae, MATCH_LARGEST_LTE));
  }
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.