Example usage for org.apache.poi.ss.formula.functions IDStarAlgorithm processMatch

List of usage examples for org.apache.poi.ss.formula.functions IDStarAlgorithm processMatch

Introduction

In this page you can find the example usage for org.apache.poi.ss.formula.functions IDStarAlgorithm processMatch.

Prototype

boolean processMatch(ValueEval eval);

Source Link

Document

Process a match that is found during a run through a database.

Usage

From source file:nl.eur.ese.spreadsheettest.DStarRunner.java

License:Apache License

public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval database, ValueEval filterColumn,
        ValueEval conditionDatabase) {/*w  ww  .  j  ava  2  s.c  om*/
    // Input processing and error checks.
    if (!(database instanceof TwoDEval) || !(conditionDatabase instanceof TwoDEval)) {
        return ErrorEval.VALUE_INVALID;
    }
    TwoDEval db = (TwoDEval) database;
    TwoDEval cdb = (TwoDEval) conditionDatabase;

    int fc;
    try {
        fc = getColumnForName(filterColumn, db);
    } catch (EvaluationException e) {
        return ErrorEval.VALUE_INVALID;
    }
    if (fc == -1) { // column not found
        return ErrorEval.VALUE_INVALID;
    }

    // Create an algorithm runner.
    IDStarAlgorithm algorithm = fac.create();

    // Iterate over all DB entries.
    for (int row = 1; row < db.getHeight(); ++row) {
        boolean matches = true;
        try {
            matches = fullfillsConditions(db, row, cdb);
        } catch (EvaluationException e) {
            return ErrorEval.VALUE_INVALID;
        }
        // Filter each entry.
        if (matches) {
            try {
                ValueEval currentValueEval = solveReference(db.getValue(row, fc));
                // Pass the match to the algorithm and conditionally abort the search.
                boolean shouldContinue = algorithm.processMatch(currentValueEval);
                if (!shouldContinue) {
                    break;
                }
            } catch (EvaluationException e) {
                return e.getErrorEval();
            }
        }
    }

    // Return the result of the algorithm.
    return algorithm.getResult();
}