Search in sources :

Example 1 with IStabilityClassifier

use of org.apache.poi.ss.formula.IStabilityClassifier in project poi by apache.

the class TestForkedEvaluator method testBasic.

/**
	 * Shows a basic use-case for {@link ForkedEvaluator}
	 */
@Test
public void testBasic() throws IOException {
    Workbook wb = createWorkbook();
    // The stability classifier is useful to reduce memory consumption of caching logic
    IStabilityClassifier stabilityClassifier = new IStabilityClassifier() {

        @Override
        public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
            return sheetIndex == 1;
        }
    };
    ForkedEvaluator fe1 = ForkedEvaluator.create(wb, stabilityClassifier, null);
    ForkedEvaluator fe2 = ForkedEvaluator.create(wb, stabilityClassifier, null);
    // fe1 and fe2 can be used concurrently on separate threads
    fe1.updateCell("Inputs", 0, 0, new NumberEval(4.0));
    fe1.updateCell("Inputs", 0, 1, new NumberEval(1.1));
    fe2.updateCell("Inputs", 0, 0, new NumberEval(1.2));
    fe2.updateCell("Inputs", 0, 1, new NumberEval(2.0));
    assertEquals(18.9, ((NumberEval) fe1.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0);
    assertEquals(4.0, ((NumberEval) fe2.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0);
    fe1.updateCell("Inputs", 0, 0, new NumberEval(3.0));
    assertEquals(13.9, ((NumberEval) fe1.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0);
    wb.close();
}
Also used : IStabilityClassifier(org.apache.poi.ss.formula.IStabilityClassifier) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 2 with IStabilityClassifier

use of org.apache.poi.ss.formula.IStabilityClassifier in project poi by apache.

the class TestDec2Bin method createContext.

private OperationEvaluationContext createContext() {
    HSSFWorkbook wb = new HSSFWorkbook();
    Sheet sheet = wb.createSheet();
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    cell.setCellValue("13.43");
    cell = row.createCell(1);
    cell.setCellValue("8");
    cell = row.createCell(2);
    cell.setCellValue("-8");
    cell = row.createCell(3);
    cell.setCellValue("1");
    HSSFEvaluationWorkbook workbook = HSSFEvaluationWorkbook.create(wb);
    WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, new IStabilityClassifier() {

        @Override
        public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
            return true;
        }
    }, null);
    OperationEvaluationContext ctx = new OperationEvaluationContext(workbookEvaluator, workbook, 0, 0, 0, null);
    return ctx;
}
Also used : IStabilityClassifier(org.apache.poi.ss.formula.IStabilityClassifier) WorkbookEvaluator(org.apache.poi.ss.formula.WorkbookEvaluator) OperationEvaluationContext(org.apache.poi.ss.formula.OperationEvaluationContext) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFEvaluationWorkbook(org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook)

Example 3 with IStabilityClassifier

use of org.apache.poi.ss.formula.IStabilityClassifier in project poi by apache.

the class TestBin2Dec method createContext.

private OperationEvaluationContext createContext() {
    HSSFWorkbook wb = new HSSFWorkbook();
    wb.createSheet();
    HSSFEvaluationWorkbook workbook = HSSFEvaluationWorkbook.create(wb);
    WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, new IStabilityClassifier() {

        @Override
        public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
            return true;
        }
    }, null);
    OperationEvaluationContext ctx = new OperationEvaluationContext(workbookEvaluator, workbook, 0, 0, 0, null);
    return ctx;
}
Also used : IStabilityClassifier(org.apache.poi.ss.formula.IStabilityClassifier) WorkbookEvaluator(org.apache.poi.ss.formula.WorkbookEvaluator) OperationEvaluationContext(org.apache.poi.ss.formula.OperationEvaluationContext) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFEvaluationWorkbook(org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook)

Example 4 with IStabilityClassifier

use of org.apache.poi.ss.formula.IStabilityClassifier in project poi by apache.

the class TestHex2Dec method createContext.

private OperationEvaluationContext createContext() {
    HSSFWorkbook wb = new HSSFWorkbook();
    wb.createSheet();
    HSSFEvaluationWorkbook workbook = HSSFEvaluationWorkbook.create(wb);
    WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, new IStabilityClassifier() {

        @Override
        public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
            return true;
        }
    }, null);
    OperationEvaluationContext ctx = new OperationEvaluationContext(workbookEvaluator, workbook, 0, 0, 0, null);
    return ctx;
}
Also used : IStabilityClassifier(org.apache.poi.ss.formula.IStabilityClassifier) WorkbookEvaluator(org.apache.poi.ss.formula.WorkbookEvaluator) OperationEvaluationContext(org.apache.poi.ss.formula.OperationEvaluationContext) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFEvaluationWorkbook(org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook)

Example 5 with IStabilityClassifier

use of org.apache.poi.ss.formula.IStabilityClassifier in project poi by apache.

the class TestDec2Hex method createContext.

private OperationEvaluationContext createContext() {
    HSSFWorkbook wb = new HSSFWorkbook();
    Sheet sheet = wb.createSheet();
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    cell.setCellValue("123.43");
    cell = row.createCell(1);
    cell.setCellValue("8");
    cell = row.createCell(2);
    cell.setCellValue("-8");
    HSSFEvaluationWorkbook workbook = HSSFEvaluationWorkbook.create(wb);
    WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, new IStabilityClassifier() {

        @Override
        public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
            return true;
        }
    }, null);
    OperationEvaluationContext ctx = new OperationEvaluationContext(workbookEvaluator, workbook, 0, 0, 0, null);
    return ctx;
}
Also used : IStabilityClassifier(org.apache.poi.ss.formula.IStabilityClassifier) WorkbookEvaluator(org.apache.poi.ss.formula.WorkbookEvaluator) OperationEvaluationContext(org.apache.poi.ss.formula.OperationEvaluationContext) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFEvaluationWorkbook(org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook)

Aggregations

HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)5 IStabilityClassifier (org.apache.poi.ss.formula.IStabilityClassifier)5 HSSFEvaluationWorkbook (org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook)4 OperationEvaluationContext (org.apache.poi.ss.formula.OperationEvaluationContext)4 WorkbookEvaluator (org.apache.poi.ss.formula.WorkbookEvaluator)4 Cell (org.apache.poi.ss.usermodel.Cell)2 Row (org.apache.poi.ss.usermodel.Row)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 Test (org.junit.Test)1