From f235e1c1d01d0697f08c911e841d7561ea1452b4 Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Fri, 14 Dec 2012 22:12:34 +0000 Subject: [PATCH] Replaced deprecated "RandomDataImpl" with "RandomDataGenerator". Added private constructor. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1422123 13f79535-47bb-0310-9956-ffa450edef68 --- .../math3/random/EmpiricalDistribution.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/apache/commons/math3/random/EmpiricalDistribution.java b/src/main/java/org/apache/commons/math3/random/EmpiricalDistribution.java index 3ac1333e7..02435dcdf 100644 --- a/src/main/java/org/apache/commons/math3/random/EmpiricalDistribution.java +++ b/src/main/java/org/apache/commons/math3/random/EmpiricalDistribution.java @@ -134,14 +134,14 @@ public class EmpiricalDistribution extends AbstractRealDistribution { /** upper bounds of subintervals in (0,1) "belonging" to the bins */ private double[] upperBounds = null; - /** RandomDataImpl instance to use in repeated calls to getNext() */ - private final RandomDataImpl randomData; + /** RandomDataGenerator instance to use in repeated calls to getNext() */ + private final RandomDataGenerator randomData; /** * Creates a new EmpiricalDistribution with the default bin count. */ public EmpiricalDistribution() { - this(DEFAULT_BIN_COUNT, new RandomDataImpl()); + this(DEFAULT_BIN_COUNT); } /** @@ -150,7 +150,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution { * @param binCount number of bins */ public EmpiricalDistribution(int binCount) { - this(binCount, new RandomDataImpl()); + this(binCount, new RandomDataGenerator()); } /** @@ -162,9 +162,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution { * @since 3.0 */ public EmpiricalDistribution(int binCount, RandomGenerator generator) { - this.binCount = binCount; - randomData = new RandomDataImpl(generator); - binStats = new ArrayList(); + this(binCount, new RandomDataGenerator(generator)); } /** @@ -189,9 +187,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution { */ @Deprecated public EmpiricalDistribution(int binCount, RandomDataImpl randomData) { - this.binCount = binCount; - this.randomData = randomData; - binStats = new ArrayList(); + this(binCount, randomData.getDelegate()); } /** @@ -207,7 +203,22 @@ public class EmpiricalDistribution extends AbstractRealDistribution { this(DEFAULT_BIN_COUNT, randomData); } - /** + /** + * Private constructor to allow lazy initialisation of the RNG contained + * in the {@link #randomData} instance variable. + * + * @param binCount number of bins + * @param randomData Random data generator. + */ + private EmpiricalDistribution(int binCount, + RandomDataGenerator randomData) { + super(null); + this.binCount = binCount; + this.randomData = randomData; + binStats = new ArrayList(); + } + + /** * Computes the empirical distribution from the provided * array of numbers. *