Examples of Eval


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

    /*
     * Note: no short-circuit boolean loop exit because any ErrorEvals will override the result
     */
    for (int i=0, iSize=args.length; i<iSize; i++) {
      Eval arg = args[i];
      if (arg instanceof AreaEval) {
        AreaEval ae = (AreaEval) arg;
        int height = ae.getHeight();
        int width = ae.getWidth();
        for (int rrIx=0; rrIx<height; rrIx++) {
          for (int rcIx=0; rcIx<width; rcIx++) {
            ValueEval ve = ae.getRelativeValue(rrIx, rcIx);
            Boolean tempVe = OperandResolver.coerceValueToBoolean(ve, true);
            if (tempVe != null) {
              result = partialEvaluate(result, tempVe.booleanValue());
              atleastOneNonBlank = true;
            }
          }
        }
        continue;
      }
      Boolean tempVe;
      if (arg instanceof RefEval) {
        ValueEval ve = ((RefEval) arg).getInnerValueEval();
        tempVe = OperandResolver.coerceValueToBoolean(ve, true);
      } else if (arg instanceof ValueEval) {
        ValueEval ve = (ValueEval) arg;
        tempVe = OperandResolver.coerceValueToBoolean(ve, false);
      } else {
        throw new RuntimeException("Unexpected eval (" + arg.getClass().getName() + ")");
      }


      if (tempVe != null) {
        result = partialEvaluate(result, tempVe.booleanValue());
View Full Code Here

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

* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
*
*/
public final class Istext extends LogicalFunction {
    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
        Eval retval = BoolEval.FALSE;

        switch (operands.length) {
        default:
            retval = ErrorEval.VALUE_INVALID;
            break;
        case 1:
            Eval eval = operands[0];
            if (eval instanceof StringEval) {
                retval = BoolEval.TRUE;
            }
            else if (eval instanceof RefEval) {
                Eval xlatedEval = xlateRefEval((RefEval) eval);
                if (xlatedEval instanceof StringEval) {
                    retval = BoolEval.TRUE;
                }
            }
        }
View Full Code Here

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

*
*/
public final class If implements Function {

  public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) {
    Eval falseResult;
    switch (args.length) {
      case 3:
        falseResult = args[2];
        break;
      case 2:
View Full Code Here

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

    int nArgs = args.length;
    if(nArgs < 2) {
      // too few arguments
      return ErrorEval.VALUE_INVALID;
    }
    Eval firstArg = args[0];
    if (firstArg instanceof RefEval) {
      // convert to area ref for simpler code in getValueFromArea()
      firstArg = ((RefEval)firstArg).offset(0, 0, 0, 0);
    }
    if(!(firstArg instanceof AreaEval)) {

      // else the other variation of this function takes an array as the first argument
      // it seems like interface 'ArrayEval' does not even exist yet
      throw new RuntimeException("Incomplete code - cannot handle first arg of type ("
          + firstArg.getClass().getName() + ")");
    }
    AreaEval reference = (AreaEval) firstArg;

    int rowIx = 0;
    int columnIx = 0;
View Full Code Here

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

* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
*
*/
public final class Isnumber extends LogicalFunction {
    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
        Eval retval = BoolEval.FALSE;

        switch (operands.length) {
        default:
            retval = ErrorEval.VALUE_INVALID;
            break;
        case 1:
            Eval eval = operands[0];
            if (eval instanceof NumberEval) {
                retval = BoolEval.TRUE;
            }
            else if (eval instanceof RefEval) {
                Eval xlatedEval = xlateRefEval((RefEval) eval);
                if (xlatedEval instanceof NumberEval) {
                    retval = BoolEval.TRUE;
                }
            }
        }
View Full Code Here

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



  private static double evaluateMatchTypeArg(Eval arg, int srcCellRow, short srcCellCol)
      throws EvaluationException {
    Eval match_type = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);

    if(match_type instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval)match_type);
    }
    if(match_type instanceof NumericValueEval) {
      NumericValueEval ne = (NumericValueEval) match_type;
      return ne.getNumberValue();
    }
    if (match_type instanceof StringEval) {
      StringEval se = (StringEval) match_type;
      Double d = OperandResolver.parseDouble(se.getStringValue());
      if(d == null) {
        // plain string
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      // if the string parses as a number, it is OK
      return d.doubleValue();
    }
    throw new RuntimeException("Unexpected match_type type (" + match_type.getClass().getName() + ")");
  }
View Full Code Here

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

        new NumberEval(26.0),
        new NumberEval(28.0),
    };
    AreaEval arg0 = EvalFactory.createAreaEval("A10:C10", values);
    Eval[] args = new Eval[] { arg0, MissingArgEval.instance, new NumberEval(2), };
    Eval actualResult;
    try {
      actualResult = FUNC_INST.evaluate(args, 1, (short)1);
    } catch (RuntimeException e) {
      if (e.getMessage().equals("Unexpected arg eval type (org.apache.poi.hssf.record.formula.eval.MissingArgEval")) {
        throw new AssertionFailedError("Identified bug 47048b - INDEX() should support missing-arg");
      }
      throw e;
    }
    assertEquals(NumberEval.class, actualResult.getClass());
    assertEquals(26.0, ((NumberEval)actualResult).getNumberValue(), 0.0);
  }
View Full Code Here

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

  private static void confirmPredicate(boolean expectedResult, I_MatchPredicate matchPredicate, int value) {
    assertEquals(expectedResult, matchPredicate.matches(new NumberEval(value)));
  }
  private static void confirmPredicate(boolean expectedResult, I_MatchPredicate matchPredicate, String value) {
    Eval ev = value == null ? (Eval)BlankEval.INSTANCE : new StringEval(value);
    assertEquals(expectedResult, matchPredicate.matches(ev));
  }
View Full Code Here

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

  /**
   * Formats nicer error messages for the junit output
   */
  private static double invokeInternal(Object target, Eval[] args, int srcCellRow, int srcCellCol)
        throws NumericEvalEx {
    Eval evalResult;
    // TODO - make OperationEval extend Function
    try {
      if (target instanceof Function) {
        Function ff = (Function) target;
        evalResult = ff.evaluate(args, srcCellRow, (short)srcCellCol);
      } else {
        OperationEval ff = (OperationEval) target;
        evalResult = ff.evaluate(args, srcCellRow, (short)srcCellCol);
      }
    } catch (NotImplementedException e) {
      throw new NumericEvalEx("Not implemented:" + e.getMessage());
    }
   
    if(evalResult == null) {
      throw new NumericEvalEx("Result object was null");
    }
    if(evalResult instanceof ErrorEval) {
      ErrorEval ee = (ErrorEval) evalResult;
      throw new NumericEvalEx(formatErrorMessage(ee));
    }
    if(!(evalResult instanceof NumericValueEval)) {
      throw new NumericEvalEx("Result object type (" + evalResult.getClass().getName()
          + ") is invalid.  Expected implementor of ("
          + NumericValueEval.class.getName() + ")");
    }
   
    NumericValueEval result = (NumericValueEval) evalResult;
View Full Code Here

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

    Eval[] args = {
      new NumberEval(0.05),
      new NumberEval(250),
      new NumberEval(-1000),
    };
    Eval result = FinanceFunction.NPER.evaluate(args, 0, (short)0);

    assertEquals(NumberEval.class, result.getClass());
    assertEquals(4.57353557, ((NumberEval)result).getNumberValue(), 0.00000001);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.