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

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


      NumberEval ne = (NumberEval) ve;
      temp.add(ne.getNumberValue());
      return;
    }
    if (ve instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval) ve);
    }
    if (ve instanceof StringEval) {
      if (isViaReference) {
        // ignore all ref strings
        return;
      }
      String s = ((StringEval) ve).getStringValue();
      Double d = OperandResolver.parseDouble(s);
      if(d == null) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      temp.add(d.doubleValue());
      return;
    }
    if (ve instanceof BoolEval) {
View Full Code Here


      return new SingleValueVector(re.getInnerValueEval());
    }
    if (eval instanceof AreaEval) {
      ValueVector result = LookupUtils.createVector((AreaEval)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

    }
    if (eval instanceof AreaEval) {
      AreaEval ae = (AreaEval) eval;
      // an area ref can work as a scalar value if it is 1x1
      if(!ae.isColumn() || !ae.isRow()) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      eval = ae.getRelativeValue(0, 0);
    }

    return getProductTerm(eval, true);
View Full Code Here

    int width = areaEval.getWidth();
    for (int rrIx=0; rrIx<height; rrIx++) {
      for (int rcIx=0; rcIx<width; rcIx++) {
        ValueEval ve = areaEval.getRelativeValue(rrIx, rcIx);
        if (ve instanceof ErrorEval) {
          throw new EvaluationException((ErrorEval) ve);
        }
      }
    }
  }
View Full Code Here

    if(ve instanceof BlankEval || ve == null) {
      // TODO - shouldn't BlankEval.INSTANCE be used always instead of null?
      // null seems to occur when the blank cell is part of an area ref (but not reliably)
      if(isScalarProduct) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      return 0;
    }

    if(ve instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval)ve);
    }
    if(ve instanceof StringEval) {
      if(isScalarProduct) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      // Note for area SUMPRODUCTs, string values are interpreted as zero
      // even if they would parse as valid numeric values
      return 0;
    }
View Full Code Here

   *
   * @param v
   */
  public static double evaluate(double[] v) throws EvaluationException {
    if (v.length < 2) {
      throw new EvaluationException(ErrorEval.NA);
    }

    // very naive impl, may need to be optimized
    int[] counts = new int[v.length];
    Arrays.fill(counts, 1);
    for (int i = 0, iSize = v.length; i < iSize; i++) {
      for (int j = i + 1, jSize = v.length; j < jSize; j++) {
        if (v[i] == v[j])
          counts[i]++;
      }
    }
    double maxv = 0;
    int maxc = 0;
    for (int i = 0, iSize = counts.length; i < iSize; i++) {
      if (counts[i] > maxc) {
        maxv = v[i];
        maxc = counts[i];
      }
    }
    if (maxc > 1) {
      return maxv;
    }
    throw new EvaluationException(ErrorEval.NA);

  }
View Full Code Here

  }

  private static void collectValue(ValueEval arg, List<Double> temp, boolean mustBeNumber)
      throws EvaluationException {
    if (arg instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval) arg);
    }
    if (arg == BlankEval.instance || arg instanceof BoolEval || arg instanceof StringEval) {
      if (mustBeNumber) {
        throw EvaluationException.invalidValue();
      }
View Full Code Here

   * evaluates to an error.
   */
  private static double evaluate(int hours, int minutes, int seconds) throws EvaluationException {

    if (hours > 32767 || minutes > 32767 || seconds > 32767) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    int totalSeconds = hours * SECONDS_PER_HOUR + minutes * SECONDS_PER_MINUTE + seconds;

    if (totalSeconds < 0) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    return (totalSeconds % SECONDS_PER_DAY) / (double)SECONDS_PER_DAY;
  }
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.