Package org.openntf.formula

Examples of org.openntf.formula.ValueHolder


   * Returns {@link FormulaContext#TRUE ctx.TRUE} if the Value's Datatype = DataType.ERROR
   */
  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {

    ValueHolder ret = children[0].evaluate(ctx);
    if (ret.dataType == DataType.ERROR)
      return ctx.TRUE;
    return ctx.FALSE;

  }
View Full Code Here


  // ----------- Strings
  @Override
  protected ValueHolder evaluateString(final FormulaContext ctx, final ValueHolder[] params) {
    Collection<String[]> values = new ParameterCollectionObject<String>(params, String.class, isPermutative);
    ValueHolder ret = ValueHolder.createValueHolder(String.class, values.size());
    for (String[] value : values) {
      ret.add(computer.compute(value[0], value[1]));
    }
    return ret;

  }
View Full Code Here

  // ----------- Numbers
  @Override
  protected ValueHolder evaluateNumber(final FormulaContext ctx, final ValueHolder[] params) {

    Collection<double[]> values = new ParameterCollectionDouble(params, isPermutative);
    ValueHolder ret = ValueHolder.createValueHolder(double.class, values.size());

    for (double[] value : values) {
      ret.add(computer.compute(value[0], value[1]));
    }

    return ret;
  }
View Full Code Here

  // ----------- Integers
  @Override
  protected ValueHolder evaluateInt(final FormulaContext ctx, final ValueHolder[] params) {

    Collection<int[]> values = new ParameterCollectionInt(params, isPermutative);
    ValueHolder ret = ValueHolder.createValueHolder(int.class, values.size());

    for (int[] value : values) {
      try {
        ret.add(computer.compute(value[0], value[1]));
      } catch (IntegerOverflowException e) {
        ret.add(computer.compute((double) value[0], (double) value[1]));
      }
    }
    return ret;
  }
View Full Code Here

  // ----------- DateTimes
  @Override
  protected ValueHolder evaluateDateTime(final FormulaContext ctx, final ValueHolder[] params) {
    Collection<DateTime[]> values = new ParameterCollectionObject<DateTime>(params, DateTime.class, isPermutative);
    ValueHolder ret = ValueHolder.createValueHolder(DateTime.class, values.size());

    for (DateTime[] value : values) {
      ret.add(computer.compute(value[0], value[1]));
    }
    return ret;
  }
View Full Code Here

  // ----------- Numbers
  @Override
  protected ValueHolder evaluateBoolean(final FormulaContext ctx, final ValueHolder[] params) {

    Collection<boolean[]> values = new ParameterCollectionBoolean(params, isPermutative);
    ValueHolder ret = ValueHolder.createValueHolder(boolean.class, values.size());

    for (boolean[] value : values) {
      ret.add(computer.compute(value[0], value[1]));
    }

    return ret;
  }
View Full Code Here

    function = p.getFunctionLC("@text");
  }

  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {
    ValueHolder params[] = new ValueHolder[children.length];
    ValueHolder ret = null;
    for (int i = 0; i < children.length; i++) {
      params[i] = children[i].evaluate(ctx);
      if (params[i].dataType == DataType.ERROR) {
        ret = params[i];
        break;
      }
    }
    try {
      if (ret == null) {
        ret = function.evaluate(ctx, params);
      }
    } catch (RuntimeException e) {
      return ValueHolder.valueOf(new EvaluateException(codeLine, codeColumn, e));
    }
    if (ret.dataType == DataType.ERROR)
      ret = ValueHolder.valueOf(ret.getError().getMessage());
    return ret;
  }
View Full Code Here

   * {@literal @}IfError detects the error of the first valueHolder and returns the second one
   */
  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {

    ValueHolder vh = children[0].evaluate(ctx);

    if (vh.dataType == DataType.ERROR && children.length == 2) {
      return children[1].evaluate(ctx);
    }

View Full Code Here

    int valueSize = 0;
    int holders = 0;

    for (int i = 0; i < children.length; ++i) {
      // Cumulate all return values
      ValueHolder vh = children[i].evaluate(ctx);
      if (vh != null) {
        if (vh.dataType == DataType.ERROR)
          return vh;
        valueSize += vh.size;
        tmpHolders[holders++] = vh;
      }
    }

    if (holders == 0)
      return null;

    ValueHolder vhRet = tmpHolders[0].newInstance(valueSize);
    for (int i = 0; i < holders; i++) {
      vhRet.addAll(tmpHolders[i]);
    }
    return vhRet;
  }
View Full Code Here

  @SuppressWarnings("deprecation")
  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {
    try {
      ValueHolder base = children[0].evaluate(ctx);

      ValueHolder subscript = children[1].evaluate(ctx);

      int idx = subscript.getInt(0); // we need it as INT here
      if (idx < 1 || idx > base.size) {
        throw new IndexOutOfBoundsException("Index " + idx + " not in 1.." + base.size);
      }

      idx--; // Formula is 1 based
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.