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

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


  /**
   * @param month 1-based
   */
  private static Calendar makeDate(int year, int month, int day) throws EvaluationException {
    if (month < 1 || month > 12) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    Calendar cal = new GregorianCalendar(year, month-1, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    if (day <1 || day>cal.getActualMaximum(Calendar.DAY_OF_MONTH)) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    cal.set(Calendar.DAY_OF_MONTH, day);
    return cal;
  }
View Full Code Here


        atleastOneNonBlank = true;
      }
    }

    if (!atleastOneNonBlank) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    return result;
  }
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

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

  /**
   * @throws EvaluationException (#NUM!) if <tt>result</tt> is <tt>NaN</> or <tt>Infinity</tt>
   */
  static final void checkValue(double result) throws EvaluationException {
    if (Double.isNaN(result) || Double.isInfinite(result)) {
      throw new EvaluationException(ErrorEval.NUM_ERROR);
    }
  }
View Full Code Here

      }
      return new NumberEval(result);
    }
    protected final double eval(ValueEval[] args, int srcCellRow, int srcCellCol) throws EvaluationException {
      if (args.length != 1) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      double d = singleOperandEvaluate(args[0], srcCellRow, srcCellCol);
      return evaluate(d);
    }
View Full Code Here

        atleastOneNonBlank = true;
      }
    }

    if (!atleastOneNonBlank) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    return result;
  }
View Full Code Here

      LinearOffsetRange orRow, LinearOffsetRange orCol) throws EvaluationException {
    LinearOffsetRange absRows = orRow.normaliseAndTranslate(baseRef.getFirstRowIndex());
    LinearOffsetRange absCols = orCol.normaliseAndTranslate(baseRef.getFirstColumnIndex());

    if(absRows.isOutOfBounds(0, LAST_VALID_ROW_INDEX)) {
      throw new EvaluationException(ErrorEval.REF_INVALID);
    }
    if(absCols.isOutOfBounds(0, LAST_VALID_COLUMN_INDEX)) {
      throw new EvaluationException(ErrorEval.REF_INVALID);
    }
    return baseRef.offset(orRow.getFirstIndex(), orRow.getLastIndex(), orCol.getFirstIndex(), orCol.getLastIndex());
  }
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.