Package org.openntf.formula

Examples of org.openntf.formula.ValueHolder


  /**
   * Evaluates the operator
   */
  public ValueHolder evaluate(final FormulaContext ctx, final ValueHolder[] params) {
    ValueHolder v1 = params[0]; // Fetch first element to determine operation
    ValueHolder v2 = params[1]; // Fetch first element to determine operation

    if (v1.dataType == DataType.ERROR) {
      return v1;
    }
    if (v2.dataType == DataType.ERROR) {
      return v2;
    }

    boolean multi = v1.size > 1 ? true : false;
    if (v2.size > 1)
      multi = true;

    switch (v1.dataType) {
    case DATETIME:
      if (v2.dataType == DataType.DATETIME) {
        if (multi)
          return evaluateDateTime(ctx, params);
        return evaluateDateTime(ctx, v1.getDateTime(0), v2.getDateTime(0));
      }
      break;

    case INTEGER:

      if (v2.dataType == DataType.INTEGER) {
        if (multi)
          return evaluateInt(ctx, params);
        return evaluateInt(ctx, v1.getInt(0), v2.getInt(0));
      }
      //do not break - fall through. It may be integer & double
    case DOUBLE:
      if (v2.dataType.numeric) {
        if (multi)
          return evaluateNumber(ctx, params);
        return evaluateNumber(ctx, v1.getDouble(0), v2.getDouble(0));
      }
      break;

    case STRING:
      if (v2.dataType == DataType.STRING) {
        if (multi)
          return evaluateString(ctx, params);
        return evaluateString(ctx, v1.getString(0), v2.getString(0));
      }
      break;

    case BOOLEAN:
      if (v2.dataType == DataType.BOOLEAN) {
        if (multi)
          return evaluateBoolean(ctx, params);
        return evaluateBoolean(ctx, v1.getBoolean(0), v2.getBoolean(0));
      }
      break;

    case _UNSET:
      break;
View Full Code Here


  }

  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {
    ValueHolder[] oldVHs = null;
    ValueHolder vhEval = children[0].evaluate(ctx);
    if (vhEval.dataType == DataType.ERROR)
      return vhEval;
    if (vhEval.size != children.length) {
      IllegalArgumentException ia = new IllegalArgumentException("Wrong number of parameters: Expected " + (vhEval.size - 1)
          + ", got " + (children.length - 1));
      return ValueHolder.valueOf(new EvaluateException(codeLine, codeColumn, ia));
    }
    oldVHs = new ValueHolder[vhEval.size - 1];
    for (int i = 1; i < vhEval.size; i++)
      oldVHs[i - 1] = ctx.setVarLC(vhEval.getString(i).toLowerCase(), children[i].evaluate(ctx));
    try {

      Node n = (Node) ctx.getParser().parse(vhEval.getString(0));
      return n.evaluate(ctx);
    } catch (FormulaParseException e) {
      return ValueHolder.valueOf(new EvaluateException(codeLine, codeColumn, e));
    } finally {
      if (oldVHs != null)
        for (int i = 1; i < vhEval.size; i++)
          ctx.setVarLC(vhEval.getString(i).toLowerCase(), oldVHs[i - 1]);
    }
  }
View Full Code Here

  }

  @Test
  public final void testNewInstance() {
    vhi.add(42);
    ValueHolder vh = vhi.newInstance(10);
    assertEquals(DataType._UNSET, vh.dataType);
  }
View Full Code Here

  /**
   * ASTAssignment stores the value in a FIELD, VAR or ENV-VAR. There is no special error handling needed here.
   */
  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {
    ValueHolder value;
    value = children[0].evaluate(ctx);

    switch (type) {
    case FIELD:
      ctx.setField(varName, value);
      break;

    case VAR:
      ctx.setVarLC(varNameLC, value);
      break;

    case ENV:
      ctx.setEnv(varName, value.getString(0));
      break;

    case DEFAULT:
      ctx.setDefaultLC(varNameLC, varName, value);
      break;
View Full Code Here

  /**
   * Evaluates every entry and returns the last one
   */
  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {
    ValueHolder vhEval = children[0].evaluate(ctx);
    if (vhEval.dataType == DataType.ERROR)
      return vhEval;

    ValueHolder ret = null;
    try {
      for (int i = 0; i < vhEval.size; i++) {
        String toEval = vhEval.getString(i);

        Node n = (Node) ctx.getParser().parse(toEval, false);
View Full Code Here

  /**
   * AtDo returns the last child's value. This might be a ValueHolder of DataType.ERROR. No additional errorhandling needed
   */
  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {
    ValueHolder ret = null;
    if (children == null)
      return null;
    for (int i = 0; i < children.length; ++i) {
      ret = children[i].evaluate(ctx);
    }
View Full Code Here

  /**
   * {@literal @}If returns an error, if the condition statement fails
   */
  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {
    ValueHolder nIf;
    int i = 0;
    nIf = children[i++].evaluate(ctx);

    while (i < children.length) {
      if (nIf.dataType == DataType.ERROR)
        return nIf;

      if (nIf.isTrue(ctx)) {
        return children[i++].evaluate(ctx);
      } else {
        i++;
      }
      nIf = children[i++].evaluate(ctx);
View Full Code Here

   * AtDoWhile returns always TRUE, or an Error-ValueHolder, if an error occurs in the last parameter.
   */
  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {

    ValueHolder ret = null;
    if (children != null) {
      while (children[0].evaluate(ctx).isTrue(ctx)) {
        for (int i = 1; i < children.length; ++i) {
          children[i].evaluate(ctx);
        }
View Full Code Here

  /**
   * Evaluates the operator
   */
  public ValueHolder evaluate(final FormulaContext ctx, final ValueHolder[] params) {
    ValueHolder v1 = params[0]; // Fetch first element to determine operation

    if (v1.dataType == DataType.ERROR) {
      return v1;
    }

    ValueHolder ret = v1.newInstance(v1.size);
    switch (v1.dataType) {

    case INTEGER:
      for (int i = 0; i < v1.size; i++) {
        ret.add(compute(ctx, v1.getInt(i)));
      }
      return ret;
    case BOOLEAN:
      for (int i = 0; i < v1.size; i++) {
        ret.add(compute(ctx, v1.getBoolean(i)));
      }
      return ret;

    case DOUBLE:
      for (int i = 0; i < v1.size; i++) {
        ret.add(compute(ctx, v1.getDouble(i)));
      }
      return ret;
    default:
      break;

View Full Code Here

  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {
    Node init = children[0];
    Node condition = children[1];
    Node increment = children[2];

    ValueHolder vh = init.evaluate(ctx);
    if (vh.dataType == DataType.ERROR)
      return vh;

    while (true) {

      vh = condition.evaluate(ctx);
      if (vh.dataType == DataType.ERROR)
        return vh;
      if (!vh.isTrue(ctx))
        break;

      // execute statements
      for (int i = 3; i < children.length; ++i) {
        children[i].evaluate(ctx);
View Full Code Here

TOP

Related Classes of org.openntf.formula.ValueHolder

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.