whitespace (tabs to spaces)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751838 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-07-07 22:29:28 +00:00
parent 9beb66309c
commit 40e715a54b
4 changed files with 193 additions and 193 deletions

View File

@ -25,30 +25,30 @@ import org.apache.poi.ss.formula.EvaluationSheet;
*/
final class HSSFEvaluationSheet implements EvaluationSheet {
private final HSSFSheet _hs;
private final HSSFSheet _hs;
public HSSFEvaluationSheet(HSSFSheet hs) {
_hs = hs;
}
public HSSFEvaluationSheet(HSSFSheet hs) {
_hs = hs;
}
public HSSFSheet getHSSFSheet() {
return _hs;
}
@Override
public EvaluationCell getCell(int rowIndex, int columnIndex) {
HSSFRow row = _hs.getRow(rowIndex);
if (row == null) {
return null;
}
HSSFCell cell = row.getCell(columnIndex);
if (cell == null) {
return null;
}
return new HSSFEvaluationCell(cell, this);
}
@Override
public void clearAllCachedResultValues() {
// nothing to do
}
public HSSFSheet getHSSFSheet() {
return _hs;
}
@Override
public EvaluationCell getCell(int rowIndex, int columnIndex) {
HSSFRow row = _hs.getRow(rowIndex);
if (row == null) {
return null;
}
HSSFCell cell = row.getCell(columnIndex);
if (cell == null) {
return null;
}
return new HSSFEvaluationCell(cell, this);
}
@Override
public void clearAllCachedResultValues() {
// nothing to do
}
}

View File

