Remove comparator.
Its usage is unnecessary within the library.
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.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 @@
= 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 @@
}
/**
- * 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 @@
// 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;