Use a "static" instance rather than an anonymous one instantiated

on-the-fly.
This commit is contained in:
Luc Maisonobe 2015-11-04 14:51:03 +01:00
parent 4a1708d2e1
commit fff5c35b27
1 changed files with 14 additions and 16 deletions

View File

@ -20,9 +20,9 @@ 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;
import java.util.Comparator;
import org.apache.commons.math3.exception.NoDataException;
import org.apache.commons.math3.ml.distance.DistanceMeasure;
@ -137,13 +137,7 @@ public class MapUtils {
list.add(new PairNeuronDouble(n, d));
}
Collections.sort(list, new Comparator<PairNeuronDouble>() {
/** {@inheritDoc} */
@Override
public int compare(final PairNeuronDouble pn1, final PairNeuronDouble pn2) {
return Double.compare(pn1.getValue(), pn2.getValue());
}
});
Collections.sort(list, PairNeuronDouble.COMPARATOR);
final int len = list.size();
final Neuron[] sorted = new Neuron[len];
@ -300,9 +294,19 @@ public class MapUtils {
* Helper data structure holding a (Neuron, double) pair.
*/
private static class PairNeuronDouble {
/** Key */
/** Comparator. */
static final Comparator<PairNeuronDouble> COMPARATOR
= new Comparator<PairNeuronDouble>() {
/** {@inheritDoc} */
@Override
public int compare(PairNeuronDouble o1,
PairNeuronDouble o2) {
return Double.compare(o1.value, o2.value);
}
};
/** Key. */
private final Neuron neuron;
/** Value */
/** Value. */
private final double value;
/**
@ -319,11 +323,5 @@ public class MapUtils {
return neuron;
}
/** @return the value. */
public double getValue() {
return value;
}
}
}