poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dno...@apache.org
Subject svn commit: r1701055 - in /poi/trunk/src/java/org/apache/poi/ss/formula: eval/FunctionEval.java functions/DGet.java functions/DMin.java functions/DStarRunner.java functions/IDStarAlgorithm.java
Date Thu, 03 Sep 2015 15:58:00 GMT
Author: dnorth
Date: Thu Sep  3 15:58:00 2015
New Revision: 1701055

URL: http://svn.apache.org/r1701055
Log:
Make D* functions thread safe, thanks to Patrick Zimmermann for the patch.

https://bz.apache.org/bugzilla/show_bug.cgi?id=58039

Modified:
    poi/trunk/src/java/org/apache/poi/ss/formula/eval/FunctionEval.java
    poi/trunk/src/java/org/apache/poi/ss/formula/functions/DGet.java
    poi/trunk/src/java/org/apache/poi/ss/formula/functions/DMin.java
    poi/trunk/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java
    poi/trunk/src/java/org/apache/poi/ss/formula/functions/IDStarAlgorithm.java

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/eval/FunctionEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/eval/FunctionEval.java?rev=1701055&r1=1701054&r2=1701055&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/eval/FunctionEval.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/eval/FunctionEval.java Thu Sep  3 15:58:00
2015
@@ -98,7 +98,7 @@ public final class FunctionEval {
         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;
@@ -191,7 +191,7 @@ public final class FunctionEval {
         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
 

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/DGet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/DGet.java?rev=1701055&r1=1701054&r2=1701055&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/DGet.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/DGet.java Thu Sep  3 15:58:00 2015
@@ -23,18 +23,11 @@ import org.apache.poi.ss.formula.eval.Va
 /**
  * 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.
         {
@@ -49,6 +42,7 @@ public final class DGet implements IDSta
         return true;
     }
 
+    @Override
     public ValueEval getResult() {
         if(result == null) {
             return ErrorEval.VALUE_INVALID;

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/DMin.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/DMin.java?rev=1701055&r1=1701054&r2=1701055&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/DMin.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/DMin.java Thu Sep  3 15:58:00 2015
@@ -32,10 +32,7 @@ import org.apache.poi.ss.formula.eval.Va
 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.
@@ -52,6 +49,7 @@ public final class DMin implements IDSta
         return true;
     }
 
+    @Override
     public ValueEval getResult() {
         if(minimumValue == null) {
             return NumberEval.ZERO;

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java?rev=1701055&r1=1701054&r2=1701055&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java Thu Sep  3 15:58:00
2015
@@ -32,12 +32,21 @@ import org.apache.poi.ss.util.NumberComp
  * 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)
{
@@ -69,10 +78,14 @@ public final class DStarRunner implement
             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 {

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/IDStarAlgorithm.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/IDStarAlgorithm.java?rev=1701055&r1=1701054&r2=1701055&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/IDStarAlgorithm.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/IDStarAlgorithm.java Thu Sep  3
15:58:00 2015
@@ -25,11 +25,6 @@ import org.apache.poi.ss.formula.eval.Va
  */
 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.
      * @return Whether we should continue iterating through the database.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message