View | Details | Raw Unified | Return to bug 57840
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java (-9 / +41 lines)
Lines 17-24 Link Here
17
17
18
package org.apache.poi.xssf.usermodel;
18
package org.apache.poi.xssf.usermodel;
19
19
20
import java.util.HashMap;
21
import java.util.Map;
22
20
import org.apache.poi.ss.formula.EvaluationCell;
23
import org.apache.poi.ss.formula.EvaluationCell;
21
import org.apache.poi.ss.formula.EvaluationSheet;
24
import org.apache.poi.ss.formula.EvaluationSheet;
25
import org.apache.poi.ss.usermodel.Cell;
26
import org.apache.poi.ss.usermodel.Row;
22
27
23
/**
28
/**
24
 * XSSF wrapper for a sheet under evaluation
29
 * XSSF wrapper for a sheet under evaluation
Lines 26-31 Link Here
26
final class XSSFEvaluationSheet implements EvaluationSheet {
31
final class XSSFEvaluationSheet implements EvaluationSheet {
27
32
28
	private final XSSFSheet _xs;
33
	private final XSSFSheet _xs;
34
	private Map<CellKey, EvaluationCell> _cellCache;
29
35
30
	public XSSFEvaluationSheet(XSSFSheet sheet) {
36
	public XSSFEvaluationSheet(XSSFSheet sheet) {
31
		_xs = sheet;
37
		_xs = sheet;
Lines 35-48 Link Here
35
		return _xs;
41
		return _xs;
36
	}
42
	}
37
	public EvaluationCell getCell(int rowIndex, int columnIndex) {
43
	public EvaluationCell getCell(int rowIndex, int columnIndex) {
38
		XSSFRow row = _xs.getRow(rowIndex);
44
	    if (_cellCache == null) {
39
		if (row == null) {
45
	        _cellCache = new HashMap<CellKey, EvaluationCell>(_xs.getLastRowNum()*3);
40
			return null;
46
	        for (Row row : _xs) {
41
		}
47
	            for (Cell cell : row) {
42
		XSSFCell cell = row.getCell(columnIndex);
48
	                // cast is safe, the iterator is just defined using the interface
43
		if (cell == null) {
49
	                _cellCache.put(new CellKey(row.getRowNum(), cell.getColumnIndex()), new XSSFEvaluationCell((XSSFCell) cell, this));
44
			return null;
50
	            }
45
		}
51
	        }
46
		return new XSSFEvaluationCell(cell, this);
52
	    }
53
	    
54
	    return _cellCache.get(new CellKey(rowIndex, columnIndex));
55
		
47
	}
56
	}
57
	
58
	private static class CellKey {
59
	    private final int _row;
60
	    private final int _col;
61
	    private final int _hash;
62
	    
63
	    protected CellKey(int row, int col) {
64
	        _row = row;
65
	        _col = col;
66
	        _hash = (17 * 37 + row) *37 + col;
67
	    }
68
	    
69
	    public int hashCode() {
70
	        return _hash;
71
	    }
72
	    
73
	    public boolean equals(Object obj) {
74
	        if (obj == null) return false;
75
	        // assumes other object is one of us
76
	        final CellKey oKey = (CellKey) obj;
77
	        return _row == oKey._row && _col == oKey._col;
78
	    }
79
	}
48
}
80
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java (-1 / +13 lines)
Lines 27-32 Link Here
27
 * Internal POI use only
27
 * Internal POI use only
28
 */
28
 */
29
public final class XSSFEvaluationWorkbook extends BaseXSSFEvaluationWorkbook {
29
public final class XSSFEvaluationWorkbook extends BaseXSSFEvaluationWorkbook {
30
    private XSSFEvaluationSheet[] _sheetCache;
31
    
30
    public static XSSFEvaluationWorkbook create(XSSFWorkbook book) {
32
    public static XSSFEvaluationWorkbook create(XSSFWorkbook book) {
31
        if (book == null) {
33
        if (book == null) {
32
            return null;
34
            return null;
Lines 46-52 Link Here
46
48
47
    @Override
49
    @Override
48
    public EvaluationSheet getSheet(int sheetIndex) {
50
    public EvaluationSheet getSheet(int sheetIndex) {
49
        return new XSSFEvaluationSheet(_uBook.getSheetAt(sheetIndex));
51
        if (_sheetCache == null) {
52
            _sheetCache = new XSSFEvaluationSheet[_uBook.getNumberOfSheets()];
53
            for (int i=0; i < _uBook.getNumberOfSheets(); i++) {
54
                _sheetCache[i] = new XSSFEvaluationSheet(_uBook.getSheetAt(i));
55
            }
56
        }
57
        if (sheetIndex < 0 || sheetIndex >= _sheetCache.length) {
58
            // do this to reuse the out-of-bounds logic and message from XSSFWorkbook
59
            _uBook.getSheetAt(sheetIndex);
60
        }
61
        return _sheetCache[sheetIndex];
50
    }
62
    }
51
63
52
    @Override    
64
    @Override    

Return to bug 57840