/** * 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 <c>null</c>. */ private static ValueEval DereferenceValue(ValueEval evaluationResult, int srcRowNum, int srcColNum) { if (evaluationResult is RefEval) { RefEval rv = (RefEval)evaluationResult; return(rv.InnerValueEval); } if (evaluationResult is AreaEval) { AreaEval ae = (AreaEval)evaluationResult; if (ae.IsRow) { if (ae.IsColumn) { return(ae.GetRelativeValue(0, 0)); } return(ae.GetValueAt(ae.FirstRow, srcColNum)); } if (ae.IsColumn) { return(ae.GetValueAt(srcRowNum, ae.FirstColumn)); } return(ErrorEval.VALUE_INVALID); } return(evaluationResult); }
/** * @return possibly <tt>ErrorEval</tt>, and <c>null</c> */ private static ValueEval ChooseSingleElementFromAreaInternal(AreaEval ae, int srcCellRow, int srcCellCol) { //if (false) //{ // // this is too simplistic // if (ae.ContainsRow(srcCellRow) && ae.ContainsColumn(srcCellCol)) // { // throw new EvaluationException(ErrorEval.CIRCULAR_REF_ERROR); // } // /* // Circular references are not dealt with directly here, but it is worth noting some Issues. // ANY one of the return statements in this method could return a cell that is identical // to the one immediately being Evaluated. The evaluating cell is identified by srcCellRow, // srcCellRow AND sheet. The sheet is not available in any nearby calling method, so that's // one reason why circular references are not easy to detect here. (The sheet of the returned // cell can be obtained from ae if it is an Area3DEval.) // Another reason there's little value in attempting to detect circular references here Is // that only direct circular references could be detected. If the cycle involved two or more // cells this method could not detect it. // Logic to detect evaluation cycles of all kinds has been coded in EvaluationCycleDetector // (and HSSFFormulaEvaluator). // */ //} if (ae.IsColumn) { if (ae.IsRow) { return(ae.GetRelativeValue(0, 0)); } if (!ae.ContainsRow(srcCellRow)) { throw EvaluationException.InvalidValue(); } return(ae.GetValueAt(srcCellRow, ae.FirstColumn)); } if (!ae.IsRow) { // multi-column, multi-row area if (ae.ContainsRow(srcCellRow) && ae.ContainsColumn(srcCellCol)) { return(ae.GetValueAt(ae.FirstRow, ae.FirstColumn)); } throw EvaluationException.InvalidValue(); } if (!ae.ContainsColumn(srcCellCol)) { throw EvaluationException.InvalidValue(); } return(ae.GetValueAt(ae.FirstRow, srcCellCol)); }
public void TestGetValue_bug44950() { AreaPtg ptg = new AreaPtg("B2:D3"); NumberEval one = new NumberEval(1); ValueEval[] values = { one, new NumberEval(2), new NumberEval(3), new NumberEval(4), new NumberEval(5), new NumberEval(6), }; AreaEval ae = EvalFactory.CreateAreaEval(ptg, values); if (one == ae.GetValueAt(1, 2)) { throw new AssertFailedException("Identified bug 44950 a"); } Confirm(1, ae, 1, 1); Confirm(2, ae, 1, 2); Confirm(3, ae, 1, 3); Confirm(4, ae, 2, 1); Confirm(5, ae, 2, 2); Confirm(6, ae, 2, 3); }
protected ValueEval SingleOperandEvaluate(Eval eval, int srcRow, short srcCol) { ValueEval retval; if (eval is AreaEval) { AreaEval ae = (AreaEval)eval; if (ae.Contains(srcRow, srcCol)) { // circular ref! retval = ErrorEval.CIRCULAR_REF_ERROR; } else if (ae.IsRow) { if (ae.ContainsColumn(srcCol)) { ValueEval ve = ae.GetValueAt(ae.FirstRow, srcCol); ve = Xlator.AttemptXlateToNumeric(ve); retval = Xlator.AttemptXlateToNumeric(ve); } else { retval = ErrorEval.VALUE_INVALID; } } else if (ae.IsColumn) { if (ae.ContainsRow(srcRow)) { ValueEval ve = ae.GetValueAt(srcRow, ae.FirstColumn); retval = Xlator.AttemptXlateToNumeric(ve); } else { retval = ErrorEval.VALUE_INVALID; } } else { retval = ErrorEval.VALUE_INVALID; } } else { retval = Xlator.AttemptXlateToNumeric((ValueEval)eval); } return(retval); }
/** * Returns an is StringValueEval or ErrorEval or BlankEval * * @param eval * @param srcRow * @param srcCol */ protected ValueEval SingleOperandEvaluate(Eval eval, int srcRow, short srcCol) { ValueEval retval; if (eval is AreaEval) { AreaEval ae = (AreaEval)eval; if (ae.Contains(srcRow, srcCol)) { // circular ref! retval = ErrorEval.CIRCULAR_REF_ERROR; } else if (ae.IsRow) { if (ae.ContainsColumn(srcCol)) { ValueEval ve = ae.GetValueAt(ae.FirstRow, srcCol); retval = InternalResolveEval(eval); } else { retval = ErrorEval.NAME_INVALID; } } else if (ae.IsColumn) { if (ae.ContainsRow(srcRow)) { ValueEval ve = ae.GetValueAt(srcRow, ae.FirstColumn); retval = InternalResolveEval(eval); } else { retval = ErrorEval.NAME_INVALID; } } else { retval = ErrorEval.NAME_INVALID; } } else { retval = InternalResolveEval(eval); } return(retval); }
/** * @return possibly <tt>ErrorEval</tt>, and <c>null</c> */ private static ValueEval ChooseSingleElementFromAreaInternal(AreaEval ae, int srcCellRow, short srcCellCol) { //if (false) //{ // // this Is too simplistic // if (ae.ContainsRow(srcCellRow) && ae.ContainsColumn(srcCellCol)) // { // throw new EvaluationException(ErrorEval.CIRCULAR_REF_ERROR); // } // /* // Circular references are not dealt with directly here, but it Is worth noting some Issues. // ANY one of the return statements in this method could return a cell that Is identical // to the one immediately being Evaluated. The evaluating cell Is identified by srcCellRow, // srcCellRow AND sheet. The sheet Is not available in any nearby calling method, so that's // one reason why circular references are not easy to detect here. (The sheet of the returned // cell can be obtained from ae if it Is an Area3DEval.) // Another reason there's little value in attempting to detect circular references here Is // that only direct circular references could be detected. If the cycle involved two or more // cells this method could not detect it. // Logic to detect evaluation cycles of all kinds has been coded in EvaluationCycleDetector // (and HSSFFormulaEvaluator). // */ //} if (ae.IsColumn) { if (ae.IsRow) { return ae.GetRelativeValue(0, 0); } if (!ae.ContainsRow(srcCellRow)) { throw EvaluationException.InvalidValue(); } return ae.GetValueAt(srcCellRow, ae.FirstColumn); } if (!ae.IsRow) { // multi-column, multi-row area if (ae.ContainsRow(srcCellRow) && ae.ContainsColumn(srcCellCol)) { return ae.GetValueAt(ae.FirstRow, ae.FirstColumn); } throw EvaluationException.InvalidValue(); } if (!ae.ContainsColumn(srcCellCol)) { throw EvaluationException.InvalidValue(); } return ae.GetValueAt(ae.FirstRow, srcCellCol); }
private static void Confirm(int expectedValue, AreaEval ae, int row, int col) { NumberEval v = (NumberEval)ae.GetValueAt(row, col); Assert.AreEqual(expectedValue, v.NumberValue, 0.0); }