Skip to content

Commit

Permalink
changed workbook reference to index in CellLocation
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@701598 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Josh Micich committed Oct 4, 2008
1 parent d0850e4 commit 4bf266b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/java/org/apache/poi/ss/formula/CellLocation.java
Expand Up @@ -25,24 +25,24 @@ Licensed to the Apache Software Foundation (ASF) under one or more
final class CellLocation {
public static final CellLocation[] EMPTY_ARRAY = { };

private final EvaluationWorkbook _book;
private final int _bookIx;
private final int _sheetIndex;
private final int _rowIndex;
private final int _columnIndex;
private final int _hashCode;

public CellLocation(EvaluationWorkbook book, int sheetIndex, int rowIndex, int columnIndex) {
public CellLocation(int bookIx, int sheetIndex, int rowIndex, int columnIndex) {
if (sheetIndex < 0) {
throw new IllegalArgumentException("sheetIndex must not be negative");
}
_book = book;
_bookIx = bookIx;
_sheetIndex = sheetIndex;
_rowIndex = rowIndex;
_columnIndex = columnIndex;
_hashCode = System.identityHashCode(book) + sheetIndex + 17 * (rowIndex + 17 * columnIndex);
_hashCode = _bookIx + 17 * (sheetIndex + 17 * (rowIndex + 17 * columnIndex));
}
public Object getBook() {
return _book;
public int getBookIndex() {
return _bookIx;
}
public int getSheetIndex() {
return _sheetIndex;
Expand All @@ -65,7 +65,7 @@ public boolean equals(Object obj) {
if (getSheetIndex() != other.getSheetIndex()) {
return false;
}
if (getBook() != other.getBook()) {
if (getBookIndex() != other.getBookIndex()) {
return false;
}
return true;
Expand Down
Expand Up @@ -97,7 +97,7 @@ private static void hookNewEnvironment(WorkbookEvaluator[] evaluators, Collabora
EvaluationCache cache = new EvaluationCache(evalListener);

for(int i=0; i<nItems; i++) {
evaluators[i].attachToEnvironment(env, cache);
evaluators[i].attachToEnvironment(env, cache, i);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/java/org/apache/poi/ss/formula/EvaluationCache.java
Expand Up @@ -203,7 +203,7 @@ public int compare(Object a, Object b) {
CellLocation clB = (CellLocation) b;

int cmp;
cmp = System.identityHashCode(clA.getBook()) - System.identityHashCode(clB.getBook());
cmp = clA.getBookIndex() - clB.getBookIndex();
if (cmp != 0) {
return cmp;
}
Expand Down
17 changes: 12 additions & 5 deletions src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
Expand Up @@ -80,6 +80,7 @@ public final class WorkbookEvaluator {

private final EvaluationWorkbook _workbook;
private EvaluationCache _cache;
private int _workbookIx;

private final IEvaluationListener _evaluationListener;
private final Map _sheetIndexesBySheet;
Expand All @@ -94,6 +95,7 @@ public WorkbookEvaluator(EvaluationWorkbook workbook) {
_cache = new EvaluationCache(evaluationListener);
_sheetIndexesBySheet = new IdentityHashMap();
_collaboratingWorkbookEnvironment = CollaboratingWorkbooksEnvironment.EMPTY;
_workbookIx = 0;
}

/**
Expand All @@ -111,9 +113,10 @@ private static void logDebug(String s) {
System.out.println(s);
}
}
/* package */ void attachToEnvironment(CollaboratingWorkbooksEnvironment collaboratingWorkbooksEnvironment, EvaluationCache cache) {
/* package */ void attachToEnvironment(CollaboratingWorkbooksEnvironment collaboratingWorkbooksEnvironment, EvaluationCache cache, int workbookIx) {
_collaboratingWorkbookEnvironment = collaboratingWorkbooksEnvironment;
_cache = cache;
_workbookIx = workbookIx;
}
/* package */ CollaboratingWorkbooksEnvironment getEnvironment() {
return _collaboratingWorkbookEnvironment;
Expand All @@ -122,6 +125,7 @@ private static void logDebug(String s) {
/* package */ void detachFromEnvironment() {
_collaboratingWorkbookEnvironment = CollaboratingWorkbooksEnvironment.EMPTY;
_cache = new EvaluationCache(_evaluationListener);
_workbookIx = 0;
}
/* package */ IEvaluationListener getEvaluationListener() {
return _evaluationListener;
Expand All @@ -148,7 +152,7 @@ public void setCachedPlainValue(HSSFSheet sheet, int rowIndex, int columnIndex,
throw new IllegalArgumentException("value must not be null");
}
int sheetIndex = getSheetIndex(sheet);
_cache.setValue(new CellLocation(_workbook, sheetIndex, rowIndex, columnIndex), true, CellLocation.EMPTY_ARRAY, value);
_cache.setValue(getCellLoc(sheetIndex, rowIndex, columnIndex), true, CellLocation.EMPTY_ARRAY, value);

}
/**
Expand All @@ -157,7 +161,7 @@ public void setCachedPlainValue(HSSFSheet sheet, int rowIndex, int columnIndex,
*/
public void notifySetFormula(HSSFSheet sheet, int rowIndex, int columnIndex) {
int sheetIndex = getSheetIndex(sheet);
_cache.setValue(new CellLocation(_workbook, sheetIndex, rowIndex, columnIndex), false, CellLocation.EMPTY_ARRAY, null);
_cache.setValue(getCellLoc(sheetIndex, rowIndex, columnIndex), false, CellLocation.EMPTY_ARRAY, null);

}
private int getSheetIndex(HSSFSheet sheet) {
Expand All @@ -175,7 +179,7 @@ private int getSheetIndex(HSSFSheet sheet) {

public ValueEval evaluate(HSSFCell srcCell) {
int sheetIndex = getSheetIndex(srcCell.getSheet());
CellLocation cellLoc = new CellLocation(_workbook, sheetIndex, srcCell.getRowIndex(), srcCell.getCellNum());
CellLocation cellLoc = getCellLoc(sheetIndex, srcCell.getRowIndex(), srcCell.getCellNum());
return internalEvaluate(srcCell, cellLoc, new EvaluationTracker(_cache));
}

Expand Down Expand Up @@ -471,8 +475,11 @@ private Eval evaluateNameFormula(Ptg[] ptgs, int sheetIndex, EvaluationTracker t
} else {
cell = row.getCell(columnIndex);
}
CellLocation cellLoc = new CellLocation(_workbook, sheetIndex, rowIndex, columnIndex);
CellLocation cellLoc = getCellLoc(sheetIndex, rowIndex, columnIndex);
tracker.acceptDependency(cellLoc);
return internalEvaluate(cell, cellLoc, tracker);
}
private CellLocation getCellLoc(int sheetIndex, int rowIndex, int columnIndex) {
return new CellLocation(_workbookIx, sheetIndex, rowIndex, columnIndex);
}
}

0 comments on commit 4bf266b

Please sign in to comment.