You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2015/11/03 13:19:48 UTC

[1/3] [math] Replaced use of inefficient keyset with use of entryset.

Repository: commons-math
Updated Branches:
  refs/heads/MATH_3_X b6c2d697a -> f0c6d3c0c


Replaced use of inefficient keyset with use of entryset.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/96723996
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/96723996
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/96723996

Branch: refs/heads/MATH_3_X
Commit: 96723996663a595cb1d491b09e0a1707a01dc5f0
Parents: b6c2d69
Author: Luc Maisonobe <lu...@apache.org>
Authored: Tue Nov 3 12:12:19 2015 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Tue Nov 3 12:12:19 2015 +0100

----------------------------------------------------------------------
 .../commons/math3/exception/util/ExceptionContext.java       | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/96723996/src/main/java/org/apache/commons/math3/exception/util/ExceptionContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/exception/util/ExceptionContext.java b/src/main/java/org/apache/commons/math3/exception/util/ExceptionContext.java
index a9fd95c..1a78bd3 100644
--- a/src/main/java/org/apache/commons/math3/exception/util/ExceptionContext.java
+++ b/src/main/java/org/apache/commons/math3/exception/util/ExceptionContext.java
@@ -283,12 +283,12 @@ public class ExceptionContext implements Serializable {
     private void serializeContext(ObjectOutputStream out)
         throws IOException {
         // Step 1.
-        final int len = context.keySet().size();
+        final int len = context.size();
         out.writeInt(len);
-        for (String key : context.keySet()) {
+        for (Map.Entry<String, Object> entry : context.entrySet()) {
             // Step 2.
-            out.writeObject(key);
-            final Object value = context.get(key);
+            out.writeObject(entry.getKey());
+            final Object value = entry.getValue();
             if (value instanceof Serializable) {
                 // Step 3a.
                 out.writeObject(value);


[3/3] [math] Fixed inconsistent synchronization.

Posted by lu...@apache.org.
Fixed inconsistent synchronization.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/f0c6d3c0
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/f0c6d3c0
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/f0c6d3c0

Branch: refs/heads/MATH_3_X
Commit: f0c6d3c0c564b82f4e02f183ce7409332155ac36
Parents: be8563a
Author: Luc Maisonobe <lu...@apache.org>
Authored: Tue Nov 3 12:22:46 2015 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Tue Nov 3 12:34:07 2015 +0100

----------------------------------------------------------------------
 .../math3/util/ResizableDoubleArray.java        | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/f0c6d3c0/src/main/java/org/apache/commons/math3/util/ResizableDoubleArray.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/util/ResizableDoubleArray.java b/src/main/java/org/apache/commons/math3/util/ResizableDoubleArray.java
index d49f6a8..89c42da 100644
--- a/src/main/java/org/apache/commons/math3/util/ResizableDoubleArray.java
+++ b/src/main/java/org/apache/commons/math3/util/ResizableDoubleArray.java
@@ -808,13 +808,15 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
      */
     @Deprecated
     public int getExpansionMode() {
-        switch (expansionMode) {
-        case MULTIPLICATIVE:
-            return MULTIPLICATIVE_MODE;
-        case ADDITIVE:
-            return ADDITIVE_MODE;
-        default:
-            throw new MathInternalError(); // Should never happen.
+        synchronized (this) {
+            switch (expansionMode) {
+                case MULTIPLICATIVE:
+                    return MULTIPLICATIVE_MODE;
+                case ADDITIVE:
+                    return ADDITIVE_MODE;
+                default:
+                    throw new MathInternalError(); // Should never happen.
+            }
         }
     }
 
@@ -1026,7 +1028,9 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
      */
     @Deprecated
     public void setExpansionMode(ExpansionMode expansionMode) {
-        this.expansionMode = expansionMode;
+        synchronized(this) {
+            this.expansionMode = expansionMode;
+        }
     }
 
     /**


[2/3] [math] Fixed findbugs warnings.

Posted by lu...@apache.org.
Fixed findbugs warnings.

The warnings were related to compareTo implementations not handling -0.0
or NaN properly (cf
<http://findbugs.sourceforge.net/bugDescriptions.html#CO_COMPARETO_INCORRECT_FLOATING>).

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/be8563a6
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/be8563a6
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/be8563a6

Branch: refs/heads/MATH_3_X
Commit: be8563a6c567cf521090239587e8f7034f69f72a
Parents: 9672399
Author: Luc Maisonobe <lu...@apache.org>
Authored: Tue Nov 3 12:21:08 2015 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Tue Nov 3 12:21:08 2015 +0100

----------------------------------------------------------------------
 .../commons/math3/fitting/GaussianCurveFitter.java   | 15 +++++++++------
 .../apache/commons/math3/fitting/GaussianFitter.java | 15 +++++++++------
 .../math3/optimization/fitting/GaussianFitter.java   | 15 +++++++++------
 3 files changed, 27 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/be8563a6/src/main/java/org/apache/commons/math3/fitting/GaussianCurveFitter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/fitting/GaussianCurveFitter.java b/src/main/java/org/apache/commons/math3/fitting/GaussianCurveFitter.java
index 64e0bda..9a4617b 100644
--- a/src/main/java/org/apache/commons/math3/fitting/GaussianCurveFitter.java
+++ b/src/main/java/org/apache/commons/math3/fitting/GaussianCurveFitter.java
@@ -260,22 +260,25 @@ public class GaussianCurveFitter extends AbstractCurveFitter {
                     if (p2 == null) {
                         return 1;
                     }
-                    if (p1.getX() < p2.getX()) {
+                    final int cmpX = Double.compare(p1.getX(), p2.getX());
+                    if (cmpX < 0) {
                         return -1;
                     }
-                    if (p1.getX() > p2.getX()) {
+                    if (cmpX > 0) {
                         return 1;
                     }
-                    if (p1.getY() < p2.getY()) {
+                    final int cmpY = Double.compare(p1.getY(), p2.getY());
+                    if (cmpY < 0) {
                         return -1;
                     }
-                    if (p1.getY() > p2.getY()) {
+                    if (cmpY > 0) {
                         return 1;
                     }
-                    if (p1.getWeight() < p2.getWeight()) {
+                    final int cmpW = Double.compare(p1.getWeight(), p2.getWeight());
+                    if (cmpW < 0) {
                         return -1;
                     }
-                    if (p1.getWeight() > p2.getWeight()) {
+                    if (cmpW > 0) {
                         return 1;
                     }
                     return 0;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/be8563a6/src/main/java/org/apache/commons/math3/fitting/GaussianFitter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/fitting/GaussianFitter.java b/src/main/java/org/apache/commons/math3/fitting/GaussianFitter.java
index 3946540..87c515b 100644
--- a/src/main/java/org/apache/commons/math3/fitting/GaussianFitter.java
+++ b/src/main/java/org/apache/commons/math3/fitting/GaussianFitter.java
@@ -194,22 +194,25 @@ public class GaussianFitter extends CurveFitter<Gaussian.Parametric> {
                     if (p2 == null) {
                         return 1;
                     }
-                    if (p1.getX() < p2.getX()) {
+                    final int cmpX = Double.compare(p1.getX(), p2.getX());
+                    if (cmpX < 0) {
                         return -1;
                     }
-                    if (p1.getX() > p2.getX()) {
+                    if (cmpX > 0) {
                         return 1;
                     }
-                    if (p1.getY() < p2.getY()) {
+                    final int cmpY = Double.compare(p1.getY(), p2.getY());
+                    if (cmpY < 0) {
                         return -1;
                     }
-                    if (p1.getY() > p2.getY()) {
+                    if (cmpY > 0) {
                         return 1;
                     }
-                    if (p1.getWeight() < p2.getWeight()) {
+                    final int cmpW = Double.compare(p1.getWeight(), p2.getWeight());
+                    if (cmpW < 0) {
                         return -1;
                     }
-                    if (p1.getWeight() > p2.getWeight()) {
+                    if (cmpW > 0) {
                         return 1;
                     }
                     return 0;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/be8563a6/src/main/java/org/apache/commons/math3/optimization/fitting/GaussianFitter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/optimization/fitting/GaussianFitter.java b/src/main/java/org/apache/commons/math3/optimization/fitting/GaussianFitter.java
index 1676496..b1bfe7d 100644
--- a/src/main/java/org/apache/commons/math3/optimization/fitting/GaussianFitter.java
+++ b/src/main/java/org/apache/commons/math3/optimization/fitting/GaussianFitter.java
@@ -195,22 +195,25 @@ public class GaussianFitter extends CurveFitter<Gaussian.Parametric> {
                     if (p2 == null) {
                         return 1;
                     }
-                    if (p1.getX() < p2.getX()) {
+                    final int cmpX = Double.compare(p1.getX(), p2.getX());
+                    if (cmpX < 0) {
                         return -1;
                     }
-                    if (p1.getX() > p2.getX()) {
+                    if (cmpX > 0) {
                         return 1;
                     }
-                    if (p1.getY() < p2.getY()) {
+                    final int cmpY = Double.compare(p1.getY(), p2.getY());
+                    if (cmpY < 0) {
                         return -1;
                     }
-                    if (p1.getY() > p2.getY()) {
+                    if (cmpY > 0) {
                         return 1;
                     }
-                    if (p1.getWeight() < p2.getWeight()) {
+                    final int cmpW = Double.compare(p1.getWeight(), p2.getWeight());
+                    if (cmpW < 0) {
                         return -1;
                     }
-                    if (p1.getWeight() > p2.getWeight()) {
+                    if (cmpW > 0) {
                         return 1;
                     }
                     return 0;