Use Map.merge
This commit is contained in:
parent
7ed772e474
commit
9fcd3885dc
|
@ -80,11 +80,7 @@ public class EnumeratedIntegerDistribution extends AbstractIntegerDistribution {
|
||||||
public EnumeratedIntegerDistribution(final int[] data) {
|
public EnumeratedIntegerDistribution(final int[] data) {
|
||||||
final Map<Integer, Integer> dataMap = new HashMap<>();
|
final Map<Integer, Integer> dataMap = new HashMap<>();
|
||||||
for (int value : data) {
|
for (int value : data) {
|
||||||
Integer count = dataMap.get(value);
|
dataMap.merge(value, 1, Integer::sum);
|
||||||
if (count == null) {
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
dataMap.put(value, ++count);
|
|
||||||
}
|
}
|
||||||
final int massPoints = dataMap.size();
|
final int massPoints = dataMap.size();
|
||||||
final double denom = data.length;
|
final double denom = data.length;
|
||||||
|
|
|
@ -82,11 +82,7 @@ public class EnumeratedRealDistribution
|
||||||
public EnumeratedRealDistribution(final double[] data) {
|
public EnumeratedRealDistribution(final double[] data) {
|
||||||
final Map<Double, Integer> dataMap = new HashMap<>();
|
final Map<Double, Integer> dataMap = new HashMap<>();
|
||||||
for (double value : data) {
|
for (double value : data) {
|
||||||
Integer count = dataMap.get(value);
|
dataMap.merge(value, 1, Integer::sum);
|
||||||
if (count == null) {
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
dataMap.put(value, ++count);
|
|
||||||
}
|
}
|
||||||
final int massPoints = dataMap.size();
|
final int massPoints = dataMap.size();
|
||||||
final double denom = data.length;
|
final double denom = data.length;
|
||||||
|
|
Loading…
Reference in New Issue