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

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


    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

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



  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

        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

  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

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

    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

    Eval[] args = new Eval[] { new StringEval(strText), };
    return new Value().evaluate(args, -1, (short) -1);
  }

  private static void confirmValue(String strText, double expected) {
    Eval result = invokeValue(strText);
    assertEquals(NumberEval.class, result.getClass());
    assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0);
  }
View Full Code Here

    assertEquals(NumberEval.class, result.getClass());
    assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0);
  }

  private static void confirmValueError(String strText) {
    Eval result = invokeValue(strText);
    assertEquals(ErrorEval.class, result.getClass());
    assertEquals(ErrorEval.VALUE_INVALID, result);
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.record.formula.eval.Eval

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.