示例#1
0
    public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
      double dn;
      try {
        ValueEval ve1 = OperandResolver.getSingleValue(arg1, srcRowIndex, srcColumnIndex);
        dn = OperandResolver.coerceValueToDouble(ve1);
      } catch (EvaluationException e1) {
        // all errors in the second arg translate to #VALUE!
        return ErrorEval.VALUE_INVALID;
      }
      // weird Excel behaviour on second arg
      if (dn < 1.0) {
        // values between 0.0 and 1.0 result in #NUM!
        return ErrorEval.NUM_ERROR;
      }
      // all other values are rounded up to the next integer
      int k = (int) Math.ceil(dn);

      double result;
      try {
        double[] ds = ValueCollector.collectValues(arg0);
        if (k > ds.length) {
          return ErrorEval.NUM_ERROR;
        }
        result = _isLarge ? StatsLib.kthLargest(ds, k) : StatsLib.kthSmallest(ds, k);
        NumericFunction.checkValue(result);
      } catch (EvaluationException e) {
        return e.getErrorEval();
      }

      return new NumberEval(result);
    }
  public ValueEval evaluate(ValueEval[] args, int srcCellRow, int srcCellCol) {

    int maxN = args.length;

    if (maxN < 1) {
      return ErrorEval.VALUE_INVALID;
    }
    ValueEval firstArg = args[0];
    try {
      if (firstArg instanceof NumericValueEval) {
        return evaluateSingleProduct(args);
      }
      if (firstArg instanceof RefEval) {
        return evaluateSingleProduct(args);
      }
      if (firstArg instanceof TwoDEval) {
        TwoDEval ae = (TwoDEval) firstArg;
        if (ae.isRow() && ae.isColumn()) {
          return evaluateSingleProduct(args);
        }
        return evaluateAreaSumProduct(args);
      }
    } catch (EvaluationException e) {
      return e.getErrorEval();
    }
    throw new RuntimeException(
        "Invalid arg type for SUMPRODUCT: (" + firstArg.getClass().getName() + ")");
  }
示例#3
0
文件: Errortype.java 项目: srnsw/xena
  public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) {

    try {
      OperandResolver.getSingleValue(args[0], srcCellRow, srcCellCol);
      return ErrorEval.NA;
    } catch (EvaluationException e) {
      int result = translateErrorCodeToErrorTypeValue(e.getErrorEval().getErrorCode());
      return new NumberEval(result);
    }
  }
  public ValueEval evaluate(
      int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2) {
    String result;
    try {
      String oldStr = TextFunction.evaluateStringArg(arg0, srcRowIndex, srcColumnIndex);
      String searchStr = TextFunction.evaluateStringArg(arg1, srcRowIndex, srcColumnIndex);
      String newStr = TextFunction.evaluateStringArg(arg2, srcRowIndex, srcColumnIndex);

      result = replaceAllOccurrences(oldStr, searchStr, newStr);
    } catch (EvaluationException e) {
      return e.getErrorEval();
    }
    return new StringEval(result);
  }
  public ValueEval evaluate(
      int srcRowIndex,
      int srcColumnIndex,
      ValueEval arg0,
      ValueEval arg1,
      ValueEval arg2,
      ValueEval arg3) {
    String result;
    try {
      String oldStr = TextFunction.evaluateStringArg(arg0, srcRowIndex, srcColumnIndex);
      String searchStr = TextFunction.evaluateStringArg(arg1, srcRowIndex, srcColumnIndex);
      String newStr = TextFunction.evaluateStringArg(arg2, srcRowIndex, srcColumnIndex);

      int instanceNumber = TextFunction.evaluateIntArg(arg3, srcRowIndex, srcColumnIndex);
      if (instanceNumber < 1) {
        return ErrorEval.VALUE_INVALID;
      }
      result = replaceOneOccurrence(oldStr, searchStr, newStr, instanceNumber);
    } catch (EvaluationException e) {
      return e.getErrorEval();
    }
    return new StringEval(result);
  }