org.apache.poi.ss.formula.eval.forked
Class ForkedEvaluator

java.lang.Object
  extended by org.apache.poi.ss.formula.eval.forked.ForkedEvaluator

public final class ForkedEvaluator
extends java.lang.Object

An alternative workbook evaluator that saves memory in situations where a single workbook is concurrently and independently evaluated many times. With standard formula evaluation, around 90% of memory consumption is due to loading of the HSSFWorkbook or XSSFWorkbook. This class enables a 'master workbook' to be loaded just once and shared between many evaluation clients. Each evaluation client creates its own ForkedEvaluator and can set cell values that will be used for local evaluations (and don't disturb evaluations on other evaluators).


Method Summary
 void copyUpdatedCells(Workbook workbook)
          Copies the values of all updated cells (modified by calls to updateCell(String, int, int, ValueEval)) to the supplied workbook.
Typically, the supplied workbook is a writable copy of the 'master workbook', but at the very least it must contain sheets with the same names.
static ForkedEvaluator create(Workbook wb, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder)
           
 ValueEval evaluate(java.lang.String sheetName, int rowIndex, int columnIndex)
          If cell contains a formula, the formula is evaluated and returned, else the CellValue simply copies the appropriate cell value from the cell and also its cell type.
static void setupEnvironment(java.lang.String[] workbookNames, ForkedEvaluator[] evaluators)
          Coordinates several formula evaluators together so that formulas that involve external references can be evaluated.
 void updateCell(java.lang.String sheetName, int rowIndex, int columnIndex, ValueEval value)
          Sets the specified cell to the supplied value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static ForkedEvaluator create(Workbook wb,
                                     IStabilityClassifier stabilityClassifier,
                                     UDFFinder udfFinder)
Parameters:
udfFinder - pass null for default (AnalysisToolPak only)

updateCell

public void updateCell(java.lang.String sheetName,
                       int rowIndex,
                       int columnIndex,
                       ValueEval value)
Sets the specified cell to the supplied value

Parameters:
sheetName - the name of the sheet containing the cell
rowIndex - zero based
columnIndex - zero based

copyUpdatedCells

public void copyUpdatedCells(Workbook workbook)
Copies the values of all updated cells (modified by calls to updateCell(String, int, int, ValueEval)) to the supplied workbook.
Typically, the supplied workbook is a writable copy of the 'master workbook', but at the very least it must contain sheets with the same names.


evaluate

public ValueEval evaluate(java.lang.String sheetName,
                          int rowIndex,
                          int columnIndex)
If cell contains a formula, the formula is evaluated and returned, else the CellValue simply copies the appropriate cell value from the cell and also its cell type. This method should be preferred over evaluateInCell() when the call should not modify the contents of the original cell.

Parameters:
sheetName - the name of the sheet containing the cell
rowIndex - zero based
columnIndex - zero based
Returns:
null if the supplied cell is null or blank

setupEnvironment

public static void setupEnvironment(java.lang.String[] workbookNames,
                                    ForkedEvaluator[] evaluators)
Coordinates several formula evaluators together so that formulas that involve external references can be evaluated.

Parameters:
workbookNames - the simple file names used to identify the workbooks in formulas with external links (for example "MyData.xls" as used in a formula "[MyData.xls]Sheet1!A1")
evaluators - all evaluators for the full set of workbooks required by the formulas.