/** * Applies some conversion rules if the supplied value is not already a number. * Note - <tt>BlankEval</tt> is converted to {@link NumberEval#ZERO}. * @param ev must be a {@link NumberEval}, {@link StringEval}, {@link BoolEval} or * {@link BlankEval} * @return actual, parsed or interpreted double value (respectively). * @throws EvaluationException(#VALUE!) only if a StringEval is supplied and cannot be parsed * as a double (See <tt>parseDouble()</tt> for allowable formats). * @throws RuntimeException if the supplied parameter is not {@link NumberEval}, * {@link StringEval}, {@link BoolEval} or {@link BlankEval} */ public static double coerceValueToDouble(ValueEval ev) throws EvaluationException { if (ev == BlankEval.instance) { return 0.0; } if (ev instanceof NumericValueEval) { // this also handles booleans return ((NumericValueEval)ev).getNumberValue(); } if (ev instanceof StringEval) { Double dd = parseDouble(((StringEval) ev).getStringValue()); if (dd == null) { throw EvaluationException.invalidValue(); } return dd.doubleValue(); } throw new RuntimeException("Unexpected arg eval type (" + ev.getClass().getName() + ")"); }
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg1, ValueEval arg2) { ValueEval veText1; try { veText1 = OperandResolver.getSingleValue(arg1, srcRowIndex, srcColumnIndex); } catch (EvaluationException e) { return e.getErrorEval(); } String strText1 = OperandResolver.coerceValueToString(veText1); Double number1 = OperandResolver.parseDouble(strText1); if (number1 == null) { return ErrorEval.VALUE_INVALID; } ValueEval veText2; try { veText2 = OperandResolver.getSingleValue(arg2, srcRowIndex, srcColumnIndex); } catch (EvaluationException e) { return e.getErrorEval(); } String strText2 = OperandResolver.coerceValueToString(veText2); Double number2 = OperandResolver.parseDouble(strText2); if (number2 == null) { return ErrorEval.VALUE_INVALID; } int result = new BigDecimal(number1.doubleValue()).compareTo(new BigDecimal(number2.doubleValue())); return result == 0 ? ONE : ZERO; }
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() + ")"); }
Double number = OperandResolver.parseDouble(strText1); Double placesNumberDouble = OperandResolver.parseDouble(placesStr);
private static double evaluateDateArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException { ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol); if (ve instanceof StringEval) { String strVal = ((StringEval) ve).getStringValue(); Double dVal = OperandResolver.parseDouble(strVal); if (dVal != null) { return dVal.doubleValue(); } Calendar date = DateParser.parseDate(strVal); return DateUtil.getExcelDate(date, false); } return OperandResolver.coerceValueToDouble(ve); }
Double number1 = OperandResolver.parseDouble(strText1); Double placesNumberDouble = OperandResolver.parseDouble(placesStr);
/** * Evaluate a generic {@link ValueEval} argument to a double value that represents a date in POI. * * @param arg {@link ValueEval} an argument. * @param srcCellRow number cell row. * @param srcCellCol number cell column. * @return a double representing a date in POI. * @throws EvaluationException exception upon argument evaluation. */ public double evaluateDateArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException { ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol); if (ve instanceof StringEval) { String strVal = ((StringEval) ve).getStringValue(); Double dVal = OperandResolver.parseDouble(strVal); if (dVal != null) { return dVal.doubleValue(); } Calendar date = DateParser.parseDate(strVal); return DateUtil.getExcelDate(date, false); } return OperandResolver.coerceValueToDouble(ve); }
Double val = OperandResolver.parseDouble(se.getStringValue()); if(val == null) {
/** * When the second argument is a string, many things are possible */ private static I_MatchPredicate createGeneralMatchPredicate(StringEval stringEval) { String value = stringEval.getStringValue(); CmpOp operator = CmpOp.getOperator(value); value = value.substring(operator.getLength()); Boolean booleanVal = parseBoolean(value); if(booleanVal != null) { return new BooleanMatcher(booleanVal.booleanValue(), operator); } Double doubleVal = OperandResolver.parseDouble(value); if(doubleVal != null) { return new NumberMatcher(doubleVal.doubleValue(), operator); } ErrorEval ee = parseError(value); if (ee != null) { return new ErrorMatcher(ee.getErrorCode(), operator); } //else - just a plain string with no interpretation. return new StringMatcher(value, operator); } private static ErrorEval parseError(String value) {
Double d = OperandResolver.parseDouble(s); if(d == null) { throw new EvaluationException(ErrorEval.VALUE_INVALID);
StringEval se = (StringEval) veRowColIndexArg; String strVal = se.getStringValue(); Double dVal = OperandResolver.parseDouble(strVal); if(dVal == null) {
Double d = OperandResolver.parseDouble(se.getStringValue()); if(d == null) {
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() + ")"); }
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() + ")"); }
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() + ")"); }
private static double evaluateDateArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException { ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol); if (ve instanceof StringEval) { String strVal = ((StringEval) ve).getStringValue(); Double dVal = OperandResolver.parseDouble(strVal); if (dVal != null) { return dVal.doubleValue(); } Calendar date = DateParser.parseDate(strVal); return DateUtil.getExcelDate(date, false); } return OperandResolver.coerceValueToDouble(ve); }
private static double evaluateDateArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException { ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol); if (ve instanceof StringEval) { String strVal = ((StringEval) ve).getStringValue(); Double dVal = OperandResolver.parseDouble(strVal); if (dVal != null) { return dVal.doubleValue(); } Calendar date = DateParser.parseDate(strVal); return DateUtil.getExcelDate(date, false); } return OperandResolver.coerceValueToDouble(ve); }
private static double evaluateDateArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException { ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol); if (ve instanceof StringEval) { String strVal = ((StringEval) ve).getStringValue(); Double dVal = OperandResolver.parseDouble(strVal); if (dVal != null) { return dVal.doubleValue(); } Calendar date = DateParser.parseDate(strVal); return DateUtil.getExcelDate(date, false); } return OperandResolver.coerceValueToDouble(ve); }
/** * Evaluate a generic {@link ValueEval} argument to a double value that represents a date in POI. * * @param arg {@link ValueEval} an argument. * @param srcCellRow number cell row. * @param srcCellCol number cell column. * @return a double representing a date in POI. * @throws EvaluationException exception upon argument evaluation. */ public double evaluateDateArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException { ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol); if (ve instanceof StringEval) { String strVal = ((StringEval) ve).getStringValue(); Double dVal = OperandResolver.parseDouble(strVal); if (dVal != null) { return dVal.doubleValue(); } Calendar date = DateParser.parseDate(strVal); return DateUtil.getExcelDate(date, false); } return OperandResolver.coerceValueToDouble(ve); }
/** * Evaluate a generic {@link ValueEval} argument to a double value that represents a date in POI. * * @param arg {@link ValueEval} an argument. * @param srcCellRow number cell row. * @param srcCellCol number cell column. * @return a double representing a date in POI. * @throws EvaluationException exception upon argument evaluation. */ public double evaluateDateArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException { ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol); if (ve instanceof StringEval) { String strVal = ((StringEval) ve).getStringValue(); Double dVal = OperandResolver.parseDouble(strVal); if (dVal != null) { return dVal.doubleValue(); } Calendar date = DateParser.parseDate(strVal); return DateUtil.getExcelDate(date, false); } return OperandResolver.coerceValueToDouble(ve); }