/** * uses the relevant flags to decode the supplied RefVal * @param eval */ private ValueEval XlateRefEval(RefEval reval) { ValueEval eval = reval.InnerValueEval; // most common case - least worries :) if (eval is NumberEval) { return(eval); } if (eval is BoolEval) { return(((flags & REF_BOOL_IS_PARSED) > 0) ? (ValueEval)eval : BlankEval.instance); } if (eval is StringEval) { return(XlateRefStringEval((StringEval)eval)); } if (eval is ErrorEval) { return(eval); } if (eval is BlankEval) { return(XlateBlankEval(REF_BLANK_IS_PARSED)); } throw new Exception("Invalid ValueEval type passed for conversion: (" + eval.GetType().Name + ")"); }
/** * Determines a <c>double</c> value for the specified <c>ValueEval</c>. * @param IsScalarProduct <c>false</c> for SUMPRODUCTs over area refs. * @throws EvalEx if <c>ve</c> represents an error value. * <p/> * Note - string values and empty cells are interpreted differently depending on * <c>isScalarProduct</c>. For scalar products, if any term Is blank or a string, the * error (#VALUE!) Is raised. For area (sum)products, if any term Is blank or a string, the * result Is zero. */ private static double GetProductTerm(ValueEval ve, bool IsScalarProduct) { if (ve is 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 is ErrorEval) { throw new EvaluationException((ErrorEval)ve); } if (ve is 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); } if (ve is NumericValueEval) { NumericValueEval nve = (NumericValueEval)ve; return(nve.NumberValue); } throw new RuntimeException("Unexpected value eval class (" + ve.GetType().Name + ")"); }
/** * Creates a criteria predicate object for the supplied criteria arg * @return <code>null</code> if the arg evaluates to blank. */ public static IMatchPredicate CreateCriteriaPredicate(ValueEval arg, int srcRowIndex, int srcColumnIndex) { ValueEval evaluatedCriteriaArg = EvaluateCriteriaArg(arg, srcRowIndex, srcColumnIndex); if (evaluatedCriteriaArg is NumberEval) { return(new NumberMatcher(((NumberEval)evaluatedCriteriaArg).NumberValue, CmpOp.OP_NONE)); } if (evaluatedCriteriaArg is BoolEval) { return(new BooleanMatcher(((BoolEval)evaluatedCriteriaArg).BooleanValue, CmpOp.OP_NONE)); } if (evaluatedCriteriaArg is StringEval) { return(CreateGeneralMatchPredicate((StringEval)evaluatedCriteriaArg)); } if (evaluatedCriteriaArg is ErrorEval) { return(new ErrorMatcher(((ErrorEval)evaluatedCriteriaArg).ErrorCode, CmpOp.OP_NONE)); } if (evaluatedCriteriaArg == BlankEval.instance) { return(null); } throw new Exception("Unexpected type for criteria (" + evaluatedCriteriaArg.GetType().Name + ")"); }
private void ConfirmLen(ValueEval text, int expected) { ValueEval result = invokeLen(text); Assert.AreEqual(typeof(NumberEval), result.GetType()); Assert.AreEqual(expected, ((NumberEval)result).NumberValue, 0); }
private static double EvaluateMatchTypeArg(ValueEval arg, int srcCellRow, int srcCellCol) { ValueEval match_type = OperandResolver.GetSingleValue(arg, srcCellRow, srcCellCol); if (match_type is ErrorEval) { throw new EvaluationException((ErrorEval)match_type); } if (match_type is NumericValueEval) { NumericValueEval ne = (NumericValueEval)match_type; return(ne.NumberValue); } if (match_type is StringEval) { StringEval se = (StringEval)match_type; double d = OperandResolver.ParseDouble(se.StringValue); if (double.IsNaN(d)) { // plain string throw new EvaluationException(ErrorEval.VALUE_INVALID); } // if the string Parses as a number, it Is OK return(d); } throw new Exception("Unexpected match_type type (" + match_type.GetType().Name + ")"); }
private static void ConfirmValueError(string msg, string real_num, string i_num, string suffix, ErrorEval numError) { ValueEval result = invokeValue(real_num, i_num, suffix); Assert.AreEqual(typeof(ErrorEval), result.GetType()); Assert.AreEqual(numError, result, msg); }
/** * Returns a CellValue wrapper around the supplied ValueEval instance. */ private CellValue EvaluateFormulaCellValue(ICell cell) { if (!(cell is XSSFCell)) { throw new ArgumentException("Unexpected type of cell: " + cell.GetType() + "." + " Only XSSFCells can be Evaluated."); } ValueEval eval = _bookEvaluator.Evaluate(new XSSFEvaluationCell((XSSFCell)cell)); if (eval is NumberEval) { NumberEval ne = (NumberEval)eval; return(new CellValue(ne.NumberValue)); } if (eval is BoolEval) { BoolEval be = (BoolEval)eval; return(CellValue.ValueOf(be.BooleanValue)); } if (eval is StringEval) { StringEval ne = (StringEval)eval; return(new CellValue(ne.StringValue)); } if (eval is ErrorEval) { return(CellValue.GetError(((ErrorEval)eval).ErrorCode)); } throw new Exception("Unexpected eval class (" + eval.GetType().Name + ")"); }
private bool AreValuesEqual(ValueEval a, ValueEval b) { if (a == null) { return(false); } Type cls = a.GetType(); if (cls != b.GetType()) { // value type is changing return(false); } if (a == BlankEval.instance) { return(b == a); } if (cls == typeof(NumberEval)) { return(((NumberEval)a).NumberValue == ((NumberEval)b).NumberValue); } if (cls == typeof(StringEval)) { return(((StringEval)a).StringValue.Equals(((StringEval)b).StringValue)); } if (cls == typeof(BoolEval)) { return(((BoolEval)a).BooleanValue == ((BoolEval)b).BooleanValue); } if (cls == typeof(ErrorEval)) { return(((ErrorEval)a).ErrorCode == ((ErrorEval)b).ErrorCode); } throw new InvalidOperationException("Unexpected value class (" + cls.Name + ")"); }
private static void ConfirmEvaluate(MySheet ms, String cellRefText, double expectedValue) { ValueEval v = ms.EvaluateCell(cellRefText); Assert.AreEqual(typeof(NumberEval), v.GetType()); Assert.AreEqual(expectedValue, ((NumberEval)v).NumberValue, 0.0); }
private static void ConfirmValueError(String strText) { ValueEval result = InvokeValue(strText); Assert.AreEqual(typeof(ErrorEval), result.GetType()); Assert.AreEqual(ErrorEval.VALUE_INVALID, result); }
private void ConfirmTrim(ValueEval text, string expected) { ValueEval result = invokeTrim(text); Assert.AreEqual(typeof(StringEval), result.GetType()); Assert.AreEqual(expected, ((StringEval)result).StringValue); }
private static void ConfirmValue(String strText, double expected) { ValueEval result = InvokeValue(strText); Assert.AreEqual(typeof(NumberEval), result.GetType()); Assert.AreEqual(expected, ((NumberEval)result).NumberValue, 0.0); }
private static void ConfirmValueError(string number1, string number2) { ValueEval result = invokeValue(number1, number2); Assert.AreEqual(typeof(ErrorEval), result.GetType()); Assert.AreEqual(ErrorEval.VALUE_INVALID, result); }
private void Confirm(Function function, ValueEval xArray, ValueEval yArray, double expected) { ValueEval result = invoke(function, xArray, yArray); Assert.AreEqual(typeof(NumberEval), result.GetType()); Assert.AreEqual(expected, ((NumberEval)result).NumberValue, 0); }
private static void ConfirmValueError(String msg, String number1, ErrorEval numError) { ValueEval result = invokeValue(number1); Assert.AreEqual(typeof(ErrorEval), result.GetType()); Assert.AreEqual(numError, result, msg); }
private void ConfirmAverage(ValueEval[] args, double expected) { ValueEval result = InvokeAverage(args); Assert.AreEqual(typeof(NumberEval), result.GetType()); Assert.AreEqual(expected, ((NumberEval)result).NumberValue, 0); }
private static void ConfirmValue(string msg, string real_num, string i_num, string suffix, string expected) { ValueEval result = invokeValue(real_num, i_num, suffix); Assert.AreEqual(typeof(StringEval), result.GetType()); Assert.AreEqual(expected, ((StringEval)result).StringValue, msg); }
private void ConfirmAverage(ValueEval[] args, ErrorEval expectedError) { ValueEval result = InvokeAverage(args); Assert.AreEqual(typeof(ErrorEval), result.GetType()); Assert.AreEqual(expectedError.ErrorCode, ((ErrorEval)result).ErrorCode); }
private CellValue EvaluateFormulaCellValue(ICell cell) { if (!(cell is XSSFCell)) { throw new ArgumentException("Unexpected type of cell: " + (object)cell.GetType() + ". Only XSSFCells can be Evaluated."); } ValueEval valueEval = this._bookEvaluator.Evaluate((IEvaluationCell) new XSSFEvaluationCell(cell)); if (valueEval is NumberEval) { return(new CellValue(((NumberEval)valueEval).NumberValue)); } if (valueEval is BoolEval) { return(CellValue.ValueOf(((BoolEval)valueEval).BooleanValue)); } if (valueEval is StringEval) { return(new CellValue(((StringEval)valueEval).StringValue)); } if (valueEval is ErrorEval) { return(CellValue.GetError(((ErrorEval)valueEval).ErrorCode)); } throw new Exception("Unexpected eval class (" + valueEval.GetType().Name + ")"); }
private static void ConfirmValue(string msg, string numerator, string denominator, string expected) { ValueEval result = invokeValue(numerator, denominator); Assert.AreEqual(typeof(NumberEval), result.GetType()); Assert.AreEqual(expected, ((NumberEval)result).StringValue, msg); }
private static bool AreValuesEqual(ValueEval a, ValueEval b) { if (a == null) { return false; } Type cls = a.GetType(); if (cls != b.GetType()) { // value type is changing return false; } if (a == BlankEval.instance) { return b == a; } if (cls == typeof(NumberEval)) { return ((NumberEval)a).NumberValue == ((NumberEval)b).NumberValue; } if (cls == typeof(StringEval)) { return ((StringEval)a).StringValue.Equals(((StringEval)b).StringValue); } if (cls == typeof(BoolEval)) { return ((BoolEval)a).BooleanValue == ((BoolEval)b).BooleanValue; } if (cls == typeof(ErrorEval)) { return ((ErrorEval)a).ErrorCode == ((ErrorEval)b).ErrorCode; } throw new InvalidOperationException("Unexpected value class (" + cls.Name + ")"); }
private static void ConfirmValueError(string msg, string numerator, string denominator, ErrorEval numError) { ValueEval result = invokeValue(numerator, denominator); Assert.AreEqual(typeof(ErrorEval), result.GetType()); Assert.AreEqual(numError, result, msg); }
private void ConfirmLen(ValueEval text, ErrorEval expectedError) { ValueEval result = invokeLen(text); Assert.AreEqual(typeof(ErrorEval), result.GetType()); Assert.AreEqual(expectedError.ErrorCode, ((ErrorEval)result).ErrorCode); }
private void ConfirmMid(ValueEval text, ValueEval startPos, ValueEval numChars, string expected) { ValueEval result = invokeMid(text, startPos, numChars); Assert.AreEqual(typeof(StringEval), result.GetType()); Assert.AreEqual(expected, ((StringEval)result).StringValue); }
public void SetValue(ValueEval value) { Type cls = value.GetType(); if (cls == typeof(NumberEval)) { _cellType = CellType.NUMERIC; _numberValue = ((NumberEval)value).NumberValue; return; } if (cls == typeof(StringEval)) { _cellType = CellType.STRING; _stringValue = ((StringEval)value).StringValue; return; } if (cls == typeof(BoolEval)) { _cellType = CellType.BOOLEAN; _boolValue = ((BoolEval)value).BooleanValue; return; } if (cls == typeof(ErrorEval)) { _cellType = CellType.ERROR; _errorValue = ((ErrorEval)value).ErrorCode; return; } if (cls == typeof(BlankEval)) { _cellType = CellType.BLANK; return; } throw new ArgumentException("Unexpected value class (" + cls.Name + ")"); }
private void ConfirmMid(ValueEval text, ValueEval startPos, ValueEval numChars, ErrorEval expectedError) { ValueEval result = invokeMid(text, startPos, numChars); Assert.AreEqual(typeof(ErrorEval), result.GetType()); Assert.AreEqual(expectedError.ErrorCode, ((ErrorEval)result).ErrorCode); }
private void ConfirmPercentile(ValueEval percentile, ValueEval[] args, ErrorEval expectedError) { ValueEval result = invokePercentile(args, percentile); Assert.AreEqual(typeof(ErrorEval), result.GetType()); Assert.AreEqual(expectedError.ErrorCode, ((ErrorEval)result).ErrorCode); }
private static double EvaluateDoubleArg(ValueEval eval, int srcCellRow, int srcCellCol) { ValueEval ve = OperandResolver.GetSingleValue(eval, srcCellRow, srcCellCol); if (ve is NumericValueEval) { return(((NumericValueEval)ve).NumberValue); } if (ve is StringEval) { StringEval se = (StringEval)ve; double d = OperandResolver.ParseDouble(se.StringValue); if (double.IsNaN(d)) { throw new EvalEx(ErrorEval.VALUE_INVALID); } return(d); } if (ve is BoolEval) { // in the context of OFFSet, bools resolve to 0 and 1. if (((BoolEval)ve).BooleanValue) { return(1); } return(0); } throw new Exception("Unexpected eval type (" + ve.GetType().Name + ")"); }
public void SetValue(ValueEval value) { Type cls = value.GetType(); if (cls == typeof(NumberEval)) { _cellType = CellType.NUMERIC; _numberValue = ((NumberEval)value).NumberValue; return; } if (cls == typeof(StringEval)) { _cellType = CellType.STRING; _stringValue = ((StringEval)value).StringValue; return; } if (cls == typeof(BoolEval)) { _cellType = CellType.BOOLEAN; _boolValue = ((BoolEval)value).BooleanValue; return; } if (cls == typeof(ErrorEval)) { _cellType = CellType.ERROR; _errorValue = ((ErrorEval)value).ErrorCode; return; } if (cls == typeof(BlankEval)) { _cellType = CellType.BLANK; return; } throw new ArgumentException("Unexpected value class (" + cls.Name + ")"); }
/** * Returns a CellValue wrapper around the supplied ValueEval instance. * @param eval */ private CellValue EvaluateFormulaCellValue(ICell cell) { ValueEval eval = _bookEvaluator.Evaluate(new HSSFEvaluationCell((HSSFCell)cell)); if (eval is NumberEval) { NumberEval ne = (NumberEval)eval; return(new CellValue(ne.NumberValue)); } if (eval is BoolEval) { BoolEval be = (BoolEval)eval; return(CellValue.ValueOf(be.BooleanValue)); } if (eval is StringEval) { StringEval ne = (StringEval)eval; return(new CellValue(ne.StringValue)); } if (eval is ErrorEval) { return(CellValue.GetError(((ErrorEval)eval).ErrorCode)); } throw new InvalidOperationException("Unexpected eval class (" + eval.GetType().Name + ")"); }
private static void ConfirmValue(String msg, String number1, String expected) { ValueEval result = invokeValue(number1); Assert.AreEqual(typeof(NumberEval), result.GetType()); Assert.AreEqual(expected, ((NumberEval)result).StringValue, msg); }
private void ConfirmError(Function function, ValueEval xArray, ValueEval yArray, ErrorEval expectedError) { ValueEval result = invoke(function, xArray, yArray); Assert.AreEqual(typeof(ErrorEval), result.GetType()); Assert.AreEqual(expectedError.ErrorCode, ((ErrorEval)result).ErrorCode); }
private Object GetText(ValueEval ve) { if (ve is StringValueEval) { StringValueEval sve = (StringValueEval)ve; return sve.StringValue; } if (ve == BlankEval.instance) { return ""; } throw new InvalidOperationException("Unexpected value type (" + ve.GetType().Name + ")"); }
private static AreaEval EvaluateRef(ValueEval arg) { if (arg is AreaEval) { return (AreaEval)arg; } if (arg is RefEval) { return ((RefEval)arg).Offset(0, 0, 0, 0); } if (arg is ErrorEval) { throw new EvaluationException((ErrorEval)arg); } throw new ArgumentException("Unexpected ref arg class (" + arg.GetType().Name + ")"); }
public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) { double result; if (arg0 is RefEval) { result = CountUtils.CountMatchingCell((RefEval)arg0, predicate); } else if (arg0 is TwoDEval) { result = CountUtils.CountMatchingCellsInArea((TwoDEval)arg0, predicate); } else { throw new ArgumentException("Bad range arg type (" + arg0.GetType().Name + ")"); } return new NumberEval(result); }
public static I_MatchPredicate CreateCriteriaPredicate(ValueEval evaluatedCriteriaArg) { if (evaluatedCriteriaArg is NumberEval) { return new NumberMatcher(((NumberEval)evaluatedCriteriaArg).NumberValue, CmpOp.OP_NONE); } if (evaluatedCriteriaArg is BoolEval) { return new BooleanMatcher(((BoolEval)evaluatedCriteriaArg).BooleanValue, CmpOp.OP_NONE); } if (evaluatedCriteriaArg is StringEval) { return CreateGeneralMatchPredicate((StringEval)evaluatedCriteriaArg); } if (evaluatedCriteriaArg == BlankEval.instance) { return null; } throw new Exception("Unexpected type for criteria (" + evaluatedCriteriaArg.GetType().Name + ")"); }
/** * @param ve must be a <tt>NumberEval</tt>, <tt>StringEval</tt>, <tt>BoolEval</tt>, or <tt>BlankEval</tt> * @return the Converted string value. never <c>null</c> */ public static String CoerceValueToString(ValueEval ve) { if (ve is StringValueEval) { StringValueEval sve = (StringValueEval)ve; return sve.StringValue; } if (ve is NumberEval) { NumberEval neval = (NumberEval)ve; return neval.StringValue; } if (ve is BlankEval) { return ""; } throw new ArgumentException("Unexpected eval class (" + ve.GetType().Name + ")"); }
/** * Applies some conversion rules if the supplied value Is not alReady a number. * Note - <tt>BlankEval</tt> Is not supported and must be handled by the caller. * @param ev must be a <tt>NumberEval</tt>, <tt>StringEval</tt> or <tt>BoolEval</tt> * @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 Exception if the supplied parameter Is not <tt>NumberEval</tt>, * <tt>StringEval</tt> or <tt>BoolEval</tt> */ public static double CoerceValueToDouble(ValueEval ev) { if (ev == BlankEval.INSTANCE) { return 0.0; } if (ev is NumericValueEval) { // this also handles bools return ((NumericValueEval)ev).NumberValue; } if (ev is StringEval) { double dd = ParseDouble(((StringEval)ev).StringValue); if (double.IsNaN(dd) ) { throw EvaluationException.InvalidValue(); } return dd; } throw new Exception("Unexpected arg eval type (" + ev.GetType().Name + ")"); }
public CompareResult CompareTo(ValueEval other) { if (other == null) { throw new Exception("Compare to value cannot be null"); } if (_targetType != other.GetType()) { return CompareResult.TypeMismatch; } return CompareSameType(other); }
private static int DoCompare(ValueEval va, ValueEval vb) { // special cases when one operand is blank if (va == BlankEval.instance) { return CompareBlank(vb); } if (vb == BlankEval.instance) { return -CompareBlank(va); } if (va is BoolEval) { if (vb is BoolEval) { BoolEval bA = (BoolEval)va; BoolEval bB = (BoolEval)vb; if (bA.BooleanValue == bB.BooleanValue) { return 0; } return bA.BooleanValue ? 1 : -1; } return 1; } if (vb is BoolEval) { return -1; } if (va is StringEval) { if (vb is StringEval) { StringEval sA = (StringEval)va; StringEval sB = (StringEval)vb; return string.Compare(sA.StringValue, sB.StringValue, StringComparison.OrdinalIgnoreCase); } return 1; } if (vb is StringEval) { return -1; } if (va is NumberEval) { if (vb is NumberEval) { NumberEval nA = (NumberEval)va; NumberEval nB = (NumberEval)vb; if (nA.NumberValue == nB.NumberValue) { // Excel considers -0.0 == 0.0 which is different to Double.compare() return 0; } return NumberComparer.Compare(nA.NumberValue, nB.NumberValue); } } throw new ArgumentException("Bad operand types (" + va.GetType().Name + "), (" + vb.GetType().Name + ")"); }
private static int CompareBlank(ValueEval v) { if (v == BlankEval.instance) { return 0; } if (v is BoolEval) { BoolEval boolEval = (BoolEval) v; return boolEval.BooleanValue ? -1 : 0; } if (v is NumberEval) { NumberEval ne = (NumberEval) v; //return ne.NumberValue.CompareTo(0.0); return NumberComparer.Compare(0.0, ne.NumberValue); } if (v is StringEval) { StringEval se = (StringEval) v; return se.StringValue.Length < 1 ? 0 : -1; } throw new ArgumentException("bad value class (" + v.GetType().Name + ")"); }
public static LookupValueComparer CreateLookupComparer(ValueEval lookupValue) { if (lookupValue == BlankEval.instance) { // blank eval translates to zero // Note - a blank eval in the lookup column/row never matches anything // empty string in the lookup column/row can only be matched by explicit emtpty string return new NumberLookupComparer(NumberEval.ZERO); } if (lookupValue is StringEval) { return new StringLookupComparer((StringEval)lookupValue); } if (lookupValue is NumberEval) { return new NumberLookupComparer((NumberEval)lookupValue); } if (lookupValue is BoolEval) { return new BooleanLookupComparer((BoolEval)lookupValue); } throw new ArgumentException("Bad lookup value type (" + lookupValue.GetType().Name + ")"); }
/** * @return the number of Evaluated cells in the range that match the specified criteria */ private ValueEval CountMatchingCellsInArea(ValueEval rangeArg, I_MatchPredicate criteriaPredicate) { int result; if (rangeArg is RefEval) { result = CountUtils.CountMatchingCell((RefEval)rangeArg, criteriaPredicate); } else if (rangeArg is AreaEval) { result = CountUtils.CountMatchingCellsInArea((AreaEval)rangeArg, criteriaPredicate); } else { throw new ArgumentException("Bad range arg type (" + rangeArg.GetType().Name + ")"); } return new NumberEval(result); }
private static int DoCompare(ValueEval va, ValueEval vb) { // special cases when one operand is blank if (va == BlankEval.instance) { return CompareBlank(vb); } if (vb == BlankEval.instance) { return -CompareBlank(va); } if (va is BoolEval) { if (vb is BoolEval) { BoolEval bA = (BoolEval)va; BoolEval bB = (BoolEval)vb; if (bA.BooleanValue == bB.BooleanValue) { return 0; } return bA.BooleanValue ? 1 : -1; } return 1; } if (vb is BoolEval) { return -1; } if (va is StringEval) { if (vb is StringEval) { StringEval sA = (StringEval)va; StringEval sB = (StringEval)vb; return string.Compare(sA.StringValue,sB.StringValue,true); } return 1; } if (vb is StringEval) { return -1; } if (va is NumberEval) { if (vb is NumberEval) { NumberEval nA = (NumberEval)va; NumberEval nB = (NumberEval)vb; return nA.NumberValue.CompareTo(nB.NumberValue); } } throw new ArgumentException("Bad operand types (" + va.GetType().Name + "), (" + vb.GetType().Name + ")"); }
/** * @return the number of evaluated cells in the range that match the specified criteria */ private double CountMatchingCellsInArea(ValueEval rangeArg, I_MatchPredicate criteriaPredicate) { if (rangeArg is RefEval) { return CountUtils.CountMatchingCell((RefEval)rangeArg, criteriaPredicate); } else if (rangeArg is TwoDEval) { return CountUtils.CountMatchingCellsInArea((TwoDEval)rangeArg, criteriaPredicate); } else { throw new ArgumentException("Bad range arg type (" + rangeArg.GetType().Name + ")"); } }
private static ValueVector EvaluateLookupRange(ValueEval eval) { if (eval is RefEval) { RefEval re = (RefEval)eval; return new SingleValueVector(re.InnerValueEval); } if (eval is 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 is NumericValueEval) { throw new EvaluationException(ErrorEval.NA); } if (eval is StringEval) { StringEval se = (StringEval)eval; double d = OperandResolver.ParseDouble(se.StringValue); if (double.IsNaN(d)) { // plain string throw new EvaluationException(ErrorEval.VALUE_INVALID); } // else looks like a number throw new EvaluationException(ErrorEval.NA); } throw new Exception("Unexpected eval type (" + eval.GetType().Name + ")"); }
public CompareResult CompareTo(ValueEval other) { if (other == null) { throw new Exception("Compare to value cannot be null"); } if (_tarGetType != other.GetType()) { return CompareResult.TYPE_MISMATCH; } if (_tarGetType == typeof(StringEval)) { } return CompareSameType(other); }
protected LookupValueComparerBase(ValueEval tarGetValue) { if (tarGetValue == null) { throw new Exception("tarGetValue cannot be null"); } _tarGetType = tarGetValue.GetType(); }
/** * @return <c>null</c> to represent blank values * @throws EvaluationException if ve is an ErrorEval, or if a string value cannot be converted */ public static Boolean? CoerceValueToBoolean(ValueEval ve, bool stringsAreBlanks) { if (ve == null || ve == BlankEval.INSTANCE) { // TODO - remove 've == null' condition once AreaEval is fixed return null; } if (ve is BoolEval) { return ((BoolEval)ve).BooleanValue; } if (ve is StringEval) { if (stringsAreBlanks) { return null; } String str = ((StringEval)ve).StringValue; if (str.Equals("true", StringComparison.InvariantCultureIgnoreCase)) { return true; } if (str.Equals("false", StringComparison.InvariantCultureIgnoreCase)) { return false; } // else - string cannot be converted to boolean throw new EvaluationException(ErrorEval.VALUE_INVALID); } if (ve is NumericValueEval) { NumericValueEval ne = (NumericValueEval)ve; double d = ne.NumberValue; if (Double.IsNaN(d)) { throw new EvaluationException(ErrorEval.VALUE_INVALID); } return d != 0; } if (ve is ErrorEval) { throw new EvaluationException((ErrorEval)ve); } throw new InvalidOperationException("Unexpected eval (" + ve.GetType().Name + ")"); }
private void CollectValue(ValueEval ve, bool isViaReference, DoubleList temp) { if (ve == null) { throw new ArgumentException("ve must not be null"); } if (ve is NumberEval) { NumberEval ne = (NumberEval)ve; temp.Add(ne.NumberValue); return; } if (ve is ErrorEval) { throw new EvaluationException((ErrorEval)ve); } if (ve is StringEval) { if (isViaReference) { // ignore all ref strings return; } String s = ((StringEval)ve).StringValue; Double d = OperandResolver.ParseDouble(s); if (double.IsNaN(d)) { throw new EvaluationException(ErrorEval.VALUE_INVALID); } temp.Add(d); return; } if (ve is BoolEval) { if (!isViaReference || _isReferenceBoolCounted) { BoolEval boolEval = (BoolEval)ve; temp.Add(boolEval.NumberValue); } return; } if (ve == BlankEval.instance) { if (_isBlankCounted) { temp.Add(0.0); } return; } throw new InvalidOperationException("Invalid ValueEval type passed for conversion: (" + ve.GetType() + ")"); }
private static void CollectValue(ValueEval arg, IList temp, bool mustBeNumber) { if (arg is ErrorEval) { throw new EvaluationException((ErrorEval)arg); } if (arg == BlankEval.instance || arg is BoolEval || arg is StringEval) { if (mustBeNumber) { throw EvaluationException.InvalidValue(); } return; } if (arg is NumberEval) { temp.Add(((NumberEval)arg).NumberValue); return; } throw new InvalidOperationException("Unexpected value type (" + arg.GetType().Name + ")"); }
/** * Determines a <c>double</c> value for the specified <c>ValueEval</c>. * @param IsScalarProduct <c>false</c> for SUMPRODUCTs over area refs. * @throws EvalEx if <c>ve</c> represents an error value. * <p/> * Note - string values and empty cells are interpreted differently depending on * <c>isScalarProduct</c>. For scalar products, if any term Is blank or a string, the * error (#VALUE!) Is raised. For area (sum)products, if any term Is blank or a string, the * result Is zero. */ private static double GetProductTerm(ValueEval ve, bool IsScalarProduct) { if (ve is 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 EvalEx(ErrorEval.VALUE_INVALID); } return 0; } if (ve is ErrorEval) { throw new EvalEx((ErrorEval)ve); } if (ve is StringEval) { if (IsScalarProduct) { throw new EvalEx(ErrorEval.VALUE_INVALID); } // Note for area SUMPRODUCTs, string values are interpreted as zero // even if they would Parse as valid numeric values return 0; } if (ve is NumericValueEval) { NumericValueEval nve = (NumericValueEval)ve; return nve.NumberValue; } throw new Exception("Unexpected value eval class (" + ve.GetType().Name + ")"); }
/** * returned value can be either A NumericValueEval, BlankEval or ErrorEval. * The params can be either NumberEval, BoolEval, StringEval, or * RefEval * @param eval */ public ValueEval AttemptXlateToNumeric(ValueEval eval) { ValueEval retval = null; if (eval == null) { retval = BlankEval.instance; } // most common case - least worries :) else if (eval is NumberEval) { retval = eval; } // booleval else if (eval is BoolEval) { retval = ((flags & BOOL_IS_PARSED) > 0) ? (NumericValueEval)eval : XlateBlankEval(BLANK_IS_PARSED); } // stringeval else if (eval is StringEval) { retval = XlateStringEval((StringEval)eval); // TODO: recursive call needed } // refeval else if (eval is RefEval) { retval = XlateRefEval((RefEval)eval); } // erroreval else if (eval is ErrorEval) { retval = eval; } else if (eval is BlankEval) { retval = XlateBlankEval(BLANK_IS_PARSED); } // probably AreaEval? then not acceptable. else { throw new Exception("Invalid ValueEval type passed for conversion: " + eval.GetType()); } return retval; }