poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r882375 - in /poi/trunk/src/java/org/apache/poi: hssf/record/formula/eval/AreaEvalBase.java ss/formula/LazyAreaEval.java ss/formula/LazyRefEval.java ss/formula/OperationEvaluationContext.java ss/formula/WorkbookEvaluator.java
Date Fri, 20 Nov 2009 01:13:17 GMT
Author: josh
Date: Fri Nov 20 01:13:17 2009
New Revision: 882375

URL: http://svn.apache.org/viewvc?rev=882375&view=rev
Log:
moved lazy ref creation methods to OperationEvaluationContext

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/AreaEvalBase.java
    poi/trunk/src/java/org/apache/poi/ss/formula/LazyAreaEval.java
    poi/trunk/src/java/org/apache/poi/ss/formula/LazyRefEval.java
    poi/trunk/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java
    poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/AreaEvalBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/AreaEvalBase.java?rev=882375&r1=882374&r2=882375&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/AreaEvalBase.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/AreaEvalBase.java Fri Nov 20
01:13:17 2009
@@ -31,12 +31,22 @@
 	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();
 		_lastRow = ptg.getLastRow();
 		_lastColumn = ptg.getLastColumn();
-		
+
 		_nColumns = _lastColumn - _firstColumn + 1;
 		_nRows = _lastRow - _firstRow + 1;
 	}
@@ -60,20 +70,20 @@
 	public final ValueEval getValueAt(int row, int col) {
 		int rowOffsetIx = row - _firstRow;
 		int colOffsetIx = col - _firstColumn;
-		
+
 		if(rowOffsetIx < 0 || rowOffsetIx >= _nRows) {
-			throw new IllegalArgumentException("Specified row index (" + row 
+			throw new IllegalArgumentException("Specified row index (" + row
 					+ ") is outside the allowed range (" + _firstRow + ".." + _lastRow + ")");
 		}
 		if(colOffsetIx < 0 || colOffsetIx >= _nColumns) {
-			throw new IllegalArgumentException("Specified column index (" + col 
+			throw new IllegalArgumentException("Specified column index (" + col
 					+ ") is outside the allowed range (" + _firstColumn + ".." + col + ")");
 		}
 		return getRelativeValue(rowOffsetIx, colOffsetIx);
 	}
 
 	public final boolean contains(int row, int col) {
-		return _firstRow <= row && _lastRow >= row 
+		return _firstRow <= row && _lastRow >= row
 			&& _firstColumn <= col && _lastColumn >= col;
 	}
 

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/LazyAreaEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/LazyAreaEval.java?rev=882375&r1=882374&r2=882375&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/LazyAreaEval.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/LazyAreaEval.java Fri Nov 20 01:13:17 2009
@@ -26,22 +26,28 @@
 
 /**
  *
- * @author Josh Micich 
+ * @author Josh Micich
  */
 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 ValueEval getRelativeValue(int relativeRowIndex, int relativeColumnIndex) { 
-		
+	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;
 		int colIx = (relativeColumnIndex + getFirstColumn() ) & 0x00FF;
-		
+
 		return _evaluator.getEvalForCell(rowIx, colIx);
 	}
 

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/LazyRefEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/LazyRefEval.java?rev=882375&r1=882374&r2=882375&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/LazyRefEval.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/LazyRefEval.java Fri Nov 20 01:13:17 2009
@@ -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 @@
 		}
 		_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());

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java?rev=882375&r1=882374&r2=882375&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java Fri Nov 20
01:13:17 2009
@@ -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 @@
 		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 @@
 			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 @@
 		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 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);
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java?rev=882375&r1=882374&r2=882375&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java Fri Nov 20 01:13:17
2009
@@ -560,21 +560,20 @@
 				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) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message