From b38ce47047020643166dc5eb4dd34cdc981fa12f Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Sun, 15 Nov 2015 10:56:43 -0700 Subject: [PATCH] Added @since tags, cleaned up code. JIRA: MATH-1287 --- .../distribution/EnumeratedIntegerDistribution.java | 11 +++++------ .../distribution/EnumeratedRealDistribution.java | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/apache/commons/math3/distribution/EnumeratedIntegerDistribution.java b/src/main/java/org/apache/commons/math3/distribution/EnumeratedIntegerDistribution.java index 9e29b66cf..399baad6b 100644 --- a/src/main/java/org/apache/commons/math3/distribution/EnumeratedIntegerDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/EnumeratedIntegerDistribution.java @@ -107,19 +107,17 @@ public class EnumeratedIntegerDistribution extends AbstractIntegerDistribution { * * @param rng random number generator used for sampling * @param data input dataset + * @since 3.6 */ public EnumeratedIntegerDistribution(final RandomGenerator rng, final int[] data) { super(rng); final Map dataMap = new HashMap(); - for (int value : data) { Integer count = dataMap.get(value); if (count == null) { - count = new Integer(1); - } else { - count = new Integer(count.intValue() + 1); + count = 0; } - dataMap.put(value, count); + dataMap.put(value, ++count); } final int massPoints = dataMap.size(); final double denom = data.length; @@ -140,6 +138,7 @@ public class EnumeratedIntegerDistribution extends AbstractIntegerDistribution { * with values 0, 1 and 2 having probability masses 0.25, 0.5 and 0.25 respectively, * * @param data input dataset + * @since 3.6 */ public EnumeratedIntegerDistribution(final int[] data) { this(new Well19937c(), data); @@ -152,7 +151,7 @@ public class EnumeratedIntegerDistribution extends AbstractIntegerDistribution { * @param probabilities probabilities * @return list of value/probability pairs */ - private List> createDistribution(int[] singletons, double[] probabilities) { + private static List> createDistribution(int[] singletons, double[] probabilities) { if (singletons.length != probabilities.length) { throw new DimensionMismatchException(probabilities.length, singletons.length); } diff --git a/src/main/java/org/apache/commons/math3/distribution/EnumeratedRealDistribution.java b/src/main/java/org/apache/commons/math3/distribution/EnumeratedRealDistribution.java index 2edb37509..7e95e8efb 100644 --- a/src/main/java/org/apache/commons/math3/distribution/EnumeratedRealDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/EnumeratedRealDistribution.java @@ -109,19 +109,17 @@ public class EnumeratedRealDistribution extends AbstractRealDistribution { * * @param rng random number generator used for sampling * @param data input dataset + * @since 3.6 */ public EnumeratedRealDistribution(final RandomGenerator rng, final double[] data) { super(rng); final Map dataMap = new HashMap(); - for (double value : data) { Integer count = dataMap.get(value); if (count == null) { - count = new Integer(1); - } else { - count = new Integer(count.intValue() + 1); + count = 0; } - dataMap.put(value, count); + dataMap.put(value, ++count); } final int massPoints = dataMap.size(); final double denom = data.length; @@ -142,6 +140,7 @@ public class EnumeratedRealDistribution extends AbstractRealDistribution { * with values 0, 1 and 2 having probability masses 0.25, 0.5 and 0.25 respectively, * * @param data input dataset + * @since 3.6 */ public EnumeratedRealDistribution(final double[] data) { this(new Well19937c(), data); @@ -153,7 +152,7 @@ public class EnumeratedRealDistribution extends AbstractRealDistribution { * @param probabilities probabilities * @return list of value/probability pairs */ - private List> createDistribution(double[] singletons, double[] probabilities) { + private static List> createDistribution(double[] singletons, double[] probabilities) { if (singletons.length != probabilities.length) { throw new DimensionMismatchException(probabilities.length, singletons.length); }