Examples of Eval


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

    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

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

    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

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

                int numops = operation.getNumberOfOperands();
                Eval[] ops = new Eval[numops];

                // storing the ops in reverse order since they are popping
                for (int j = numops - 1; j >= 0; j--) {
                    Eval p = (Eval) stack.pop();
                    ops[j] = p;
                }
                Eval opresult = invokeOperation(operation, ops, srcRowNum, srcColNum, workbook, sheet);
                stack.push(opresult);
            }
            else if (ptg instanceof ReferencePtg) {
                ReferencePtg refPtg = (ReferencePtg) ptg;
                int colIx = refPtg.getColumn();
                int rowIx = refPtg.getRow();
                HSSFRow row = sheet.getRow(rowIx);
                HSSFCell cell = (row != null) ? row.getCell(colIx) : null;
                stack.push(createRef2DEval(refPtg, cell, row, sheet, workbook));
            }
            else if (ptg instanceof Ref3DPtg) {
                Ref3DPtg refPtg = (Ref3DPtg) ptg;
                int colIx = refPtg.getColumn();
                int rowIx = refPtg.getRow();
                Workbook wb = workbook.getWorkbook();
                HSSFSheet xsheet = workbook.getSheetAt(wb.getSheetIndexFromExternSheetIndex(refPtg.getExternSheetIndex()));
                HSSFRow row = xsheet.getRow(rowIx);
                HSSFCell cell = (row != null) ? row.getCell(colIx) : null;
                stack.push(createRef3DEval(refPtg, cell, row, xsheet, workbook));
            }
            else if (ptg instanceof AreaPtg) {
                AreaPtg ap = (AreaPtg) ptg;
                AreaEval ae = evaluateAreaPtg(sheet, workbook, ap);
                stack.push(ae);
            }
            else if (ptg instanceof Area3DPtg) {
                Area3DPtg a3dp = (Area3DPtg) ptg;
                AreaEval ae = evaluateArea3dPtg(workbook, a3dp);
                stack.push(ae);
            }
            else {
                Eval ptgEval = getEvalForPtg(ptg);
                stack.push(ptgEval);
            }
        }

        ValueEval value = ((ValueEval) stack.pop());
View Full Code Here

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

     * passed here!
     *
     * @param ptg
     */
    protected static Eval getEvalForPtg(Ptg ptg) {
        Eval retval = null;

        Class clazz = (Class) VALUE_EVALS_MAP.get(ptg.getClass());
        try {
            if (ptg instanceof Area3DPtg) {
                Constructor constructor = clazz.getConstructor(AREA3D_CONSTRUCTOR_CLASS_ARRAY);
View Full Code Here

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

* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
public 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

      return _size;
    }
  }

  public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) {
    Eval arg3 = null;
    switch(args.length) {
      case 4:
        arg3 = args[3]; // important: assumed array element is never null
      case 3:
        break;
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 AreaEval) {
      AreaEval reference = (AreaEval) firstArg;
     
      int rowIx = 0;
      int columnIx = 0;
      int areaIx = 0;
      switch(nArgs) {
        case 4:
          areaIx = convertIndexArgToZeroBase(args[3]);
          throw new RuntimeException("Incomplete code" +
              " - don't know how to support the 'area_num' parameter yet)");
          // Excel expression might look like this "INDEX( (A1:B4, C3:D6, D2:E5 ), 1, 2, 3)
          // In this example, the 3rd area would be used i.e. D2:E5, and the overall result would be E2
          // Token array might be encoded like this: MemAreaPtg, AreaPtg, AreaPtg, UnionPtg, UnionPtg, ParenthesesPtg
          // The formula parser doesn't seem to support this yet. Not sure if the evaluator does either
         
        case 3:
          columnIx = convertIndexArgToZeroBase(args[2]);
        case 2:
          rowIx = convertIndexArgToZeroBase(args[1]);
          break;
        default:
          // too many arguments
          return ErrorEval.VALUE_INVALID;
      }
     
          int nColumns = reference.getLastColumn()-reference.getFirstColumn()+1;
      int index = rowIx * nColumns + columnIx;
     
      return reference.getValues()[index];
    }
   
    // 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() + ")");
  }
View Full Code Here

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

*
*/
public class Right extends TextFunction {

    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
        Eval retval = ErrorEval.VALUE_INVALID;
        int index = 1;
        switch (operands.length) {
        default:
            break;
        case 2:
            Eval indexEval = operands[1];
            index = evaluateAsInteger(indexEval);
            if (index < 0) {
                break;
            }
        case 1:
View Full Code Here

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

        }
        return numval;
    }
   
    protected Eval xlateRefEval(RefEval reval) {
        Eval retval = reval.getInnerValueEval();
       
        if (retval instanceof RefEval) {
            retval = xlateRefEval((RefEval) retval);
        }
        return retval;
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.