Removed Ptg[] parameter from method IEvaluationListener.onStartEvaluate()
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@883208 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1f22e9c945
commit
b6a98299a3
@ -17,21 +17,20 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula;
|
package org.apache.poi.ss.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.Ptg;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests can implement this class to track the internal working of the {@link WorkbookEvaluator}.<br/>
|
* Tests can implement this class to track the internal working of the {@link WorkbookEvaluator}.<br/>
|
||||||
*
|
*
|
||||||
* For POI internal testing use only
|
* For POI internal testing use only
|
||||||
*
|
*
|
||||||
* @author Josh Micich
|
* @author Josh Micich
|
||||||
*/
|
*/
|
||||||
interface IEvaluationListener {
|
interface IEvaluationListener {
|
||||||
/**
|
/**
|
||||||
* A (mostly) opaque interface to allow test clients to trace cache values
|
* A (mostly) opaque interface to allow test clients to trace cache values
|
||||||
* Each spreadsheet cell gets one unique cache entry instance. These objects
|
* Each spreadsheet cell gets one unique cache entry instance. These objects
|
||||||
* are safe to use as keys in {@link java.util.HashMap}s
|
* are safe to use as keys in {@link java.util.HashMap}s
|
||||||
*/
|
*/
|
||||||
interface ICacheEntry {
|
interface ICacheEntry {
|
||||||
ValueEval getValue();
|
ValueEval getValue();
|
||||||
@ -39,13 +38,13 @@ interface IEvaluationListener {
|
|||||||
|
|
||||||
void onCacheHit(int sheetIndex, int rowIndex, int columnIndex, ValueEval result);
|
void onCacheHit(int sheetIndex, int rowIndex, int columnIndex, ValueEval result);
|
||||||
void onReadPlainValue(int sheetIndex, int rowIndex, int columnIndex, ICacheEntry entry);
|
void onReadPlainValue(int sheetIndex, int rowIndex, int columnIndex, ICacheEntry entry);
|
||||||
void onStartEvaluate(EvaluationCell cell, ICacheEntry entry, Ptg[] ptgs);
|
void onStartEvaluate(EvaluationCell cell, ICacheEntry entry);
|
||||||
void onEndEvaluate(ICacheEntry entry, ValueEval result);
|
void onEndEvaluate(ICacheEntry entry, ValueEval result);
|
||||||
void onClearWholeCache();
|
void onClearWholeCache();
|
||||||
void onClearCachedValue(ICacheEntry entry);
|
void onClearCachedValue(ICacheEntry entry);
|
||||||
/**
|
/**
|
||||||
* Internally, formula {@link ICacheEntry}s are stored in sets which may change ordering due
|
* Internally, formula {@link ICacheEntry}s are stored in sets which may change ordering due
|
||||||
* to seemingly trivial changes. This method is provided to make the order of call-backs to
|
* to seemingly trivial changes. This method is provided to make the order of call-backs to
|
||||||
* {@link #onClearDependentCachedValue(ICacheEntry, int)} more deterministic.
|
* {@link #onClearDependentCachedValue(ICacheEntry, int)} more deterministic.
|
||||||
*/
|
*/
|
||||||
void sortDependentCachedValues(ICacheEntry[] formulaCells);
|
void sortDependentCachedValues(ICacheEntry[] formulaCells);
|
||||||
|
@ -259,7 +259,7 @@ public final class WorkbookEvaluator {
|
|||||||
if (evalListener == null) {
|
if (evalListener == null) {
|
||||||
result = evaluateFormula(ec, ptgs);
|
result = evaluateFormula(ec, ptgs);
|
||||||
} else {
|
} else {
|
||||||
evalListener.onStartEvaluate(srcCell, cce, ptgs);
|
evalListener.onStartEvaluate(srcCell, cce);
|
||||||
result = evaluateFormula(ec, ptgs);
|
result = evaluateFormula(ec, ptgs);
|
||||||
evalListener.onEndEvaluate(cce, result);
|
evalListener.onEndEvaluate(cce, result);
|
||||||
}
|
}
|
||||||
|
@ -311,7 +311,7 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
|
|||||||
public void onCacheHit(int sheetIndex, int srcRowNum, int srcColNum, ValueEval result) {
|
public void onCacheHit(int sheetIndex, int srcRowNum, int srcColNum, ValueEval result) {
|
||||||
_countCacheHits++;
|
_countCacheHits++;
|
||||||
}
|
}
|
||||||
public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry, Ptg[] ptgs) {
|
public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry) {
|
||||||
_countCacheMisses++;
|
_countCacheMisses++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import junit.framework.TestCase;
|
|||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.record.NameRecord;
|
import org.apache.poi.hssf.record.NameRecord;
|
||||||
import org.apache.poi.hssf.record.formula.Ptg;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
||||||
import org.apache.poi.ss.formula.EvaluationCell;
|
import org.apache.poi.ss.formula.EvaluationCell;
|
||||||
@ -179,7 +178,7 @@ public final class TestHSSFFormulaEvaluator extends TestCase {
|
|||||||
public EvalCountListener() {
|
public EvalCountListener() {
|
||||||
_evalCount = 0;
|
_evalCount = 0;
|
||||||
}
|
}
|
||||||
public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry, Ptg[] ptgs) {
|
public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry) {
|
||||||
_evalCount++;
|
_evalCount++;
|
||||||
}
|
}
|
||||||
public int getEvalCount() {
|
public int getEvalCount() {
|
||||||
|
@ -17,43 +17,42 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula;
|
package org.apache.poi.ss.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.Ptg;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests should extend this class if they need to track the internal working of the {@link WorkbookEvaluator}.<br/>
|
* Tests should extend this class if they need to track the internal working of the {@link WorkbookEvaluator}.<br/>
|
||||||
*
|
*
|
||||||
* Default method implementations all do nothing
|
* Default method implementations all do nothing
|
||||||
*
|
*
|
||||||
* @author Josh Micich
|
* @author Josh Micich
|
||||||
*/
|
*/
|
||||||
public abstract class EvaluationListener implements IEvaluationListener {
|
public abstract class EvaluationListener implements IEvaluationListener {
|
||||||
public void onCacheHit(int sheetIndex, int rowIndex, int columnIndex, ValueEval result) {
|
public void onCacheHit(int sheetIndex, int rowIndex, int columnIndex, ValueEval result) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
public void onReadPlainValue(int sheetIndex, int rowIndex, int columnIndex, ICacheEntry entry) {
|
public void onReadPlainValue(int sheetIndex, int rowIndex, int columnIndex, ICacheEntry entry) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry, Ptg[] ptgs) {
|
public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
public void onEndEvaluate(ICacheEntry entry, ValueEval result) {
|
public void onEndEvaluate(ICacheEntry entry, ValueEval result) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
public void onClearWholeCache() {
|
public void onClearWholeCache() {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
public void onClearCachedValue(ICacheEntry entry) {
|
public void onClearCachedValue(ICacheEntry entry) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
public void onChangeFromBlankValue(int sheetIndex, int rowIndex, int columnIndex,
|
public void onChangeFromBlankValue(int sheetIndex, int rowIndex, int columnIndex,
|
||||||
EvaluationCell cell, ICacheEntry entry) {
|
EvaluationCell cell, ICacheEntry entry) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
public void sortDependentCachedValues(ICacheEntry[] entries) {
|
public void sortDependentCachedValues(ICacheEntry[] entries) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
public void onClearDependentCachedValue(ICacheEntry entry, int depth) {
|
public void onClearDependentCachedValue(ICacheEntry entry, int depth) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.StringEval;
|
import org.apache.poi.hssf.record.formula.eval.StringEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
||||||
|
import org.apache.poi.hssf.usermodel.FormulaExtractor;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFEvaluationTestHelper;
|
import org.apache.poi.hssf.usermodel.HSSFEvaluationTestHelper;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
|
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
|
||||||
@ -43,30 +44,30 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
|
|||||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.hssf.util.CellReference;
|
import org.apache.poi.hssf.util.CellReference;
|
||||||
|
import org.apache.poi.ss.formula.IEvaluationListener.ICacheEntry;
|
||||||
import org.apache.poi.ss.formula.PlainCellCache.Loc;
|
import org.apache.poi.ss.formula.PlainCellCache.Loc;
|
||||||
import org.apache.poi.ss.usermodel.CellValue;
|
import org.apache.poi.ss.usermodel.CellValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link org.apache.poi.ss.formula.EvaluationCache}. Makes sure that where possible (previously calculated) cached
|
* Tests {@link org.apache.poi.ss.formula.EvaluationCache}. Makes sure that where possible (previously calculated) cached
|
||||||
* values are used. Also checks that changing cell values causes the correct (minimal) set of
|
* values are used. Also checks that changing cell values causes the correct (minimal) set of
|
||||||
* dependent cached values to be cleared.
|
* dependent cached values to be cleared.
|
||||||
*
|
*
|
||||||
* @author Josh Micich
|
* @author Josh Micich
|
||||||
*/
|
*/
|
||||||
public class TestEvaluationCache extends TestCase {
|
public class TestEvaluationCache extends TestCase {
|
||||||
|
|
||||||
private static final class FormulaCellCacheEntryComparer implements Comparator {
|
|
||||||
|
|
||||||
private final Map _formulaCellsByCacheEntry;
|
private static final class FormulaCellCacheEntryComparer implements Comparator<ICacheEntry> {
|
||||||
|
|
||||||
public FormulaCellCacheEntryComparer(Map formulaCellsByCacheEntry) {
|
private final Map<ICacheEntry,EvaluationCell> _formulaCellsByCacheEntry;
|
||||||
|
|
||||||
|
public FormulaCellCacheEntryComparer(Map<ICacheEntry,EvaluationCell> formulaCellsByCacheEntry) {
|
||||||
_formulaCellsByCacheEntry = formulaCellsByCacheEntry;
|
_formulaCellsByCacheEntry = formulaCellsByCacheEntry;
|
||||||
}
|
}
|
||||||
private EvaluationCell getCell(Object a) {
|
private EvaluationCell getCell(ICacheEntry a) {
|
||||||
return (EvaluationCell)_formulaCellsByCacheEntry.get(a);
|
return _formulaCellsByCacheEntry.get(a);
|
||||||
}
|
}
|
||||||
|
public int compare(ICacheEntry oa, ICacheEntry ob) {
|
||||||
public int compare(Object oa, Object ob) {
|
|
||||||
EvaluationCell a = getCell(oa);
|
EvaluationCell a = getCell(oa);
|
||||||
EvaluationCell b = getCell(ob);
|
EvaluationCell b = getCell(ob);
|
||||||
int cmp;
|
int cmp;
|
||||||
@ -84,19 +85,19 @@ public class TestEvaluationCache extends TestCase {
|
|||||||
throw new RuntimeException("Incomplete code - don't know how to order sheets");
|
throw new RuntimeException("Incomplete code - don't know how to order sheets");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class EvalListener extends EvaluationListener {
|
private static final class EvalListener extends EvaluationListener {
|
||||||
|
|
||||||
private final List _logList;
|
private final List<String> _logList;
|
||||||
private final HSSFWorkbook _book;
|
private final HSSFWorkbook _book;
|
||||||
private Map _formulaCellsByCacheEntry;
|
private Map<ICacheEntry,EvaluationCell> _formulaCellsByCacheEntry;
|
||||||
private Map _plainCellLocsByCacheEntry;
|
private Map<ICacheEntry,Loc> _plainCellLocsByCacheEntry;
|
||||||
|
|
||||||
public EvalListener(HSSFWorkbook wb) {
|
public EvalListener(HSSFWorkbook wb) {
|
||||||
_book = wb;
|
_book = wb;
|
||||||
_logList = new ArrayList();
|
_logList = new ArrayList<String>();
|
||||||
_formulaCellsByCacheEntry = new HashMap();
|
_formulaCellsByCacheEntry = new HashMap<ICacheEntry,EvaluationCell>();
|
||||||
_plainCellLocsByCacheEntry = new HashMap();
|
_plainCellLocsByCacheEntry = new HashMap<ICacheEntry, Loc>();
|
||||||
}
|
}
|
||||||
public void onCacheHit(int sheetIndex, int rowIndex, int columnIndex, ValueEval result) {
|
public void onCacheHit(int sheetIndex, int rowIndex, int columnIndex, ValueEval result) {
|
||||||
log("hit", rowIndex, columnIndex, result);
|
log("hit", rowIndex, columnIndex, result);
|
||||||
@ -106,20 +107,21 @@ public class TestEvaluationCache extends TestCase {
|
|||||||
_plainCellLocsByCacheEntry.put(entry, loc);
|
_plainCellLocsByCacheEntry.put(entry, loc);
|
||||||
log("value", rowIndex, columnIndex, entry.getValue());
|
log("value", rowIndex, columnIndex, entry.getValue());
|
||||||
}
|
}
|
||||||
public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry, Ptg[] ptgs) {
|
public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry) {
|
||||||
_formulaCellsByCacheEntry.put(entry, cell);
|
_formulaCellsByCacheEntry.put(entry, cell);
|
||||||
log("start", cell.getRowIndex(), cell.getColumnIndex(), ptgs);
|
HSSFCell hc = _book.getSheetAt(0).getRow(cell.getRowIndex()).getCell(cell.getColumnIndex());
|
||||||
|
log("start", cell.getRowIndex(), cell.getColumnIndex(), FormulaExtractor.getPtgs(hc));
|
||||||
}
|
}
|
||||||
public void onEndEvaluate(ICacheEntry entry, ValueEval result) {
|
public void onEndEvaluate(ICacheEntry entry, ValueEval result) {
|
||||||
EvaluationCell cell = (EvaluationCell) _formulaCellsByCacheEntry.get(entry);
|
EvaluationCell cell = _formulaCellsByCacheEntry.get(entry);
|
||||||
log("end", cell.getRowIndex(), cell.getColumnIndex(), result);
|
log("end", cell.getRowIndex(), cell.getColumnIndex(), result);
|
||||||
}
|
}
|
||||||
public void onClearCachedValue(ICacheEntry entry) {
|
public void onClearCachedValue(ICacheEntry entry) {
|
||||||
int rowIndex;
|
int rowIndex;
|
||||||
int columnIndex;
|
int columnIndex;
|
||||||
EvaluationCell cell = (EvaluationCell) _formulaCellsByCacheEntry.get(entry);
|
EvaluationCell cell = _formulaCellsByCacheEntry.get(entry);
|
||||||
if (cell == null) {
|
if (cell == null) {
|
||||||
Loc loc = (Loc)_plainCellLocsByCacheEntry.get(entry);
|
Loc loc = _plainCellLocsByCacheEntry.get(entry);
|
||||||
if (loc == null) {
|
if (loc == null) {
|
||||||
throw new IllegalStateException("can't find cell or location");
|
throw new IllegalStateException("can't find cell or location");
|
||||||
}
|
}
|
||||||
@ -135,7 +137,7 @@ public class TestEvaluationCache extends TestCase {
|
|||||||
Arrays.sort(entries, new FormulaCellCacheEntryComparer(_formulaCellsByCacheEntry));
|
Arrays.sort(entries, new FormulaCellCacheEntryComparer(_formulaCellsByCacheEntry));
|
||||||
}
|
}
|
||||||
public void onClearDependentCachedValue(ICacheEntry entry, int depth) {
|
public void onClearDependentCachedValue(ICacheEntry entry, int depth) {
|
||||||
EvaluationCell cell = (EvaluationCell) _formulaCellsByCacheEntry.get(entry);
|
EvaluationCell cell = _formulaCellsByCacheEntry.get(entry);
|
||||||
log("clear" + depth, cell.getRowIndex(), cell.getColumnIndex(), entry.getValue());
|
log("clear" + depth, cell.getRowIndex(), cell.getColumnIndex(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,7 +397,7 @@ public class TestEvaluationCache extends TestCase {
|
|||||||
"hit B3 2",
|
"hit B3 2",
|
||||||
"hit C2 62",
|
"hit C2 62",
|
||||||
"start C3 SUM(D3:E4)",
|
"start C3 SUM(D3:E4)",
|
||||||
"hit D3 16", "hit E3 17",
|
"hit D3 16", "hit E3 17",
|
||||||
// "value D4 #BLANK#", "value E4 #BLANK#",
|
// "value D4 #BLANK#", "value E4 #BLANK#",
|
||||||
"end C3 33",
|
"end C3 33",
|
||||||
"end B2 91",
|
"end B2 91",
|
||||||
@ -560,7 +562,7 @@ public class TestEvaluationCache extends TestCase {
|
|||||||
confirmLog(ms, new String[] {
|
confirmLog(ms, new String[] {
|
||||||
"hit A1 14",
|
"hit A1 14",
|
||||||
});
|
});
|
||||||
|
|
||||||
ms.setCellValue("D1", 1);
|
ms.setCellValue("D1", 1);
|
||||||
ms.getAndClearLog();
|
ms.getAndClearLog();
|
||||||
|
|
||||||
@ -573,7 +575,7 @@ public class TestEvaluationCache extends TestCase {
|
|||||||
"end A1 15",
|
"end A1 15",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure that when blank cells are changed to value/formula cells, any dependent formulas
|
* Make sure that when blank cells are changed to value/formula cells, any dependent formulas
|
||||||
* have their cached results cleared.
|
* have their cached results cleared.
|
||||||
@ -601,7 +603,7 @@ public class TestEvaluationCache extends TestCase {
|
|||||||
cv = fe.evaluate(cellA1); // B1 was used to evaluate A1
|
cv = fe.evaluate(cellA1); // B1 was used to evaluate A1
|
||||||
assertEquals(2.2, cv.getNumberValue(), 0.0);
|
assertEquals(2.2, cv.getNumberValue(), 0.0);
|
||||||
|
|
||||||
cellB1.setCellValue(0.4); // changing B1, so A1 cached result should be cleared
|
cellB1.setCellValue(0.4); // changing B1, so A1 cached result should be cleared
|
||||||
fe.notifyUpdateCell(cellB1);
|
fe.notifyUpdateCell(cellB1);
|
||||||
cv = fe.evaluate(cellA1);
|
cv = fe.evaluate(cellA1);
|
||||||
if (cv.getNumberValue() == 2.2) {
|
if (cv.getNumberValue() == 2.2) {
|
||||||
@ -610,7 +612,7 @@ public class TestEvaluationCache extends TestCase {
|
|||||||
}
|
}
|
||||||
assertEquals(2.6, cv.getNumberValue(), 0.0);
|
assertEquals(2.6, cv.getNumberValue(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* same use-case as the test for bug 46053, but checking trace values too
|
* same use-case as the test for bug 46053, but checking trace values too
|
||||||
*/
|
*/
|
||||||
@ -642,7 +644,7 @@ public class TestEvaluationCache extends TestCase {
|
|||||||
"end A1 2.6",
|
"end A1 2.6",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void confirmEvaluate(MySheet ms, String cellRefText, double expectedValue) {
|
private static void confirmEvaluate(MySheet ms, String cellRefText, double expectedValue) {
|
||||||
ValueEval v = ms.evaluateCell(cellRefText);
|
ValueEval v = ms.evaluateCell(cellRefText);
|
||||||
assertEquals(NumberEval.class, v.getClass());
|
assertEquals(NumberEval.class, v.getClass());
|
||||||
@ -692,7 +694,6 @@ public class TestEvaluationCache extends TestCase {
|
|||||||
private static void debugPrint(PrintStream ps, String[] log) {
|
private static void debugPrint(PrintStream ps, String[] log) {
|
||||||
for (int i = 0; i < log.length; i++) {
|
for (int i = 0; i < log.length; i++) {
|
||||||
ps.println('"' + log[i] + "\",");
|
ps.println('"' + log[i] + "\",");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user