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

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


  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


      for (int i = 0; i < lookupRange.length; i++) {
        if(lookupComparer.compareTo(lookupRange[i]).isEqual()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }
   
    if(findLargestLessThanOrEqual) {
      // Note - backward iteration
      for (int i = lookupRange.length - 1; i>=0;  i--) {
        CompareResult cmp = lookupComparer.compareTo(lookupRange[i]);
        if(cmp.isTypeMismatch()) {
          continue;
        }
        if(!cmp.isLessThan()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }
   
    // else - find smallest greater than or equal to
    // TODO - is binary search used for (match_type==+1) ?
    for (int i = 0; i<lookupRange.length; i++) {
      CompareResult cmp = lookupComparer.compareTo(lookupRange[i]);
      if(cmp.isEqual()) {
        return i;
      }
      if(cmp.isGreaterThan()) {
        if(i<1) {
          throw new EvaluationException(ErrorEval.NA);
        }
        return i-1;
      }
    }

    throw new EvaluationException(ErrorEval.NA);
  }
View Full Code Here

  }

  private double evalArg(Eval arg, int srcRow, short srcCol) throws EvaluationException {
    ValueEval ve = singleOperandEvaluate(arg, srcRow, srcCol);
    if(ve instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval) ve);
    }
    if (ve instanceof NumericValueEval) {
      return ((NumericValueEval) ve).getNumberValue();
    }
    throw new EvaluationException(ErrorEval.VALUE_INVALID);
  }
View Full Code Here

     
      // check for errors first: size mismatch, value errors in x, value errors in y
     
      int nArrayItems = xops.length;
    if(nArrayItems != yops.length) {
        throw new EvaluationException(ErrorEval.NA);
      }
    for (int i = 0; i < xops.length; i++) {
      Eval eval = xops[i];
      if (eval instanceof ErrorEval) {
        throw new EvaluationException((ErrorEval) eval);
      }
    }
    for (int i = 0; i < yops.length; i++) {
      Eval eval = yops[i];
      if (eval instanceof ErrorEval) {
        throw new EvaluationException((ErrorEval) eval);
      }
    }
   
        double[] xResult = new double[nArrayItems];
        double[] yResult = new double[nArrayItems];
     
        int count = 0;
       
    for (int i=0, iSize=nArrayItems; i<iSize; i++) {
        Eval xEval = xops[i];
        Eval yEval = yops[i];
       
        if (isNumberEval(xEval) && isNumberEval(yEval)) {
          xResult[count] = getDoubleValue(xEval);
          yResult[count] = getDoubleValue(yEval);
            if (Double.isNaN(xResult[count]) || Double.isNaN(xResult[count])) {
                throw new EvaluationException(ErrorEval.NUM_ERROR);
            }
            count++;
        }
    }
       
View Full Code Here

    }
   
    private static double[][] getValues(Eval argX, Eval argY) throws EvaluationException {
     
      if (argX instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval) argX);
    }
      if (argY instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval) argY);
    }
     
        Eval[] xEvals;
    Eval[] yEvals;
    if (argX instanceof AreaEval) {
View Full Code Here

      result = performBinarySearch(vector, lookupComparer);
    } else {
      result = lookupIndexOfExactValue(lookupComparer, vector);
    }
    if(result < 0) {
      throw new EvaluationException(ErrorEval.NA);
    }
    return result;
  }
View Full Code Here

  public static LookupValueComparer createLookupComparer(ValueEval lookupValue) throws EvaluationException {
   
    if (lookupValue instanceof BlankEval) {
      // blank eval can never be found in a lookup array
      throw new EvaluationException(ErrorEval.NA);
    }
    if (lookupValue instanceof StringEval) {
      return new StringLookupComparer((StringEval) lookupValue);
    }
    if (lookupValue instanceof NumberEval) {
View Full Code Here

      return ((AreaEval) eval).offset(0, aeRange.getHeight()-1, 0, aeRange.getWidth()-1);
    }
    if (eval instanceof RefEval) {
      return ((RefEval)eval).offset(0, aeRange.getHeight()-1, 0, aeRange.getWidth()-1);
    }
    throw new EvaluationException(ErrorEval.VALUE_INVALID);
  }
View Full Code Here

      return (AreaEval) eval;
    }
    if (eval instanceof RefEval) {
      return ((RefEval)eval).offset(0, 0, 0, 0);
    }
    throw new EvaluationException(ErrorEval.VALUE_INVALID);
  }
View Full Code Here

          rowIx = pRowIx == -1 ? 0 : pRowIx;
          columnIx = pColumnIx;
        }
      }
      if (rowIx < -1 || columnIx < -1) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
    } else if (ae.isColumn()) {
      if (nArgs == 2) {
        rowIx = pRowIx;
        columnIx = 0;
      } else {
        rowIx = pRowIx;
        columnIx = pColumnIx == -1 ? 0 : pColumnIx;
      }
      if (rowIx < -1 || columnIx < -1) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
    } else {
      if (nArgs == 2) {
        // always an error with 2-D area refs
        if (pRowIx < -1) {
          throw new EvaluationException(ErrorEval.VALUE_INVALID);
        }
        throw new EvaluationException(ErrorEval.REF_INVALID);
      }
      // Normal case - area ref is 2-D, and both index args were provided
      rowIx = pRowIx;
      columnIx = pColumnIx;
    }
   
    int width = ae.getWidth();
    int height = ae.getHeight();
    // Slightly irregular logic for bounds checking errors
    if (rowIx >= height || columnIx >= width) {
      throw new EvaluationException(ErrorEval.REF_INVALID);
    }
    if (rowIx < 0 || columnIx < 0) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    return ae.getRelativeValue(rowIx, columnIx);
  }
View Full Code Here

TOP

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

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.