@ -26,11 +26,11 @@ package org.apache.poi.ss.formula;
*/
public interface EvaluationSheet {
/**
* @return <code>null</code> if there is no cell at the specified coordinates
*/
EvaluationCell getCell(int rowIndex, int columnIndex);
/**
* @return <code>null</code> if there is no cell at the specified coordinates
*/
EvaluationCell getCell(int rowIndex, int columnIndex);
/**
* Propagated from {@link EvaluationWorkbook#clearAllCachedResultValues()} to clear locally cached data.
*

View File

@ -39,109 +39,109 @@ import org.apache.poi.ss.util.CellReference;
*/
final class ForkedEvaluationSheet implements EvaluationSheet {
private final EvaluationSheet _masterSheet;
/**
* Only cells which have been split are put in this map. (This has been done to conserve memory).
*/
private final Map<RowColKey, ForkedEvaluationCell> _sharedCellsByRowCol;
private final EvaluationSheet _masterSheet;
/**
* Only cells which have been split are put in this map. (This has been done to conserve memory).
*/
private final Map<RowColKey, ForkedEvaluationCell> _sharedCellsByRowCol;
public ForkedEvaluationSheet(EvaluationSheet masterSheet) {
_masterSheet = masterSheet;
_sharedCellsByRowCol = new HashMap<RowColKey, ForkedEvaluationCell>();
}
public ForkedEvaluationSheet(EvaluationSheet masterSheet) {
_masterSheet = masterSheet;
_sharedCellsByRowCol = new HashMap<RowColKey, ForkedEvaluationCell>();
}
@Override
public EvaluationCell getCell(int rowIndex, int columnIndex) {
RowColKey key = new RowColKey(rowIndex, columnIndex);
@Override
public EvaluationCell getCell(int rowIndex, int columnIndex) {
RowColKey key = new RowColKey(rowIndex, columnIndex);
ForkedEvaluationCell result = _sharedCellsByRowCol.get(key);
if (result == null) {
return _masterSheet.getCell(rowIndex, columnIndex);
}
return result;
}
ForkedEvaluationCell result = _sharedCellsByRowCol.get(key);
if (result == null) {
return _masterSheet.getCell(rowIndex, columnIndex);
}
return result;
}
public ForkedEvaluationCell getOrCreateUpdatableCell(int rowIndex, int columnIndex) {
RowColKey key = new RowColKey(rowIndex, columnIndex);
public ForkedEvaluationCell getOrCreateUpdatableCell(int rowIndex, int columnIndex) {
RowColKey key = new RowColKey(rowIndex, columnIndex);
ForkedEvaluationCell result = _sharedCellsByRowCol.get(key);
if (result == null) {
EvaluationCell mcell = _masterSheet.getCell(rowIndex, columnIndex);
if (mcell == null) {
CellReference cr = new CellReference(rowIndex, columnIndex);
throw new UnsupportedOperationException("Underlying cell '"
+ cr.formatAsString() + "' is missing in master sheet.");
}
result = new ForkedEvaluationCell(this, mcell);
_sharedCellsByRowCol.put(key, result);
}
return result;
}
ForkedEvaluationCell result = _sharedCellsByRowCol.get(key);
if (result == null) {
EvaluationCell mcell = _masterSheet.getCell(rowIndex, columnIndex);
if (mcell == null) {
CellReference cr = new CellReference(rowIndex, columnIndex);
throw new UnsupportedOperationException("Underlying cell '"
+ cr.formatAsString() + "' is missing in master sheet.");
}
result = new ForkedEvaluationCell(this, mcell);
_sharedCellsByRowCol.put(key, result);
}
return result;
}
public void copyUpdatedCells(Sheet sheet) {
RowColKey[] keys = new RowColKey[_sharedCellsByRowCol.size()];
_sharedCellsByRowCol.keySet().toArray(keys);
Arrays.sort(keys);
for (int i = 0; i < keys.length; i++) {
RowColKey key = keys[i];
Row row = sheet.getRow(key.getRowIndex());
if (row == null) {
row = sheet.createRow(key.getRowIndex());
}
Cell destCell = row.getCell(key.getColumnIndex());
if (destCell == null) {
destCell = row.createCell(key.getColumnIndex());
}
public void copyUpdatedCells(Sheet sheet) {
RowColKey[] keys = new RowColKey[_sharedCellsByRowCol.size()];
_sharedCellsByRowCol.keySet().toArray(keys);
Arrays.sort(keys);
for (int i = 0; i < keys.length; i++) {
RowColKey key = keys[i];
Row row = sheet.getRow(key.getRowIndex());
if (row == null) {
row = sheet.createRow(key.getRowIndex());
}
Cell destCell = row.getCell(key.getColumnIndex());
if (destCell == null) {
destCell = row.createCell(key.getColumnIndex());
}
ForkedEvaluationCell srcCell = _sharedCellsByRowCol.get(key);
srcCell.copyValue(destCell);
}
}
ForkedEvaluationCell srcCell = _sharedCellsByRowCol.get(key);
srcCell.copyValue(destCell);
}
}
public int getSheetIndex(EvaluationWorkbook mewb) {
return mewb.getSheetIndex(_masterSheet);
}
public int getSheetIndex(EvaluationWorkbook mewb) {
return mewb.getSheetIndex(_masterSheet);
}
/* (non-Javadoc)
* leave the map alone, if it needs resetting, reusing this class is probably a bad idea.
* @see org.apache.poi.ss.formula.EvaluationSheet#clearAllCachedResultValues()
*/
@Override
public void clearAllCachedResultValues() {
_masterSheet.clearAllCachedResultValues();
}
/* (non-Javadoc)
* leave the map alone, if it needs resetting, reusing this class is probably a bad idea.
* @see org.apache.poi.ss.formula.EvaluationSheet#clearAllCachedResultValues()
*/
@Override
public void clearAllCachedResultValues() {
_masterSheet.clearAllCachedResultValues();
}
// FIXME: serves same purpose as org.apache.poi.xssf.usermodel.XSSFEvaluationSheet$CellKey
private static final class RowColKey implements Comparable<RowColKey>{
private final int _rowIndex;
private final int _columnIndex;
private static final class RowColKey implements Comparable<RowColKey>{
private final int _rowIndex;
private final int _columnIndex;
public RowColKey(int rowIndex, int columnIndex) {
_rowIndex = rowIndex;
_columnIndex = columnIndex;
}
@Override
public boolean equals(Object obj) {
assert obj instanceof RowColKey : "these private cache key instances are only compared to themselves";
RowColKey other = (RowColKey) obj;
return _rowIndex == other._rowIndex && _columnIndex == other._columnIndex;
}
@Override
public int hashCode() {
return _rowIndex ^ _columnIndex;
}
public int compareTo(RowColKey o) {
int cmp = _rowIndex - o._rowIndex;
if (cmp != 0) {
return cmp;
}
return _columnIndex - o._columnIndex;
}
public int getRowIndex() {
return _rowIndex;
}
public int getColumnIndex() {
return _columnIndex;
}
}
public RowColKey(int rowIndex, int columnIndex) {
_rowIndex = rowIndex;
_columnIndex = columnIndex;
}
@Override
public boolean equals(Object obj) {
assert obj instanceof RowColKey : "these private cache key instances are only compared to themselves";
RowColKey other = (RowColKey) obj;
return _rowIndex == other._rowIndex && _columnIndex == other._columnIndex;
}
@Override
public int hashCode() {
return _rowIndex ^ _columnIndex;
}
public int compareTo(RowColKey o) {
int cmp = _rowIndex - o._rowIndex;
if (cmp != 0) {
return cmp;
}
return _columnIndex - o._columnIndex;
}
public int getRowIndex() {
return _rowIndex;
}
public int getColumnIndex() {
return _columnIndex;
}
}
}

View File

@ -37,71 +37,71 @@ import org.apache.poi.ss.usermodel.Workbook;
*/
final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
private final EvaluationWorkbook _masterBook;
private final Map<String, ForkedEvaluationSheet> _sharedSheetsByName;
private final EvaluationWorkbook _masterBook;
private final Map<String, ForkedEvaluationSheet> _sharedSheetsByName;
public ForkedEvaluationWorkbook(EvaluationWorkbook master) {
_masterBook = master;
_sharedSheetsByName = new HashMap<String, ForkedEvaluationSheet>();
}
public ForkedEvaluationWorkbook(EvaluationWorkbook master) {
_masterBook = master;
_sharedSheetsByName = new HashMap<String, ForkedEvaluationSheet>();
}
public ForkedEvaluationCell getOrCreateUpdatableCell(String sheetName, int rowIndex,
int columnIndex) {
ForkedEvaluationSheet sheet = getSharedSheet(sheetName);
return sheet.getOrCreateUpdatableCell(rowIndex, columnIndex);
}
public ForkedEvaluationCell getOrCreateUpdatableCell(String sheetName, int rowIndex,
int columnIndex) {
ForkedEvaluationSheet sheet = getSharedSheet(sheetName);
return sheet.getOrCreateUpdatableCell(rowIndex, columnIndex);
}
public EvaluationCell getEvaluationCell(String sheetName, int rowIndex, int columnIndex) {
ForkedEvaluationSheet sheet = getSharedSheet(sheetName);
return sheet.getCell(rowIndex, columnIndex);
}
public EvaluationCell getEvaluationCell(String sheetName, int rowIndex, int columnIndex) {
ForkedEvaluationSheet sheet = getSharedSheet(sheetName);
return sheet.getCell(rowIndex, columnIndex);
}
private ForkedEvaluationSheet getSharedSheet(String sheetName) {
ForkedEvaluationSheet result = _sharedSheetsByName.get(sheetName);
if (result == null) {
result = new ForkedEvaluationSheet(_masterBook.getSheet(_masterBook
.getSheetIndex(sheetName)));
_sharedSheetsByName.put(sheetName, result);
}
return result;
}
private ForkedEvaluationSheet getSharedSheet(String sheetName) {
ForkedEvaluationSheet result = _sharedSheetsByName.get(sheetName);
if (result == null) {
result = new ForkedEvaluationSheet(_masterBook.getSheet(_masterBook
.getSheetIndex(sheetName)));
_sharedSheetsByName.put(sheetName, result);
}
return result;
}
public void copyUpdatedCells(Workbook workbook) {
public void copyUpdatedCells(Workbook workbook) {
String[] sheetNames = new String[_sharedSheetsByName.size()];
_sharedSheetsByName.keySet().toArray(sheetNames);
for (String sheetName : sheetNames) {
ForkedEvaluationSheet sheet = _sharedSheetsByName.get(sheetName);
sheet.copyUpdatedCells(workbook.getSheet(sheetName));
}
}
for (String sheetName : sheetNames) {
ForkedEvaluationSheet sheet = _sharedSheetsByName.get(sheetName);
sheet.copyUpdatedCells(workbook.getSheet(sheetName));
}
}
@Override
public int convertFromExternSheetIndex(int externSheetIndex) {
return _masterBook.convertFromExternSheetIndex(externSheetIndex);
}
public int convertFromExternSheetIndex(int externSheetIndex) {
return _masterBook.convertFromExternSheetIndex(externSheetIndex);
}
@Override
public ExternalSheet getExternalSheet(int externSheetIndex) {
return _masterBook.getExternalSheet(externSheetIndex);
}
public ExternalSheet getExternalSheet(int externSheetIndex) {
return _masterBook.getExternalSheet(externSheetIndex);
}
@Override
public ExternalSheet getExternalSheet(String firstSheetName, String lastSheetName, int externalWorkbookNumber) {
public ExternalSheet getExternalSheet(String firstSheetName, String lastSheetName, int externalWorkbookNumber) {
return _masterBook.getExternalSheet(firstSheetName, lastSheetName, externalWorkbookNumber);
}
@Override
public Ptg[] getFormulaTokens(EvaluationCell cell) {
if (cell instanceof ForkedEvaluationCell) {
// doesn't happen yet because formulas cannot be modified from the master workbook
throw new RuntimeException("Updated formulas not supported yet");
}
return _masterBook.getFormulaTokens(cell);
}
if (cell instanceof ForkedEvaluationCell) {
// doesn't happen yet because formulas cannot be modified from the master workbook
throw new RuntimeException("Updated formulas not supported yet");
}
return _masterBook.getFormulaTokens(cell);
}
@Override
public EvaluationName getName(NamePtg namePtg) {
return _masterBook.getName(namePtg);
}
public EvaluationName getName(NamePtg namePtg) {
return _masterBook.getName(namePtg);
}
@Override
public EvaluationName getName(String name, int sheetIndex){
@ -109,42 +109,42 @@ final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
}
@Override
public EvaluationSheet getSheet(int sheetIndex) {
return getSharedSheet(getSheetName(sheetIndex));
}
public EvaluationSheet getSheet(int sheetIndex) {
return getSharedSheet(getSheetName(sheetIndex));
}
@Override
public ExternalName getExternalName(int externSheetIndex, int externNameIndex) {
return _masterBook.getExternalName(externSheetIndex, externNameIndex);
}
public ExternalName getExternalName(int externSheetIndex, int externNameIndex) {
return _masterBook.getExternalName(externSheetIndex, externNameIndex);
}
@Override
public ExternalName getExternalName(String nameName, String sheetName, int externalWorkbookNumber) {
return _masterBook.getExternalName(nameName, sheetName, externalWorkbookNumber);
public ExternalName getExternalName(String nameName, String sheetName, int externalWorkbookNumber) {
return _masterBook.getExternalName(nameName, sheetName, externalWorkbookNumber);
}
@Override
public int getSheetIndex(EvaluationSheet sheet) {
if (sheet instanceof ForkedEvaluationSheet) {
ForkedEvaluationSheet mes = (ForkedEvaluationSheet) sheet;
return mes.getSheetIndex(_masterBook);
}
return _masterBook.getSheetIndex(sheet);
}
if (sheet instanceof ForkedEvaluationSheet) {
ForkedEvaluationSheet mes = (ForkedEvaluationSheet) sheet;
return mes.getSheetIndex(_masterBook);
}
return _masterBook.getSheetIndex(sheet);
}
@Override
public int getSheetIndex(String sheetName) {
return _masterBook.getSheetIndex(sheetName);
}
public int getSheetIndex(String sheetName) {
return _masterBook.getSheetIndex(sheetName);
}
@Override
public String getSheetName(int sheetIndex) {
return _masterBook.getSheetName(sheetIndex);
}
public String getSheetName(int sheetIndex) {
return _masterBook.getSheetName(sheetIndex);
}
@Override
public String resolveNameXText(NameXPtg ptg) {
return _masterBook.resolveNameXText(ptg);
}
public String resolveNameXText(NameXPtg ptg) {
return _masterBook.resolveNameXText(ptg);
}
@Override
public UDFFinder getUDFFinder() {