retval[38] = BooleanFunction.NOT;
retval[39] = NumericFunction.MOD;
- retval[43] = new DStarRunner(new DMin());
+ retval[43] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DMIN);
retval[46] = AggregateFunction.VAR;
retval[48] = TextFunction.TEXT;
retval[233] = NumericFunction.ACOSH;
retval[234] = NumericFunction.ATANH;
- retval[235] = new DStarRunner(new DGet());
+ retval[235] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DGET);
retval[FunctionID.EXTERNAL_FUNC] = null; // ExternalFunction is a FreeREfFunction
/**
* Implementation of the DGet function:
* Finds the value of a column in an area with given conditions.
- *
- * TODO:
- * - wildcards ? and * in string conditions
- * - functions as conditions
*/
public final class DGet implements IDStarAlgorithm {
private ValueEval result;
-
- public void reset() {
- result = null;
- }
+ @Override
public boolean processMatch(ValueEval eval) {
if(result == null) // First match, just set the value.
{
return true;
}
+ @Override
public ValueEval getResult() {
if(result == null) {
return ErrorEval.VALUE_INVALID;
public final class DMin implements IDStarAlgorithm {
private ValueEval minimumValue;
- public void reset() {
- minimumValue = null;
- }
-
+ @Override
public boolean processMatch(ValueEval eval) {
if(eval instanceof NumericValueEval) {
if(minimumValue == null) { // First match, just set the value.
return true;
}
+ @Override
public ValueEval getResult() {
if(minimumValue == null) {
return NumberEval.ZERO;
* This class performs a D* calculation. It takes an {@link IDStarAlgorithm} object and
* uses it for calculating the result value. Iterating a database and checking the
* entries against the set of conditions is done here.
+ *
+ * TODO:
+ * - wildcards ? and * in string conditions
+ * - functions as conditions
*/
public final class DStarRunner implements Function3Arg {
- private IDStarAlgorithm algorithm;
+ public enum DStarAlgorithmEnum {
+ DGET,
+ DMIN,
+ // DMAX, // DMAX is not yet implemented
+ }
+ private final DStarAlgorithmEnum algoType;
- public DStarRunner(IDStarAlgorithm algorithm) {
- this.algorithm = algorithm;
+ public DStarRunner(DStarAlgorithmEnum algorithm) {
+ this.algoType = algorithm;
}
public final ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
return ErrorEval.VALUE_INVALID;
}
- // Reset algorithm.
- algorithm.reset();
+ // Create an algorithm runner.
+ IDStarAlgorithm algorithm = null;
+ switch(algoType) {
+ case DGET: algorithm = new DGet(); break;
+ case DMIN: algorithm = new DMin(); break;
+ }
- // Iterate over all db entries.
+ // Iterate over all DB entries.
for(int row = 1; row < db.getHeight(); ++row) {
boolean matches = true;
try {
* Each implementing class should correspond to one of the D* functions.
*/
public interface IDStarAlgorithm {
- /**
- * Reset the state of this algorithm.
- * This is called before each run through a database.
- */
- void reset();
/**
* Process a match that is found during a run through a database.
* @param eval ValueEval of the cell in the matching row. References will already be resolved.