moved lazy ref creation methods to OperationEvaluationContext
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@882375 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f2b76afe66
commit
cf7f47fbe1
@ -31,6 +31,16 @@ public abstract class AreaEvalBase implements AreaEval {
|
||||
private final int _nColumns;
|
||||
private final int _nRows;
|
||||
|
||||
protected AreaEvalBase(int firstRow, int firstColumn, int lastRow, int lastColumn) {
|
||||
_firstColumn = firstColumn;
|
||||
_firstRow = firstRow;
|
||||
_lastColumn = lastColumn;
|
||||
_lastRow = lastRow;
|
||||
|
||||
_nColumns = _lastColumn - _firstColumn + 1;
|
||||
_nRows = _lastRow - _firstRow + 1;
|
||||
}
|
||||
|
||||
protected AreaEvalBase(AreaI ptg) {
|
||||
_firstRow = ptg.getFirstRow();
|
||||
_firstColumn = ptg.getFirstColumn();
|
||||
|
@ -32,11 +32,17 @@ final class LazyAreaEval extends AreaEvalBase {
|
||||
|
||||
private final SheetRefEvaluator _evaluator;
|
||||
|
||||
public LazyAreaEval(AreaI ptg, SheetRefEvaluator evaluator) {
|
||||
LazyAreaEval(AreaI ptg, SheetRefEvaluator evaluator) {
|
||||
super(ptg);
|
||||
_evaluator = evaluator;
|
||||
}
|
||||
|
||||
public LazyAreaEval(int firstRowIndex, int firstColumnIndex, int lastRowIndex,
|
||||
int lastColumnIndex, SheetRefEvaluator evaluator) {
|
||||
super(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex);
|
||||
_evaluator = evaluator;
|
||||
}
|
||||
|
||||
public ValueEval getRelativeValue(int relativeRowIndex, int relativeColumnIndex) {
|
||||
|
||||
int rowIx = (relativeRowIndex + getFirstRow() ) & 0xFFFF;
|
||||
|
@ -18,8 +18,6 @@
|
||||
package org.apache.poi.ss.formula;
|
||||
|
||||
import org.apache.poi.hssf.record.formula.AreaI;
|
||||
import org.apache.poi.hssf.record.formula.Ref3DPtg;
|
||||
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||
import org.apache.poi.hssf.record.formula.AreaI.OffsetArea;
|
||||
import org.apache.poi.hssf.record.formula.eval.AreaEval;
|
||||
import org.apache.poi.hssf.record.formula.eval.RefEvalBase;
|
||||
@ -41,12 +39,6 @@ final class LazyRefEval extends RefEvalBase {
|
||||
}
|
||||
_evaluator = sre;
|
||||
}
|
||||
public LazyRefEval(RefPtg ptg, SheetRefEvaluator sre) {
|
||||
this(ptg.getRow(), ptg.getColumn(), sre);
|
||||
}
|
||||
public LazyRefEval(Ref3DPtg ptg, SheetRefEvaluator sre) {
|
||||
this(ptg.getRow(), ptg.getColumn(), sre);
|
||||
}
|
||||
|
||||
public ValueEval getInnerValueEval() {
|
||||
return _evaluator.getEvalForCell(getRow(), getColumn());
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package org.apache.poi.ss.formula;
|
||||
|
||||
import org.apache.poi.hssf.record.formula.AreaI;
|
||||
import org.apache.poi.hssf.record.formula.eval.AreaEval;
|
||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
||||
import org.apache.poi.hssf.record.formula.eval.RefEval;
|
||||
@ -68,8 +67,10 @@ public final class OperationEvaluationContext {
|
||||
return _columnIndex;
|
||||
}
|
||||
|
||||
/* package */ SheetRefEvaluator createExternSheetRefEvaluator(ExternSheetReferenceToken ptg) {
|
||||
int externSheetIndex = ptg.getExternSheetIndex();
|
||||
SheetRefEvaluator createExternSheetRefEvaluator(ExternSheetReferenceToken ptg) {
|
||||
return createExternSheetRefEvaluator(ptg.getExternSheetIndex());
|
||||
}
|
||||
SheetRefEvaluator createExternSheetRefEvaluator(int externSheetIndex) {
|
||||
ExternalSheet externalSheet = _workbook.getExternalSheet(externSheetIndex);
|
||||
WorkbookEvaluator targetEvaluator;
|
||||
int otherSheetIndex;
|
||||
@ -212,7 +213,7 @@ public final class OperationEvaluationContext {
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected reference classification of '" + refStrPart1 + "'.");
|
||||
}
|
||||
return new LazyAreaEval(new AI(firstRow, firstCol, lastRow, lastCol), sre);
|
||||
return new LazyAreaEval(firstRow, firstCol, lastRow, lastCol, sre);
|
||||
}
|
||||
|
||||
private static int parseRowRef(String refStrPart) {
|
||||
@ -223,33 +224,6 @@ public final class OperationEvaluationContext {
|
||||
return Integer.parseInt(refStrPart) - 1;
|
||||
}
|
||||
|
||||
private static final class AI implements AreaI {
|
||||
|
||||
private final int _fr;
|
||||
private final int _lr;
|
||||
private final int _fc;
|
||||
private final int _lc;
|
||||
|
||||
public AI(int fr, int fc, int lr, int lc) {
|
||||
_fr = Math.min(fr, lr);
|
||||
_lr = Math.max(fr, lr);
|
||||
_fc = Math.min(fc, lc);
|
||||
_lc = Math.max(fc, lc);
|
||||
}
|
||||
public int getFirstColumn() {
|
||||
return _fc;
|
||||
}
|
||||
public int getFirstRow() {
|
||||
return _fr;
|
||||
}
|
||||
public int getLastColumn() {
|
||||
return _lc;
|
||||
}
|
||||
public int getLastRow() {
|
||||
return _lr;
|
||||
}
|
||||
}
|
||||
|
||||
private static NameType classifyCellReference(String str, SpreadsheetVersion ssVersion) {
|
||||
int len = str.length();
|
||||
if (len < 1) {
|
||||
@ -261,4 +235,23 @@ public final class OperationEvaluationContext {
|
||||
public FreeRefFunction findUserDefinedFunction(String functionName) {
|
||||
return _bookEvaluator.findUserDefinedFunction(functionName);
|
||||
}
|
||||
|
||||
public ValueEval getRefEval(int rowIndex, int columnIndex) {
|
||||
SheetRefEvaluator sre = getRefEvaluatorForCurrentSheet();
|
||||
return new LazyRefEval(rowIndex, columnIndex, sre);
|
||||
}
|
||||
public ValueEval getRef3DEval(int rowIndex, int columnIndex, int extSheetIndex) {
|
||||
SheetRefEvaluator sre = createExternSheetRefEvaluator(extSheetIndex);
|
||||
return new LazyRefEval(rowIndex, columnIndex, sre);
|
||||
}
|
||||
public ValueEval getAreaEval(int firstRowIndex, int firstColumnIndex,
|
||||
int lastRowIndex, int lastColumnIndex) {
|
||||
SheetRefEvaluator sre = getRefEvaluatorForCurrentSheet();
|
||||
return new LazyAreaEval(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex, sre);
|
||||
}
|
||||
public ValueEval getArea3DEval(int firstRowIndex, int firstColumnIndex,
|
||||
int lastRowIndex, int lastColumnIndex, int extSheetIndex) {
|
||||
SheetRefEvaluator sre = createExternSheetRefEvaluator(extSheetIndex);
|
||||
return new LazyAreaEval(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex, sre);
|
||||
}
|
||||
}
|
||||
|
@ -560,21 +560,20 @@ public final class WorkbookEvaluator {
|
||||
return ErrorEval.REF_INVALID;
|
||||
}
|
||||
if (ptg instanceof Ref3DPtg) {
|
||||
Ref3DPtg refPtg = (Ref3DPtg) ptg;
|
||||
SheetRefEvaluator sre = ec.createExternSheetRefEvaluator(refPtg);
|
||||
return new LazyRefEval(refPtg, sre);
|
||||
Ref3DPtg rptg = (Ref3DPtg) ptg;
|
||||
return ec.getRef3DEval(rptg.getRow(), rptg.getColumn(), rptg.getExternSheetIndex());
|
||||
}
|
||||
if (ptg instanceof Area3DPtg) {
|
||||
Area3DPtg aptg = (Area3DPtg) ptg;
|
||||
SheetRefEvaluator sre = ec.createExternSheetRefEvaluator(aptg);
|
||||
return new LazyAreaEval(aptg, sre);
|
||||
return ec.getArea3DEval(aptg.getFirstRow(), aptg.getFirstColumn(), aptg.getLastRow(), aptg.getLastColumn(), aptg.getExternSheetIndex());
|
||||
}
|
||||
SheetRefEvaluator sre = ec.getRefEvaluatorForCurrentSheet();
|
||||
if (ptg instanceof RefPtg) {
|
||||
return new LazyRefEval(((RefPtg) ptg), sre);
|
||||
RefPtg rptg = (RefPtg) ptg;
|
||||
return ec.getRefEval(rptg.getRow(), rptg.getColumn());
|
||||
}
|
||||
if (ptg instanceof AreaPtg) {
|
||||
return new LazyAreaEval(((AreaPtg) ptg), sre);
|
||||
AreaPtg aptg = (AreaPtg) ptg;
|
||||
return ec.getAreaEval(aptg.getFirstRow(), aptg.getFirstColumn(), aptg.getLastRow(), aptg.getLastColumn());
|
||||
}
|
||||
|
||||
if (ptg instanceof UnknownPtg) {
|
||||
|
Loading…
Reference in New Issue
Block a user