Package org.apache.poi.ss.formula.eval

Examples of org.apache.poi.ss.formula.eval.EvaluationException


  public static double calculate(double pStartDateVal, double pEndDateVal, int basis) throws EvaluationException {

    if (basis < 0 || basis >= 5) {
      // if basis is invalid the result is #NUM!
      throw new EvaluationException(ErrorEval.NUM_ERROR);
    }

    // common logic for all bases

    // truncate day values
View Full Code Here


        }
        if (arg instanceof RefEval) {
            RefEval refEval = (RefEval)arg;
            if (refEval.getNumberOfSheets() > 1) {
                // Multi-Sheet references are not supported
                throw new EvaluationException(ErrorEval.VALUE_INVALID);
            }
           
            ValueEval innerValueEval = refEval.getInnerValueEval(refEval.getFirstSheetIndex());
            if(innerValueEval instanceof NumberEval) {
                return ((NumberEval) innerValueEval).getNumberValue();
            }
            if(innerValueEval instanceof BlankEval) {
                return 0;
            }
        }
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
View Full Code Here

  @Override
  public double eval(ValueEval[] args, int srcCellRow, int srcCellCol) throws EvaluationException {
      
    if(args.length != 4)
            throw new EvaluationException(ErrorEval.VALUE_INVALID);

    double result;

    ValueEval v1 = OperandResolver.getSingleValue(args[0], srcCellRow, srcCellCol);
    ValueEval v2 = OperandResolver.getSingleValue(args[1], srcCellRow, srcCellCol);
View Full Code Here

      return new SingleValueVector(re.getInnerValueEval());
    }
    if (eval instanceof TwoDEval) {
      ValueVector result = LookupUtils.createVector((TwoDEval)eval);
      if (result == null) {
        throw new EvaluationException(ErrorEval.NA);
      }
      return result;
    }

    // Error handling for lookup_range arg is also unusual
    if(eval instanceof NumericValueEval) {
      throw new EvaluationException(ErrorEval.NA);
    }
    if (eval instanceof StringEval) {
      StringEval se = (StringEval) eval;
      Double d = OperandResolver.parseDouble(se.getStringValue());
      if(d == null) {
        // plain string
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      // else looks like a number
      throw new EvaluationException(ErrorEval.NA);
    }
    throw new RuntimeException("Unexpected eval type (" + eval.getClass().getName() + ")");
  }
View Full Code Here

  private static double evaluateMatchTypeArg(ValueEval arg, int srcCellRow, int srcCellCol)
      throws EvaluationException {
    ValueEval 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 < size; i++) {
        if(lookupComparer.compareTo(lookupRange.getItem(i)).isEqual()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }

    if(findLargestLessThanOrEqual) {
      // Note - backward iteration
      for (int i = size - 1; i>=0;  i--) {
        CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(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<size; i++) {
      CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(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

        }
        double beta1 = xybar / xxbar;
        double beta0 = ybar - beta1 * xbar;
   
    if (firstXerr != null) {
      throw new EvaluationException(firstXerr);
    }
    if (firstYerr != null) {
      throw new EvaluationException(firstYerr);
    }
    if (!accumlatedSome) {
      throw new EvaluationException(ErrorEval.DIV_ZERO);
    }
   
    if(function == FUNCTION.INTERCEPT) {
      return beta0;
    } else {
View Full Code Here

    }
  }

  private static ValueVector createValueVector(ValueEval arg) throws EvaluationException {
    if (arg instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval) arg);
    }
    if (arg instanceof TwoDEval) {
      return new AreaValueArray((TwoDEval) arg);
    }
    if (arg instanceof RefEval) {
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

        return;
      }
      String s = ((StringValueEval) ve).getStringValue();
      Double d = OperandResolver.parseDouble(s);
      if(d == null) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      temp.add(d.doubleValue());
      return;
    }
    if (ve instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval) ve);
    }
    if (ve == BlankEval.instance) {
      if (_isBlankCounted) {
        temp.add(0.0);
      }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.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.