Begin required interface + base-class support for multi-sheet area references for #55906
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1613460 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
97c4bbc9b8
commit
2438213bd8
@ -25,30 +25,30 @@ import org.apache.poi.ss.formula.ptg.AreaI.OffsetArea;
|
||||
import org.apache.poi.ss.util.CellReference;
|
||||
|
||||
/**
|
||||
* Provides Lazy Evaluation to a 3D Ranges
|
||||
*
|
||||
* TODO Provide access to multiple sheets where present
|
||||
* Provides Lazy Evaluation to 3D Ranges
|
||||
*/
|
||||
final class LazyAreaEval extends AreaEvalBase {
|
||||
private final SheetRangeEvaluator _evaluator;
|
||||
|
||||
LazyAreaEval(AreaI ptg, SheetRangeEvaluator evaluator) {
|
||||
super(ptg);
|
||||
super(ptg, evaluator);
|
||||
_evaluator = evaluator;
|
||||
}
|
||||
|
||||
public LazyAreaEval(int firstRowIndex, int firstColumnIndex, int lastRowIndex,
|
||||
int lastColumnIndex, SheetRangeEvaluator evaluator) {
|
||||
super(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex);
|
||||
super(evaluator, firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex);
|
||||
_evaluator = evaluator;
|
||||
}
|
||||
|
||||
public ValueEval getRelativeValue(int relativeRowIndex, int relativeColumnIndex) {
|
||||
|
||||
public ValueEval getRelativeValue(int relativeRowIndex, int relativeColumnIndex) {
|
||||
return getRelativeValue(getFirstSheetIndex(), relativeRowIndex, relativeColumnIndex);
|
||||
}
|
||||
public ValueEval getRelativeValue(int sheetIndex, int relativeRowIndex, int relativeColumnIndex) {
|
||||
int rowIx = (relativeRowIndex + getFirstRow() ) ;
|
||||
int colIx = (relativeColumnIndex + getFirstColumn() ) ;
|
||||
|
||||
return _evaluator.getEvalForCell(_evaluator.getFirstSheetIndex(), rowIx, colIx);
|
||||
return _evaluator.getEvalForCell(sheetIndex, rowIx, colIx);
|
||||
}
|
||||
|
||||
public AreaEval offset(int relFirstRowIx, int relLastRowIx, int relFirstColIx, int relLastColIx) {
|
||||
|
36
src/java/org/apache/poi/ss/formula/ThreeDEval.java
Normal file
36
src/java/org/apache/poi/ss/formula/ThreeDEval.java
Normal file
@ -0,0 +1,36 @@
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.formula;
|
||||
|
||||
import org.apache.poi.ss.formula.eval.AreaEval;
|
||||
import org.apache.poi.ss.formula.eval.ValueEval;
|
||||
|
||||
/**
|
||||
* Optional Extension to the likes of {@link AreaEval} and
|
||||
* {@link org.apache.poi.ss.formula.eval.AreaEvalBase},
|
||||
* which allows for looking up 3D (sheet+row+column) evaluations
|
||||
*/
|
||||
public interface ThreeDEval extends TwoDEval, SheetRange {
|
||||
/**
|
||||
* @param sheetIndex sheet index (zero based)
|
||||
* @param rowIndex relative row index (zero based)
|
||||
* @param columnIndex relative column index (zero based)
|
||||
* @return element at the specified row and column position
|
||||
*/
|
||||
ValueEval getValue(int sheetIndex, int rowIndex, int columnIndex);
|
||||
}
|
@ -21,9 +21,8 @@ import org.apache.poi.ss.formula.eval.AreaEval;
|
||||
import org.apache.poi.ss.formula.eval.ValueEval;
|
||||
|
||||
/**
|
||||
* Common interface of {@link AreaEval} and {@link org.apache.poi.ss.formula.eval.AreaEvalBase}
|
||||
*
|
||||
* @author Josh Micich
|
||||
* Common interface of {@link AreaEval} and {@link org.apache.poi.ss.formula.eval.AreaEvalBase},
|
||||
* for 2D (row+column) evaluations
|
||||
*/
|
||||
public interface TwoDEval extends ValueEval {
|
||||
|
||||
|
@ -17,12 +17,12 @@
|
||||
|
||||
package org.apache.poi.ss.formula.eval;
|
||||
|
||||
import org.apache.poi.ss.formula.ThreeDEval;
|
||||
import org.apache.poi.ss.formula.TwoDEval;
|
||||
/**
|
||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
||||
*
|
||||
* Evaluation of 2D (Row+Column) and 3D (Sheet+Row+Column) areas
|
||||
*/
|
||||
public interface AreaEval extends TwoDEval {
|
||||
public interface AreaEval extends TwoDEval, ThreeDEval {
|
||||
|
||||
/**
|
||||
* returns the 0-based index of the first row in
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package org.apache.poi.ss.formula.eval;
|
||||
|
||||
import org.apache.poi.ss.formula.SheetRange;
|
||||
import org.apache.poi.ss.formula.ptg.AreaI;
|
||||
|
||||
/**
|
||||
@ -24,14 +25,16 @@ import org.apache.poi.ss.formula.ptg.AreaI;
|
||||
*/
|
||||
public abstract class AreaEvalBase implements AreaEval {
|
||||
|
||||
private final int _firstSheet;
|
||||
private final int _firstColumn;
|
||||
private final int _firstRow;
|
||||
private final int _lastSheet;
|
||||
private final int _lastColumn;
|
||||
private final int _lastRow;
|
||||
private final int _nColumns;
|
||||
private final int _nRows;
|
||||
|
||||
protected AreaEvalBase(int firstRow, int firstColumn, int lastRow, int lastColumn) {
|
||||
protected AreaEvalBase(SheetRange sheets, int firstRow, int firstColumn, int lastRow, int lastColumn) {
|
||||
_firstColumn = firstColumn;
|
||||
_firstRow = firstRow;
|
||||
_lastColumn = lastColumn;
|
||||
@ -39,16 +42,24 @@ public abstract class AreaEvalBase implements AreaEval {
|
||||
|
||||
_nColumns = _lastColumn - _firstColumn + 1;
|
||||
_nRows = _lastRow - _firstRow + 1;
|
||||
|
||||
if (sheets != null) {
|
||||
_firstSheet = sheets.getFirstSheetIndex();
|
||||
_lastSheet = sheets.getLastSheetIndex();
|
||||
} else {
|
||||
_firstSheet = -1;
|
||||
_lastSheet = -1;
|
||||
}
|
||||
}
|
||||
protected AreaEvalBase(int firstRow, int firstColumn, int lastRow, int lastColumn) {
|
||||
this(null, firstRow, firstColumn, lastRow, lastColumn);
|
||||
}
|
||||
|
||||
protected AreaEvalBase(AreaI ptg) {
|
||||
_firstRow = ptg.getFirstRow();
|
||||
_firstColumn = ptg.getFirstColumn();
|
||||
_lastRow = ptg.getLastRow();
|
||||
_lastColumn = ptg.getLastColumn();
|
||||
|
||||
_nColumns = _lastColumn - _firstColumn + 1;
|
||||
_nRows = _lastRow - _firstRow + 1;
|
||||
this(ptg, null);
|
||||
}
|
||||
protected AreaEvalBase(AreaI ptg, SheetRange sheets) {
|
||||
this(sheets, ptg.getFirstRow(), ptg.getFirstColumn(), ptg.getLastRow(), ptg.getLastColumn());
|
||||
}
|
||||
|
||||
public final int getFirstColumn() {
|
||||
@ -66,7 +77,15 @@ public abstract class AreaEvalBase implements AreaEval {
|
||||
public final int getLastRow() {
|
||||
return _lastRow;
|
||||
}
|
||||
public final ValueEval getAbsoluteValue(int row, int col) {
|
||||
|
||||
public int getFirstSheetIndex() {
|
||||
return _firstSheet;
|
||||
}
|
||||
public int getLastSheetIndex() {
|
||||
return _lastSheet;
|
||||
}
|
||||
|
||||
public final ValueEval getAbsoluteValue(int row, int col) {
|
||||
int rowOffsetIx = row - _firstRow;
|
||||
int colOffsetIx = col - _firstColumn;
|
||||
|
||||
@ -108,8 +127,12 @@ public abstract class AreaEvalBase implements AreaEval {
|
||||
public final ValueEval getValue(int row, int col) {
|
||||
return getRelativeValue(row, col);
|
||||
}
|
||||
public final ValueEval getValue(int sheetIndex, int row, int col) {
|
||||
return getRelativeValue(sheetIndex, row, col);
|
||||
}
|
||||
|
||||
public abstract ValueEval getRelativeValue(int relativeRowIndex, int relativeColumnIndex);
|
||||
public abstract ValueEval getRelativeValue(int sheetIndex, int relativeRowIndex, int relativeColumnIndex);
|
||||
|
||||
public int getWidth() {
|
||||
return _lastColumn-_firstColumn+1;
|
||||
|
Loading…
Reference in New Issue
Block a user