View | Details | Raw Unified | Return to bug 58039
Collapse All | Expand All

(-)a/src/java/org/apache/poi/ss/formula/eval/FunctionEval.java (-2 / +2 lines)
Lines 98-104 public final class FunctionEval { Link Here
98
        retval[38] = BooleanFunction.NOT;
98
        retval[38] = BooleanFunction.NOT;
99
        retval[39] = NumericFunction.MOD;
99
        retval[39] = NumericFunction.MOD;
100
100
101
        retval[43] = new DStarRunner(new DMin());
101
        retval[43] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DMIN);
102
102
103
        retval[46] = AggregateFunction.VAR;
103
        retval[46] = AggregateFunction.VAR;
104
        retval[48] = TextFunction.TEXT;
104
        retval[48] = TextFunction.TEXT;
Lines 191-197 public final class FunctionEval { Link Here
191
        retval[233] = NumericFunction.ACOSH;
191
        retval[233] = NumericFunction.ACOSH;
192
        retval[234] = NumericFunction.ATANH;
192
        retval[234] = NumericFunction.ATANH;
193
193
194
        retval[235] = new DStarRunner(new DGet());
194
        retval[235] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DGET);
195
195
196
        retval[FunctionID.EXTERNAL_FUNC] = null; // ExternalFunction is a FreeREfFunction
196
        retval[FunctionID.EXTERNAL_FUNC] = null; // ExternalFunction is a FreeREfFunction
197
197
(-)a/src/java/org/apache/poi/ss/formula/functions/DGet.java (-8 / +2 lines)
Lines 23-40 import org.apache.poi.ss.formula.eval.ValueEval; Link Here
23
/**
23
/**
24
 * Implementation of the DGet function:
24
 * Implementation of the DGet function:
25
 * Finds the value of a column in an area with given conditions.
25
 * Finds the value of a column in an area with given conditions.
26
 * 
27
 * TODO:
28
 * - wildcards ? and * in string conditions
29
 * - functions as conditions
30
 */
26
 */
31
public final class DGet implements IDStarAlgorithm {
27
public final class DGet implements IDStarAlgorithm {
32
    private ValueEval result;
28
    private ValueEval result;
33
    
34
    public void reset() {
35
        result = null;
36
    }
37
29
30
    @Override
38
    public boolean processMatch(ValueEval eval) {
31
    public boolean processMatch(ValueEval eval) {
39
        if(result == null) // First match, just set the value.
32
        if(result == null) // First match, just set the value.
40
        {
33
        {
Lines 49-54 public final class DGet implements IDStarAlgorithm { Link Here
49
        return true;
42
        return true;
50
    }
43
    }
51
44
45
    @Override
52
    public ValueEval getResult() {
46
    public ValueEval getResult() {
53
        if(result == null) {
47
        if(result == null) {
54
            return ErrorEval.VALUE_INVALID;
48
            return ErrorEval.VALUE_INVALID;
(-)a/src/java/org/apache/poi/ss/formula/functions/DMin.java (-4 / +2 lines)
Lines 32-41 import org.apache.poi.ss.formula.eval.ValueEval; Link Here
32
public final class DMin implements IDStarAlgorithm {
32
public final class DMin implements IDStarAlgorithm {
33
    private ValueEval minimumValue;
33
    private ValueEval minimumValue;
34
34
35
    public void reset() {
35
    @Override
36
        minimumValue = null;
37
    }
38
39
    public boolean processMatch(ValueEval eval) {
36
    public boolean processMatch(ValueEval eval) {
40
        if(eval instanceof NumericValueEval) {
37
        if(eval instanceof NumericValueEval) {
41
            if(minimumValue == null) { // First match, just set the value.
38
            if(minimumValue == null) { // First match, just set the value.
Lines 52-57 public final class DMin implements IDStarAlgorithm { Link Here
52
        return true;
49
        return true;
53
    }
50
    }
54
51
52
    @Override
55
    public ValueEval getResult() {
53
    public ValueEval getResult() {
56
        if(minimumValue == null) {
54
        if(minimumValue == null) {
57
            return NumberEval.ZERO;
55
            return NumberEval.ZERO;
(-)a/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java (-6 / +19 lines)
Lines 32-43 import org.apache.poi.ss.util.NumberComparer; Link Here
32
 * This class performs a D* calculation. It takes an {@link IDStarAlgorithm} object and
32
 * This class performs a D* calculation. It takes an {@link IDStarAlgorithm} object and
33
 * uses it for calculating the result value. Iterating a database and checking the
33
 * uses it for calculating the result value. Iterating a database and checking the
34
 * entries against the set of conditions is done here.
34
 * entries against the set of conditions is done here.
35
 *
36
 * TODO:
37
 * - wildcards ? and * in string conditions
38
 * - functions as conditions
35
 */
39
 */
36
public final class DStarRunner implements Function3Arg {
40
public final class DStarRunner implements Function3Arg {
37
    private IDStarAlgorithm algorithm;
41
    public enum DStarAlgorithmEnum {
42
        DGET,
43
        DMIN,
44
        // DMAX, // DMAX is not yet implemented
45
    }
46
    private final DStarAlgorithmEnum algoType;
38
47
39
    public DStarRunner(IDStarAlgorithm algorithm) {
48
    public DStarRunner(DStarAlgorithmEnum algorithm) {
40
        this.algorithm = algorithm;
49
        this.algoType = algorithm;
41
    }
50
    }
42
51
43
    public final ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
52
    public final ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
Lines 69-78 public final class DStarRunner implements Function3Arg { Link Here
69
            return ErrorEval.VALUE_INVALID;
78
            return ErrorEval.VALUE_INVALID;
70
        }
79
        }
71
80
72
        // Reset algorithm.
81
        // Create an algorithm runner.
73
        algorithm.reset();
82
        IDStarAlgorithm algorithm = null;
83
        switch(algoType) {
84
        case DGET: algorithm = new DGet(); break;
85
        case DMIN: algorithm = new DMin(); break;
86
        }
74
87
75
        // Iterate over all db entries.
88
        // Iterate over all DB entries.
76
        for(int row = 1; row < db.getHeight(); ++row) {
89
        for(int row = 1; row < db.getHeight(); ++row) {
77
            boolean matches = true;
90
            boolean matches = true;
78
            try {
91
            try {
(-)a/src/java/org/apache/poi/ss/formula/functions/IDStarAlgorithm.java (-5 lines)
Lines 25-35 import org.apache.poi.ss.formula.eval.ValueEval; Link Here
25
 */
25
 */
26
public interface IDStarAlgorithm {
26
public interface IDStarAlgorithm {
27
    /**
27
    /**
28
     * Reset the state of this algorithm.
29
     * This is called before each run through a database.
30
     */
31
    void reset();
32
    /**
33
     * Process a match that is found during a run through a database.
28
     * Process a match that is found during a run through a database.
34
     * @param eval ValueEval of the cell in the matching row. References will already be resolved.
29
     * @param eval ValueEval of the cell in the matching row. References will already be resolved.
35
     * @return Whether we should continue iterating through the database.
30
     * @return Whether we should continue iterating through the database.

Return to bug 58039