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/04 14:08:06 UTC

[math] PairNeuronDouble should not implement Comparable.

Repository: commons-math
Updated Branches:
  refs/heads/MATH_3_X 97b2e8dff -> 4a1708d2e


PairNeuronDouble should not implement Comparable.

As the purpose was only to sort neurons according to an associated
value, using an explicit comparator is simpler. Implementing Comparable
induces also implementing equals and hashcode which are not really
meaningful. They are nevertheless required by our code quality checking
tools.

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

Branch: refs/heads/MATH_3_X
Commit: 4a1708d2e180b25b310f664cfbdfa8434d7ce1c6
Parents: 97b2e8d
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Nov 4 14:07:22 2015 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Nov 4 14:07:22 2015 +0100

----------------------------------------------------------------------
 .../commons/math3/ml/neuralnet/MapUtils.java    | 33 ++++++--------------
 1 file changed, 10 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/4a1708d2/src/main/java/org/apache/commons/math3/ml/neuralnet/MapUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/ml/neuralnet/MapUtils.java b/src/main/java/org/apache/commons/math3/ml/neuralnet/MapUtils.java
index 6ef9327..afafa8b 100644
--- a/src/main/java/org/apache/commons/math3/ml/neuralnet/MapUtils.java
+++ b/src/main/java/org/apache/commons/math3/ml/neuralnet/MapUtils.java
@@ -20,6 +20,7 @@ package org.apache.commons.math3.ml.neuralnet;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 
@@ -136,7 +137,13 @@ public class MapUtils {
             list.add(new PairNeuronDouble(n, d));
         }
 
-        Collections.sort(list);
+        Collections.sort(list, new Comparator<PairNeuronDouble>() {
+            /** {@inheritDoc} */
+            @Override
+            public int compare(final PairNeuronDouble pn1, final PairNeuronDouble pn2) {
+                return Double.compare(pn1.getValue(), pn2.getValue());
+            }
+        });
 
         final int len = list.size();
         final Neuron[] sorted = new Neuron[len];
@@ -292,7 +299,7 @@ public class MapUtils {
     /**
      * Helper data structure holding a (Neuron, double) pair.
      */
-    private static class PairNeuronDouble implements Comparable<PairNeuronDouble> {
+    private static class PairNeuronDouble {
         /** Key */
         private final Neuron neuron;
         /** Value */
@@ -317,26 +324,6 @@ public class MapUtils {
             return value;
         }
 
-        /** {@inheritDoc} */
-        public int compareTo(PairNeuronDouble other) {
-            return Double.compare(this.value, other.value);
-        }
-
-        /** {@inheritDoc} */
-        @Override
-        public boolean equals(Object other) {
-            if (!(other instanceof PairNeuronDouble)) {
-                return false;
-            }
-            return Double.doubleToRawLongBits(value) ==
-                   Double.doubleToRawLongBits(((PairNeuronDouble) other).value);
-        }
-
-        /** {@inheritDoc} */
-        @Override
-        public int hashCode() {
-            return Double.valueOf(value).hashCode();
-        }
-
     }
+
 }