From 468d81714d98f502bca97ac20d764149df1432a3 Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Thu, 6 Jan 2022 01:04:31 +0100 Subject: [PATCH] Remove comparator. Its usage is unnecessary within the library. --- .../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 8a21bb4f4..b01826147 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; @@ -55,23 +54,6 @@ public class Network private final ConcurrentHashMap> linkMap = new ConcurrentHashMap<>(); - /** - * Comparator that prescribes an order of the neurons according - * to the increasing order of their identifier. - */ - public static class NeuronIdentifierComparator - implements Comparator { - /** {@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. @@ -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 getNeurons(Comparator comparator) { - final List neurons = new ArrayList<>(neuronMap.values()); - - Collections.sort(neurons, comparator); - - return neurons; + public Collection 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 88154fc23..53421242e 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;