Beispiel #1
0
 /**
  * Dereferences a single value from any AreaEval or RefEval evaluation result. If the supplied
  * evaluationResult is just a plain value, it is returned as-is.
  *
  * @return a <tt>NumberEval</tt>, <tt>StringEval</tt>, <tt>BoolEval</tt>, <tt>BlankEval</tt> or
  *     <tt>ErrorEval</tt>. Never <code>null</code>.
  */
 private static ValueEval dereferenceValue(
     ValueEval evaluationResult, int srcRowNum, int srcColNum) {
   if (evaluationResult instanceof RefEval) {
     RefEval rv = (RefEval) evaluationResult;
     return rv.getInnerValueEval();
   }
   if (evaluationResult instanceof AreaEval) {
     AreaEval ae = (AreaEval) evaluationResult;
     if (ae.isRow()) {
       if (ae.isColumn()) {
         return ae.getRelativeValue(0, 0);
       }
       return ae.getValueAt(ae.getFirstRow(), srcColNum);
     }
     if (ae.isColumn()) {
       return ae.getValueAt(srcRowNum, ae.getFirstColumn());
     }
     return ErrorEval.VALUE_INVALID;
   }
   return evaluationResult;
 }
  private static double getScalarValue(ValueEval arg) throws EvaluationException {

    ValueEval eval;
    if (arg instanceof RefEval) {
      RefEval re = (RefEval) arg;
      eval = re.getInnerValueEval();
    } else {
      eval = arg;
    }

    if (eval == null) {
      throw new RuntimeException("parameter may not be null");
    }
    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);
  }