diff --git a/src/main/java/org/apache/commons/math/random/RandomData.java b/src/main/java/org/apache/commons/math/random/RandomData.java index f39885170..9b492027a 100644 --- a/src/main/java/org/apache/commons/math/random/RandomData.java +++ b/src/main/java/org/apache/commons/math/random/RandomData.java @@ -18,9 +18,6 @@ package org.apache.commons.math.random; import java.util.Collection; -import org.apache.commons.math.exception.NotStrictlyPositiveException; -import org.apache.commons.math.exception.NumberIsTooLargeException; - /** * Random data generation utilities. * @version $Id$ @@ -36,9 +33,10 @@ public interface RandomData { * * @param len the length of the string to be generated * @return a random string of hex characters of length {@code len} - * @throws NotStrictlyPositiveException if {@code len <= 0} + * @throws org.apache.commons.math.exception.NotStrictlyPositiveException + * if {@code len <= 0} */ - String nextHexString(int len) throws NotStrictlyPositiveException; + String nextHexString(int len); /** * Generates a uniformly distributed random integer between {@code lower} @@ -53,9 +51,10 @@ public interface RandomData { * @param upper upper bound for generated integer * @return a random integer greater than or equal to {@code lower} * and less than or equal to {@code upper} - * @throws NumberIsTooLargeException if {@code lower >= upper} + * @throws org.apache.commons.math.exception.NumberIsTooLargeException + * if {@code lower >= upper} */ - int nextInt(int lower, int upper) throws NumberIsTooLargeException; + int nextInt(int lower, int upper); /** * Generates a uniformly distributed random long integer between @@ -70,9 +69,10 @@ public interface RandomData { * @param upper upper bound for generated long integer * @return a random long integer greater than or equal to {@code lower} and * less than or equal to {@code upper} - * @throws NumberIsTooLargeException if {@code lower >= upper}. + * @throws org.apache.commons.math.exception.NumberIsTooLargeException + * if {@code lower >= upper}. */ - long nextLong(long lower, long upper) throws NumberIsTooLargeException; + long nextLong(long lower, long upper); /** * Generates a random string of hex characters from a secure random @@ -84,9 +84,10 @@ public interface RandomData { * * @param len the length of the string to be generated * @return a random string of hex characters of length {@code len} - * @throws NotStrictlyPositiveException if {@code len <= 0} + * @throws org.apache.commons.math.exception.NotStrictlyPositiveException + * if {@code len <= 0} */ - String nextSecureHexString(int len) throws NotStrictlyPositiveException; + String nextSecureHexString(int len); /** * Generates a uniformly distributed random integer between {@code lower} @@ -104,9 +105,10 @@ public interface RandomData { * @param upper upper bound for generated integer * @return a random integer greater than or equal to {@code lower} and less * than or equal to {@code upper}. - * @throws NumberIsTooLargeException if {@code lower >= upper}. + * @throws org.apache.commons.math.exception.NumberIsTooLargeException + * if {@code lower >= upper}. */ - int nextSecureInt(int lower, int upper) throws NumberIsTooLargeException; + int nextSecureInt(int lower, int upper); /** * Generates a uniformly distributed random long integer between @@ -125,10 +127,10 @@ public interface RandomData { * @param upper upper bound for generated integer * @return a random long integer greater than or equal to {@code lower} and * less than or equal to {@code upper}. - * @throws NumberIsTooLargeException if {@code lower >= upper}. + * @throws org.apache.commons.math.exception.NumberIsTooLargeException + * if {@code lower >= upper}. */ - long nextSecureLong(long lower, long upper) - throws NumberIsTooLargeException; + long nextSecureLong(long lower, long upper); /** * Generates a random value from the Poisson distribution with the given @@ -140,9 +142,10 @@ public interface RandomData { * * @param mean the mean of the Poisson distribution * @return a random value following the specified Poisson distribution - * @throws NotStrictlyPositiveException if {@code mean <= 0}. + * @throws org.apache.commons.math.exception.NotStrictlyPositiveException + * if {@code mean <= 0}. */ - long nextPoisson(double mean) throws NotStrictlyPositiveException; + long nextPoisson(double mean); /** * Generates a random value from the Normal (or Gaussian) distribution with @@ -155,10 +158,10 @@ public interface RandomData { * @param mu the mean of the distribution * @param sigma the standard deviation of the distribution * @return a random value following the specified Gaussian distribution - * @throws NotStrictlyPositiveException if {@code sigma <= 0}. + * @throws org.apache.commons.math.exception.NotStrictlyPositiveException + * if {@code sigma <= 0}. */ - double nextGaussian(double mu, double sigma) - throws NotStrictlyPositiveException; + double nextGaussian(double mu, double sigma); /** * Generates a random value from the exponential distribution @@ -170,9 +173,10 @@ public interface RandomData { * * @param mean the mean of the distribution * @return a random value following the specified exponential distribution - * @throws NotStrictlyPositiveException if {@code mean <= 0}. + * @throws org.apache.commons.math.exception.NotStrictlyPositiveException + * if {@code mean <= 0}. */ - double nextExponential(double mean) throws NotStrictlyPositiveException; + double nextExponential(double mean); /** * Generates a uniformly distributed random value from the open interval @@ -188,10 +192,10 @@ public interface RandomData { * @param upper the exclusive upper bound of the support * @return a uniformly distributed random value between lower and upper * (exclusive) - * @throws NumberIsTooLargeException if {@code lower >= upper} + * @throws org.apache.commons.math.exception.NumberIsTooLargeException + * if {@code lower >= upper} */ - double nextUniform(double lower, double upper) - throws NumberIsTooLargeException; + double nextUniform(double lower, double upper); /** * Generates a uniformly distributed random value from the interval @@ -210,11 +214,12 @@ public interface RandomData { * @param lowerInclusive {@code true} if the lower bound is inclusive * @return uniformly distributed random value in the {@code (lower, upper)} * interval, if {@code lowerInclusive} is {@code false}, or in the - * {@code [lower, upper)} interval, if {@code lowerInclusive} is {@code true} - * @throws NumberIsTooLargeException if {@code lower >= upper} + * {@code [lower, upper)} interval, if {@code lowerInclusive} is + * {@code true} + * @throws org.apache.commons.math.exception.NumberIsTooLargeException + * if {@code lower >= upper} */ - double nextUniform(double lower, double upper, boolean lowerInclusive) - throws NumberIsTooLargeException; + double nextUniform(double lower, double upper, boolean lowerInclusive); /** * Generates an integer array of length {@code k} whose entries are selected @@ -228,11 +233,12 @@ public interface RandomData { * @param k the size of the permutation * @return a random {@code k}-permutation of {@code n}, as an array of * integers - * @throws NumberIsTooLargeException if {@code k > n}. - * @throws NotStrictlyPositiveException if {@code k <= 0}. + * @throws org.apache.commons.math.exception.NumberIsTooLargeException + * if {@code k > n}. + * @throws org.apache.commons.math.exception.NotStrictlyPositiveException + * if {@code k <= 0}. */ - int[] nextPermutation(int n, int k) - throws NumberIsTooLargeException, NotStrictlyPositiveException; + int[] nextPermutation(int n, int k); /** * Returns an array of {@code k} objects selected randomly from the @@ -248,9 +254,10 @@ public interface RandomData { * @param c the collection to be sampled * @param k the size of the sample * @return a random sample of {@code k} elements from {@code c} - * @throws NumberIsTooLargeException if {@code k > c.size()}. - * @throws NotStrictlyPositiveException if {@code k <= 0}. + * @throws org.apache.commons.math.exception.NumberIsTooLargeException + * if {@code k > c.size()}. + * @throws org.apache.commons.math.exception.NotStrictlyPositiveException + * if {@code k <= 0}. */ - Object[] nextSample(Collection c, int k) - throws NumberIsTooLargeException, NotStrictlyPositiveException; + Object[] nextSample(Collection c, int k); } diff --git a/src/main/java/org/apache/commons/math/random/RandomDataImpl.java b/src/main/java/org/apache/commons/math/random/RandomDataImpl.java index b70f68816..cf97716e4 100644 --- a/src/main/java/org/apache/commons/math/random/RandomDataImpl.java +++ b/src/main/java/org/apache/commons/math/random/RandomDataImpl.java @@ -197,7 +197,7 @@ public class RandomDataImpl implements RandomData, Serializable { * @return the random string. * @throws NotStrictlyPositiveException if {@code len <= 0}. */ - public String nextHexString(int len) throws NotStrictlyPositiveException { + public String nextHexString(int len) { if (len <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.LENGTH, len); } @@ -233,7 +233,7 @@ public class RandomDataImpl implements RandomData, Serializable { } /** {@inheritDoc} */ - public int nextInt(int lower, int upper) throws NumberIsTooLargeException { + public int nextInt(int lower, int upper) { if (lower >= upper) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper, false); @@ -270,7 +270,7 @@ public class RandomDataImpl implements RandomData, Serializable { * *

*/ - public String nextSecureHexString(int len) throws NotStrictlyPositiveException { + public String nextSecureHexString(int len) { if (len <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.LENGTH, len); } @@ -332,8 +332,7 @@ public class RandomDataImpl implements RandomData, Serializable { } /** {@inheritDoc} */ - public long nextSecureLong(long lower, long upper) - throws NumberIsTooLargeException { + public long nextSecureLong(long lower, long upper) { if (lower >= upper) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, @@ -358,7 +357,7 @@ public class RandomDataImpl implements RandomData, Serializable { * Devroye, Luc. (1981).The Computer Generation of Poisson Random Variables * Computing vol. 26 pp. 197-207.

*/ - public long nextPoisson(double mean) throws NotStrictlyPositiveException { + public long nextPoisson(double mean) { if (mean <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean); } @@ -450,8 +449,7 @@ public class RandomDataImpl implements RandomData, Serializable { } /** {@inheritDoc} */ - public double nextGaussian(double mu, double sigma) - throws NotStrictlyPositiveException { + public double nextGaussian(double mu, double sigma) { if (sigma <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.STANDARD_DEVIATION, sigma); @@ -470,8 +468,7 @@ public class RandomDataImpl implements RandomData, Serializable { * Communications of the ACM, 15, 873-882. *

*/ - public double nextExponential(double mean) - throws NotStrictlyPositiveException { + public double nextExponential(double mean) { if (mean <= 0.0) { throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean); @@ -528,8 +525,7 @@ public class RandomDataImpl implements RandomData, Serializable { * @throws MathIllegalArgumentException if one of the bounds is infinite or * {@code NaN} or either bound is infinite or NaN */ - public double nextUniform(double lower, double upper) - throws NumberIsTooLargeException, MathIllegalArgumentException { + public double nextUniform(double lower, double upper) { return nextUniform(lower, upper, false); } @@ -550,8 +546,7 @@ public class RandomDataImpl implements RandomData, Serializable { * @since 3.0 */ public double nextUniform(double lower, double upper, - boolean lowerInclusive) - throws NumberIsTooLargeException, MathIllegalArgumentException { + boolean lowerInclusive) { if (lower >= upper) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, @@ -969,8 +964,7 @@ public class RandomDataImpl implements RandomData, Serializable { * here *

*/ - public Object[] nextSample(Collection c, int k) - throws NumberIsTooLargeException, NotStrictlyPositiveException { + public Object[] nextSample(Collection c, int k) { int len = c.size(); if (k > len) {