You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2022/01/06 00:07:46 UTC

[commons-math] 04/04: Remove comparator.

This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit 468d81714d98f502bca97ac20d764149df1432a3
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Thu Jan 6 01:04:31 2022 +0100

    Remove comparator.
    
    Its usage is unnecessary within the library.
---
 .../apache/commons/math4/neuralnet/Network.java    | 33 ++--------------------
 .../commons/math4/neuralnet/NetworkTest.java       |  2 +-
 2 files changed, 4 insertions(+), 31 deletions(-)

diff --git a/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/Network.java b/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/Network.java
index 8a21bb4..b018261 100644
--- a/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/Network.java
+++ b/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/Network.java
@@ -24,7 +24,6 @@ import java.util.Set;
 import java.util.HashSet;
 import java.util.Collection;
 import java.util.Iterator;
-import java.util.Comparator;
 import java.util.Collections;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -56,23 +55,6 @@ public class Network
         = new ConcurrentHashMap<>();
 
     /**
-     * Comparator that prescribes an order of the neurons according
-     * to the increasing order of their identifier.
-     */
-    public static class NeuronIdentifierComparator
-        implements Comparator<Neuron> {
-        /** {@inheritDoc} */
-        @Override
-        public int compare(Neuron a,
-                           Neuron b) {
-            final long aId = a.getIdentifier();
-            final long bId = b.getIdentifier();
-            return aId < bId ? -1 :
-                aId > bId ? 1 : 0;
-        }
-    }
-
-    /**
      * @param firstId Identifier of the first neuron that will be added
      * to this network.
      * @param featureSize Size of the neuron's features.
@@ -162,19 +144,10 @@ public class Network
     }
 
     /**
-     * Creates a list of the neurons, sorted in a custom order.
-     *
-     * @param comparator {@link Comparator} used for sorting the neurons.
-     * @return a list of neurons, sorted in the order prescribed by the
-     * given {@code comparator}.
-     * @see NeuronIdentifierComparator
+     * @return a shallow copy of the network's neurons.
      */
-    public Collection<Neuron> getNeurons(Comparator<Neuron> comparator) {
-        final List<Neuron> neurons = new ArrayList<>(neuronMap.values());
-
-        Collections.sort(neurons, comparator);
-
-        return neurons;
+    public Collection<Neuron> getNeurons() {
+        return Collections.unmodifiableCollection(neuronMap.values());
     }
 
     /**
diff --git a/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/NetworkTest.java b/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/NetworkTest.java
index 88154fc..5342124 100644
--- a/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/NetworkTest.java
+++ b/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/NetworkTest.java
@@ -118,7 +118,7 @@ public class NetworkTest {
         // Check that the comparator provides a specific order.
         boolean isUnspecifiedOrder = false;
         long previousId = Long.MIN_VALUE;
-        for (Neuron n : net.getNeurons(new Network.NeuronIdentifierComparator())) {
+        for (Neuron n : net.getNeurons()) {
             final long currentId = n.getIdentifier();
             if (currentId < previousId) {
                 isUnspecifiedOrder = true;