whitespace (tabs to spaces); +props svn:eol-style=native
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747839 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e3beb3abdd
commit
69ded5b7b0
@ -30,57 +30,57 @@ import org.apache.poi.ss.usermodel.Row;
|
|||||||
*/
|
*/
|
||||||
final class XSSFEvaluationSheet implements EvaluationSheet {
|
final class XSSFEvaluationSheet implements EvaluationSheet {
|
||||||
|
|
||||||
private final XSSFSheet _xs;
|
private final XSSFSheet _xs;
|
||||||
private Map<CellKey, EvaluationCell> _cellCache;
|
private Map<CellKey, EvaluationCell> _cellCache;
|
||||||
|
|
||||||
public XSSFEvaluationSheet(XSSFSheet sheet) {
|
public XSSFEvaluationSheet(XSSFSheet sheet) {
|
||||||
_xs = sheet;
|
_xs = sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XSSFSheet getXSSFSheet() {
|
public XSSFSheet getXSSFSheet() {
|
||||||
return _xs;
|
return _xs;
|
||||||
}
|
}
|
||||||
public EvaluationCell getCell(int rowIndex, int columnIndex) {
|
|
||||||
// cache for performance: ~30% speedup due to caching
|
public EvaluationCell getCell(int rowIndex, int columnIndex) {
|
||||||
if (_cellCache == null) {
|
// cache for performance: ~30% speedup due to caching
|
||||||
_cellCache = new HashMap<CellKey, EvaluationCell>(_xs.getLastRowNum()*3);
|
if (_cellCache == null) {
|
||||||
for (final Row row : _xs) {
|
_cellCache = new HashMap<CellKey, EvaluationCell>(_xs.getLastRowNum()*3);
|
||||||
final int rowNum = row.getRowNum();
|
for (final Row row : _xs) {
|
||||||
for (final Cell cell : row) {
|
final int rowNum = row.getRowNum();
|
||||||
// cast is safe, the iterator is just defined using the interface
|
for (final Cell cell : row) {
|
||||||
final CellKey key = new CellKey(rowNum, cell.getColumnIndex());
|
// cast is safe, the iterator is just defined using the interface
|
||||||
final EvaluationCell evalcell = new XSSFEvaluationCell((XSSFCell) cell, this);
|
final CellKey key = new CellKey(rowNum, cell.getColumnIndex());
|
||||||
_cellCache.put(key, evalcell);
|
final EvaluationCell evalcell = new XSSFEvaluationCell((XSSFCell) cell, this);
|
||||||
}
|
_cellCache.put(key, evalcell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return _cellCache.get(new CellKey(rowIndex, columnIndex));
|
|
||||||
|
return _cellCache.get(new CellKey(rowIndex, columnIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class CellKey {
|
private static class CellKey {
|
||||||
private final int _row;
|
private final int _row;
|
||||||
private final int _col;
|
private final int _col;
|
||||||
private final int _hash;
|
private final int _hash;
|
||||||
|
|
||||||
protected CellKey(int row, int col) {
|
protected CellKey(int row, int col) {
|
||||||
_row = row;
|
_row = row;
|
||||||
_col = col;
|
_col = col;
|
||||||
_hash = (17 * 37 + row) * 37 + col;
|
_hash = (17 * 37 + row) * 37 + col;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return _hash;
|
return _hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj == null) return false;
|
if (obj == null) return false;
|
||||||
// assumes other object is one of us, otherwise ClassCastException is thrown
|
// assumes other object is one of us, otherwise ClassCastException is thrown
|
||||||
final CellKey oKey = (CellKey) obj;
|
final CellKey oKey = (CellKey) obj;
|
||||||
return _row == oKey._row && _col == oKey._col;
|
return _row == oKey._row && _col == oKey._col;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user