]> source.dussan.org Git - poi.git/commitdiff
changed workbook reference to index in CellLocation
authorJosh Micich <josh@apache.org>
Sat, 4 Oct 2008 04:59:26 +0000 (04:59 +0000)
committerJosh Micich <josh@apache.org>
Sat, 4 Oct 2008 04:59:26 +0000 (04:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@701598 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/CellLocation.java
src/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java
src/java/org/apache/poi/ss/formula/EvaluationCache.java
src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java

index 6857c4bc1bbee17017745239aa5a619c5913c2f1..bb32e3dfa3fa83a6a5add28763df5c66daf56dcb 100644 (file)
@@ -25,24 +25,24 @@ import org.apache.poi.hssf.util.CellReference;
 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;
@@ -65,7 +65,7 @@ final class CellLocation {
                if (getSheetIndex() != other.getSheetIndex()) {
                        return false;
                }
-               if (getBook() != other.getBook()) {
+               if (getBookIndex() != other.getBookIndex()) {
                        return false;
                }
                return true;
index c62d2f182d72a38d64ac2a3ecfd2c2da0adb6283..7939596d3bf7063bae4bbde9539a6bcc074bd8c8 100644 (file)
@@ -97,7 +97,7 @@ public final class CollaboratingWorkbooksEnvironment {
                EvaluationCache cache = new EvaluationCache(evalListener);
                
                for(int i=0; i<nItems; i++) {
-                       evaluators[i].attachToEnvironment(env, cache);
+                       evaluators[i].attachToEnvironment(env, cache, i);
                }
                
        }
index b0c34fd78a01ff87e3669fa1b6c795a4d5443ce9..a1b06ad17e5f0e71e0701d60e74c0a74536682dd 100644 (file)
@@ -203,7 +203,7 @@ final class EvaluationCache {
                        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;
                        }
index 724cf2cf2bbfd26ca7d281a2cb59c8a4888631a2..cf334454bdd15415aacea20f4d82993db5e6bc7f 100644 (file)
@@ -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;
@@ -94,6 +95,7 @@ public final class WorkbookEvaluator {
                _cache = new EvaluationCache(evaluationListener);
                _sheetIndexesBySheet = new IdentityHashMap();
                _collaboratingWorkbookEnvironment = CollaboratingWorkbooksEnvironment.EMPTY;
+               _workbookIx = 0;
        }
 
        /**
@@ -111,9 +113,10 @@ public final class WorkbookEvaluator {
                        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;
@@ -122,6 +125,7 @@ public final class WorkbookEvaluator {
        /* package */ void detachFromEnvironment() {
                _collaboratingWorkbookEnvironment = CollaboratingWorkbooksEnvironment.EMPTY;
                _cache = new EvaluationCache(_evaluationListener);
+               _workbookIx = 0;
        }
        /* package */ IEvaluationListener getEvaluationListener() {
                return _evaluationListener;
@@ -148,7 +152,7 @@ public final class WorkbookEvaluator {
                        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);
 
        }
        /**
@@ -157,7 +161,7 @@ public final class WorkbookEvaluator {
         */
        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) {
@@ -175,7 +179,7 @@ public final class WorkbookEvaluator {
 
        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));
        }
 
@@ -471,8 +475,11 @@ public final class WorkbookEvaluator {
                } 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);
+       }
 }