add @Override annotations to spreadsheet formula Evaluation classes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751837 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9539c626a9
commit
38c052cca1
@ -34,6 +34,7 @@ final class HSSFEvaluationSheet implements EvaluationSheet {
|
||||
public HSSFSheet getHSSFSheet() {
|
||||
return _hs;
|
||||
}
|
||||
@Override
|
||||
public EvaluationCell getCell(int rowIndex, int columnIndex) {
|
||||
HSSFRow row = _hs.getRow(rowIndex);
|
||||
if (row == null) {
|
||||
@ -46,6 +47,7 @@ final class HSSFEvaluationSheet implements EvaluationSheet {
|
||||
return new HSSFEvaluationCell(cell, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllCachedResultValues() {
|
||||
// nothing to do
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
|
||||
_iBook = book.getWorkbook();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllCachedResultValues() {
|
||||
// nothing to do
|
||||
}
|
||||
@ -73,18 +74,22 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
|
||||
return _uBook.createName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getExternalSheetIndex(String sheetName) {
|
||||
int sheetIndex = _uBook.getSheetIndex(sheetName);
|
||||
return _iBook.checkExternSheet(sheetIndex);
|
||||
}
|
||||
@Override
|
||||
public int getExternalSheetIndex(String workbookName, String sheetName) {
|
||||
return _iBook.getExternalSheetIndex(workbookName, sheetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ptg get3DReferencePtg(CellReference cr, SheetIdentifier sheet) {
|
||||
int extIx = getSheetExtIx(sheet);
|
||||
return new Ref3DPtg(cr, extIx);
|
||||
}
|
||||
@Override
|
||||
public Ptg get3DReferencePtg(AreaReference areaRef, SheetIdentifier sheet) {
|
||||
int extIx = getSheetExtIx(sheet);
|
||||
return new Area3DPtg(areaRef, extIx);
|
||||
@ -115,26 +120,33 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
|
||||
return sheetIndex == -1 ? null : getName(name, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSheetIndex(EvaluationSheet evalSheet) {
|
||||
HSSFSheet sheet = ((HSSFEvaluationSheet)evalSheet).getHSSFSheet();
|
||||
return _uBook.getSheetIndex(sheet);
|
||||
}
|
||||
@Override
|
||||
public int getSheetIndex(String sheetName) {
|
||||
return _uBook.getSheetIndex(sheetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSheetName(int sheetIndex) {
|
||||
return _uBook.getSheetName(sheetIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EvaluationSheet getSheet(int sheetIndex) {
|
||||
// TODO Cache these evaluation sheets so they aren't re-generated on every getSheet call
|
||||
return new HSSFEvaluationSheet(_uBook.getSheetAt(sheetIndex));
|
||||
}
|
||||
@Override
|
||||
public int convertFromExternSheetIndex(int externSheetIndex) {
|
||||
// TODO Update this to expose first and last sheet indexes
|
||||
return _iBook.getFirstSheetIndexFromExternSheetIndex(externSheetIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalSheet getExternalSheet(int externSheetIndex) {
|
||||
ExternalSheet sheet = _iBook.getExternalSheet(externSheetIndex);
|
||||
if (sheet == null) {
|
||||
@ -163,36 +175,52 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
|
||||
}
|
||||
return sheet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException: XSSF-style external references are not supported for HSSF
|
||||
*/
|
||||
@Override
|
||||
public ExternalSheet getExternalSheet(String firstSheetName, String lastSheetName, int externalWorkbookNumber) {
|
||||
throw new IllegalStateException("XSSF-style external references are not supported for HSSF");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalName getExternalName(int externSheetIndex, int externNameIndex) {
|
||||
return _iBook.getExternalName(externSheetIndex, externNameIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException: XSSF-style external names are not supported for HSSF
|
||||
*/
|
||||
@Override
|
||||
public ExternalName getExternalName(String nameName, String sheetName, int externalWorkbookNumber) {
|
||||
throw new IllegalStateException("XSSF-style external names are not supported for HSSF");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolveNameXText(NameXPtg n) {
|
||||
return _iBook.resolveNameXText(n.getSheetRefIndex(), n.getNameIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSheetFirstNameByExternSheet(int externSheetIndex) {
|
||||
return _iBook.findSheetFirstNameFromExternSheet(externSheetIndex);
|
||||
}
|
||||
@Override
|
||||
public String getSheetLastNameByExternSheet(int externSheetIndex) {
|
||||
return _iBook.findSheetLastNameFromExternSheet(externSheetIndex);
|
||||
}
|
||||
@Override
|
||||
public String getNameText(NamePtg namePtg) {
|
||||
return _iBook.getNameRecord(namePtg.getIndex()).getNameText();
|
||||
}
|
||||
@Override
|
||||
public EvaluationName getName(NamePtg namePtg) {
|
||||
int ix = namePtg.getIndex();
|
||||
return new Name(_iBook.getNameRecord(ix), ix);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unused")
|
||||
public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
|
||||
HSSFCell cell = ((HSSFEvaluationCell)evalCell).getHSSFCell();
|
||||
@ -213,6 +241,7 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
|
||||
return fra.getFormulaTokens();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UDFFinder getUDFFinder(){
|
||||
return _uBook.getUDFFinder();
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ final class ForkedEvaluationSheet implements EvaluationSheet {
|
||||
_sharedCellsByRowCol = new HashMap<RowColKey, ForkedEvaluationCell>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EvaluationCell getCell(int rowIndex, int columnIndex) {
|
||||
RowColKey key = new RowColKey(rowIndex, columnIndex);
|
||||
|
||||
@ -105,10 +106,12 @@ final class ForkedEvaluationSheet implements EvaluationSheet {
|
||||
* 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;
|
||||
|
@ -75,17 +75,21 @@ final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int convertFromExternSheetIndex(int externSheetIndex) {
|
||||
return _masterBook.convertFromExternSheetIndex(externSheetIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalSheet getExternalSheet(int externSheetIndex) {
|
||||
return _masterBook.getExternalSheet(externSheetIndex);
|
||||
}
|
||||
@Override
|
||||
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
|
||||
@ -94,25 +98,31 @@ final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
|
||||
return _masterBook.getFormulaTokens(cell);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EvaluationName getName(NamePtg namePtg) {
|
||||
return _masterBook.getName(namePtg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EvaluationName getName(String name, int sheetIndex){
|
||||
return _masterBook.getName(name, sheetIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EvaluationSheet getSheet(int sheetIndex) {
|
||||
return getSharedSheet(getSheetName(sheetIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSheetIndex(EvaluationSheet sheet) {
|
||||
if (sheet instanceof ForkedEvaluationSheet) {
|
||||
ForkedEvaluationSheet mes = (ForkedEvaluationSheet) sheet;
|
||||
@ -121,18 +131,22 @@ final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
|
||||
return _masterBook.getSheetIndex(sheet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSheetIndex(String sheetName) {
|
||||
return _masterBook.getSheetIndex(sheetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSheetName(int sheetIndex) {
|
||||
return _masterBook.getSheetName(sheetIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolveNameXText(NameXPtg ptg) {
|
||||
return _masterBook.resolveNameXText(ptg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UDFFinder getUDFFinder() {
|
||||
return _masterBook.getUDFFinder();
|
||||
}
|
||||
@ -141,6 +155,7 @@ final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
|
||||
* 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() {
|
||||
_masterBook.clearAllCachedResultValues();
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ final class SXSSFEvaluationSheet implements EvaluationSheet {
|
||||
public SXSSFSheet getSXSSFSheet() {
|
||||
return _xs;
|
||||
}
|
||||
@Override
|
||||
public EvaluationCell getCell(int rowIndex, int columnIndex) {
|
||||
SXSSFRow row = _xs.getRow(rowIndex);
|
||||
if (row == null) {
|
||||
@ -48,6 +49,7 @@ final class SXSSFEvaluationSheet implements EvaluationSheet {
|
||||
return new SXSSFEvaluationCell(cell, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllCachedResultValues() {
|
||||
// nothing to do
|
||||
}
|
||||
|
@ -52,10 +52,16 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
|
||||
public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWorkbook, EvaluationWorkbook, FormulaParsingWorkbook {
|
||||
protected final XSSFWorkbook _uBook;
|
||||
|
||||
// lazily populated. This should only be accessed through getTableCache
|
||||
// keys are lower-case to make this a quasi-case-insensitive map
|
||||
private Map<String, XSSFTable> _tableCache = null;
|
||||
|
||||
|
||||
protected BaseXSSFEvaluationWorkbook(XSSFWorkbook book) {
|
||||
_uBook = book;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllCachedResultValues() {
|
||||
_tableCache = null;
|
||||
}
|
||||
@ -67,6 +73,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
* XSSF doesn't use external sheet indexes, so when asked treat
|
||||
* it just as a local index
|
||||
*/
|
||||
@Override
|
||||
public int convertFromExternSheetIndex(int externSheetIndex) {
|
||||
return externSheetIndex;
|
||||
}
|
||||
@ -80,6 +87,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
return sheetIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getExternalSheetIndex(String sheetName) {
|
||||
int sheetIndex = _uBook.getSheetIndex(sheetName);
|
||||
return convertToExternalSheetIndex(sheetIndex);
|
||||
@ -121,7 +129,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
// Not properly referenced
|
||||
throw new RuntimeException("Book not linked for filename " + bookName);
|
||||
}
|
||||
/* case-sensitive */
|
||||
/* This is case-sensitive. Is that correct? */
|
||||
private int findExternalLinkIndex(String bookName, List<ExternalLinksTable> tables) {
|
||||
int i = 0;
|
||||
for (ExternalLinksTable table : tables) {
|
||||
@ -152,6 +160,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
* EvaluationName corresponding to that named range
|
||||
* Returns null if there is no named range with the same name and scope in the workbook
|
||||
*/
|
||||
@Override
|
||||
public EvaluationName getName(String name, int sheetIndex) {
|
||||
for (int i = 0; i < _uBook.getNumberOfNames(); i++) {
|
||||
XSSFName nm = _uBook.getNameAt(i);
|
||||
@ -165,14 +174,17 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
return sheetIndex == -1 ? null : getName(name, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSheetName(int sheetIndex) {
|
||||
return _uBook.getSheetName(sheetIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalName getExternalName(int externSheetIndex, int externNameIndex) {
|
||||
throw new IllegalStateException("HSSF-style external references are not supported for XSSF");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalName getExternalName(String nameName, String sheetName, int externalWorkbookNumber) {
|
||||
if (externalWorkbookNumber > 0) {
|
||||
// External reference - reference is 1 based, link table is 0 based
|
||||
@ -236,6 +248,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
return new NameXPxg(sheetName, name);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Ptg get3DReferencePtg(CellReference cell, SheetIdentifier sheet) {
|
||||
if (sheet._bookName != null) {
|
||||
int bookIndex = resolveBookIndex(sheet._bookName);
|
||||
@ -244,6 +257,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
return new Ref3DPxg(sheet, cell);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Ptg get3DReferencePtg(AreaReference area, SheetIdentifier sheet) {
|
||||
if (sheet._bookName != null) {
|
||||
int bookIndex = resolveBookIndex(sheet._bookName);
|
||||
@ -253,6 +267,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolveNameXText(NameXPtg n) {
|
||||
int idx = n.getNameIndex();
|
||||
String name = null;
|
||||
@ -271,9 +286,11 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalSheet getExternalSheet(int externSheetIndex) {
|
||||
throw new IllegalStateException("HSSF-style external references are not supported for XSSF");
|
||||
}
|
||||
@Override
|
||||
public ExternalSheet getExternalSheet(String firstSheetName, String lastSheetName, int externalWorkbookNumber) {
|
||||
String workbookName;
|
||||
if (externalWorkbookNumber > 0) {
|
||||
@ -297,22 +314,27 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
public int getExternalSheetIndex(String workbookName, String sheetName) {
|
||||
throw new RuntimeException("not implemented yet");
|
||||
}
|
||||
@Override
|
||||
public int getSheetIndex(String sheetName) {
|
||||
return _uBook.getSheetIndex(sheetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSheetFirstNameByExternSheet(int externSheetIndex) {
|
||||
int sheetIndex = convertFromExternalSheetIndex(externSheetIndex);
|
||||
return _uBook.getSheetName(sheetIndex);
|
||||
}
|
||||
@Override
|
||||
public String getSheetLastNameByExternSheet(int externSheetIndex) {
|
||||
// XSSF does multi-sheet references differently, so this is the same as the first
|
||||
return getSheetFirstNameByExternSheet(externSheetIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameText(NamePtg namePtg) {
|
||||
return _uBook.getNameAt(namePtg.getIndex()).getNameName();
|
||||
}
|
||||
@Override
|
||||
public EvaluationName getName(NamePtg namePtg) {
|
||||
int ix = namePtg.getIndex();
|
||||
return new Name(_uBook.getNameAt(ix), ix, this);
|
||||
@ -337,7 +359,6 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
*
|
||||
* Perhaps tables can be managed similar to PivotTable references above?
|
||||
*/
|
||||
private Map<String, XSSFTable> _tableCache = null;
|
||||
private Map<String, XSSFTable> getTableCache() {
|
||||
if ( _tableCache != null ) {
|
||||
return _tableCache;
|
||||
@ -371,10 +392,16 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
return getTableCache().get(lname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UDFFinder getUDFFinder(){
|
||||
return _uBook.getUDFFinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpreadsheetVersion getSpreadsheetVersion(){
|
||||
return SpreadsheetVersion.EXCEL2007;
|
||||
}
|
||||
|
||||
private static final class Name implements EvaluationName {
|
||||
|
||||
private final XSSFName _nameRecord;
|
||||
@ -414,8 +441,4 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
||||
return new NamePtg(_index);
|
||||
}
|
||||
}
|
||||
|
||||
public SpreadsheetVersion getSpreadsheetVersion(){
|
||||
return SpreadsheetVersion.EXCEL2007;
|
||||
}
|
||||
}
|
||||
|
@ -41,10 +41,12 @@ final class XSSFEvaluationSheet implements EvaluationSheet {
|
||||
return _xs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllCachedResultValues() {
|
||||
_cellCache = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EvaluationCell getCell(int rowIndex, int columnIndex) {
|
||||
// cache for performance: ~30% speedup due to caching
|
||||
if (_cellCache == null) {
|
||||
|
@ -40,6 +40,7 @@ public final class XSSFEvaluationWorkbook extends BaseXSSFEvaluationWorkbook {
|
||||
super(book);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllCachedResultValues() {
|
||||
super.clearAllCachedResultValues();
|
||||
_sheetCache = null;
|
||||
|
Loading…
Reference in New Issue
Block a user