use of org.apache.poi.ss.formula.eval.StringValueEval in project poi by apache.
the class MultiOperandNumericFunction method collectValue.
private void collectValue(ValueEval ve, boolean isViaReference, DoubleList temp) throws EvaluationException {
if (ve == null) {
throw new IllegalArgumentException("ve must not be null");
}
if (ve instanceof BoolEval) {
if (!isViaReference || _isReferenceBoolCounted) {
BoolEval boolEval = (BoolEval) ve;
temp.add(boolEval.getNumberValue());
}
return;
}
if (ve instanceof NumericValueEval) {
NumericValueEval ne = (NumericValueEval) ve;
temp.add(ne.getNumberValue());
return;
}
if (ve instanceof StringValueEval) {
if (isViaReference) {
// ignore all ref strings
return;
}
String s = ((StringValueEval) ve).getStringValue();
Double d = OperandResolver.parseDouble(s);
if (d == null) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
temp.add(d.doubleValue());
return;
}
if (ve instanceof ErrorEval) {
throw new EvaluationException((ErrorEval) ve);
}
if (ve == BlankEval.instance) {
if (_isBlankCounted) {
temp.add(0.0);
}
return;
}
throw new RuntimeException("Invalid ValueEval type passed for conversion: (" + ve.getClass() + ")");
}
use of org.apache.poi.ss.formula.eval.StringValueEval in project poi by apache.
the class DStarRunner method fullfillsConditions.
/**
* Checks a row in a database against a condition database.
*
* @param db Database.
* @param row The row in the database to check.
* @param cdb The condition database to use for checking.
* @return Whether the row matches the conditions.
* @throws EvaluationException If references could not be resolved or comparison
* operators and operands didn't match.
*/
private static boolean fullfillsConditions(AreaEval db, int row, AreaEval cdb) throws EvaluationException {
// Only one row must match to accept the input, so rows are ORed.
// Each row is made up of cells where each cell is a condition,
// all have to match, so they are ANDed.
final int height = cdb.getHeight();
for (int conditionRow = 1; conditionRow < height; ++conditionRow) {
boolean matches = true;
final int width = cdb.getWidth();
for (int column = 0; column < width; ++column) {
// columns are ANDed
// Whether the condition column matches a database column, if not it's a
// special column that accepts formulas.
boolean columnCondition = true;
ValueEval condition = null;
// The condition to apply.
condition = resolveReference(cdb, conditionRow, column);
// If the condition is empty it matches.
if (condition instanceof BlankEval)
continue;
// The column in the DB to apply the condition to.
ValueEval targetHeader = resolveReference(cdb, 0, column);
if (!(targetHeader instanceof StringValueEval)) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
if (getColumnForName(targetHeader, db) == -1)
// No column found, it's again a special column that accepts formulas.
columnCondition = false;
if (columnCondition == true) {
// normal column condition
// Should not throw, checked above.
ValueEval value = resolveReference(db, row, getColumnForName(targetHeader, db));
if (!testNormalCondition(value, condition)) {
matches = false;
break;
}
} else {
// TODO: Check whether the condition cell contains a formula and return #VALUE! if it doesn't.
if (OperandResolver.coerceValueToString(condition).isEmpty()) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
throw new NotImplementedException("D* function with formula conditions");
}
}
if (matches == true) {
return true;
}
}
return false;
}
Aggregations