Removed unchecked exceptions from method signatures. See
- Commons-Dev mailing list http://mail-archives.apache.org/mod_mbox/commons-dev/201201.mbox/%3C20120113105913.GM6537%40dusk.harfang.homelinux.org%3E - "Effective Java, second edition", item 62. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1231847 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d96758d1c6
commit
29cd56b6f4
|
@ -18,9 +18,6 @@
|
||||||
package org.apache.commons.math.random;
|
package org.apache.commons.math.random;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.apache.commons.math.exception.NotStrictlyPositiveException;
|
|
||||||
import org.apache.commons.math.exception.NumberIsTooLargeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Random data generation utilities.
|
* Random data generation utilities.
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
|
@ -36,9 +33,10 @@ public interface RandomData {
|
||||||
*
|
*
|
||||||
* @param len the length of the string to be generated
|
* @param len the length of the string to be generated
|
||||||
* @return a random string of hex characters of length {@code len}
|
* @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}
|
* Generates a uniformly distributed random integer between {@code lower}
|
||||||
|
@ -53,9 +51,10 @@ public interface RandomData {
|
||||||
* @param upper upper bound for generated integer
|
* @param upper upper bound for generated integer
|
||||||
* @return a random integer greater than or equal to {@code lower}
|
* @return a random integer greater than or equal to {@code lower}
|
||||||
* and less than or equal to {@code upper}
|
* 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
|
* Generates a uniformly distributed random long integer between
|
||||||
|
@ -70,9 +69,10 @@ public interface RandomData {
|
||||||
* @param upper upper bound for generated long integer
|
* @param upper upper bound for generated long integer
|
||||||
* @return a random long integer greater than or equal to {@code lower} and
|
* @return a random long integer greater than or equal to {@code lower} and
|
||||||
* less than or equal to {@code upper}
|
* 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
|
* 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
|
* @param len the length of the string to be generated
|
||||||
* @return a random string of hex characters of length {@code len}
|
* @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}
|
* Generates a uniformly distributed random integer between {@code lower}
|
||||||
|
@ -104,9 +105,10 @@ public interface RandomData {
|
||||||
* @param upper upper bound for generated integer
|
* @param upper upper bound for generated integer
|
||||||
* @return a random integer greater than or equal to {@code lower} and less
|
* @return a random integer greater than or equal to {@code lower} and less
|
||||||
* than or equal to {@code upper}.
|
* 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
|
* Generates a uniformly distributed random long integer between
|
||||||
|
@ -125,10 +127,10 @@ public interface RandomData {
|
||||||
* @param upper upper bound for generated integer
|
* @param upper upper bound for generated integer
|
||||||
* @return a random long integer greater than or equal to {@code lower} and
|
* @return a random long integer greater than or equal to {@code lower} and
|
||||||
* less than or equal to {@code upper}.
|
* 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)
|
long nextSecureLong(long lower, long upper);
|
||||||
throws NumberIsTooLargeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a random value from the Poisson distribution with the given
|
* 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
|
* @param mean the mean of the Poisson distribution
|
||||||
* @return a random value following the specified 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
|
* 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 mu the mean of the distribution
|
||||||
* @param sigma the standard deviation of the distribution
|
* @param sigma the standard deviation of the distribution
|
||||||
* @return a random value following the specified Gaussian 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)
|
double nextGaussian(double mu, double sigma);
|
||||||
throws NotStrictlyPositiveException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a random value from the exponential distribution
|
* Generates a random value from the exponential distribution
|
||||||
|
@ -170,9 +173,10 @@ public interface RandomData {
|
||||||
*
|
*
|
||||||
* @param mean the mean of the distribution
|
* @param mean the mean of the distribution
|
||||||
* @return a random value following the specified exponential 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
|
* 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
|
* @param upper the exclusive upper bound of the support
|
||||||
* @return a uniformly distributed random value between lower and upper
|
* @return a uniformly distributed random value between lower and upper
|
||||||
* (exclusive)
|
* (exclusive)
|
||||||
* @throws NumberIsTooLargeException if {@code lower >= upper}
|
* @throws org.apache.commons.math.exception.NumberIsTooLargeException
|
||||||
|
* if {@code lower >= upper}
|
||||||
*/
|
*/
|
||||||
double nextUniform(double lower, double upper)
|
double nextUniform(double lower, double upper);
|
||||||
throws NumberIsTooLargeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a uniformly distributed random value from the interval
|
* 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
|
* @param lowerInclusive {@code true} if the lower bound is inclusive
|
||||||
* @return uniformly distributed random value in the {@code (lower, upper)}
|
* @return uniformly distributed random value in the {@code (lower, upper)}
|
||||||
* interval, if {@code lowerInclusive} is {@code false}, or in the
|
* interval, if {@code lowerInclusive} is {@code false}, or in the
|
||||||
* {@code [lower, upper)} interval, if {@code lowerInclusive} is {@code true}
|
* {@code [lower, upper)} interval, if {@code lowerInclusive} is
|
||||||
* @throws NumberIsTooLargeException if {@code lower >= upper}
|
* {@code true}
|
||||||
|
* @throws org.apache.commons.math.exception.NumberIsTooLargeException
|
||||||
|
* if {@code lower >= upper}
|
||||||
*/
|
*/
|
||||||
double nextUniform(double lower, double upper, boolean lowerInclusive)
|
double nextUniform(double lower, double upper, boolean lowerInclusive);
|
||||||
throws NumberIsTooLargeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates an integer array of length {@code k} whose entries are selected
|
* 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
|
* @param k the size of the permutation
|
||||||
* @return a random {@code k}-permutation of {@code n}, as an array of
|
* @return a random {@code k}-permutation of {@code n}, as an array of
|
||||||
* integers
|
* integers
|
||||||
* @throws NumberIsTooLargeException if {@code k > n}.
|
* @throws org.apache.commons.math.exception.NumberIsTooLargeException
|
||||||
* @throws NotStrictlyPositiveException if {@code k <= 0}.
|
* if {@code k > n}.
|
||||||
|
* @throws org.apache.commons.math.exception.NotStrictlyPositiveException
|
||||||
|
* if {@code k <= 0}.
|
||||||
*/
|
*/
|
||||||
int[] nextPermutation(int n, int k)
|
int[] nextPermutation(int n, int k);
|
||||||
throws NumberIsTooLargeException, NotStrictlyPositiveException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of {@code k} objects selected randomly from the
|
* 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 c the collection to be sampled
|
||||||
* @param k the size of the sample
|
* @param k the size of the sample
|
||||||
* @return a random sample of {@code k} elements from {@code c}
|
* @return a random sample of {@code k} elements from {@code c}
|
||||||
* @throws NumberIsTooLargeException if {@code k > c.size()}.
|
* @throws org.apache.commons.math.exception.NumberIsTooLargeException
|
||||||
* @throws NotStrictlyPositiveException if {@code k <= 0}.
|
* if {@code k > c.size()}.
|
||||||
|
* @throws org.apache.commons.math.exception.NotStrictlyPositiveException
|
||||||
|
* if {@code k <= 0}.
|
||||||
*/
|
*/
|
||||||
Object[] nextSample(Collection<?> c, int k)
|
Object[] nextSample(Collection<?> c, int k);
|
||||||
throws NumberIsTooLargeException, NotStrictlyPositiveException;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,7 @@ public class RandomDataImpl implements RandomData, Serializable {
|
||||||
* @return the random string.
|
* @return the random string.
|
||||||
* @throws NotStrictlyPositiveException if {@code len <= 0}.
|
* @throws NotStrictlyPositiveException if {@code len <= 0}.
|
||||||
*/
|
*/
|
||||||
public String nextHexString(int len) throws NotStrictlyPositiveException {
|
public String nextHexString(int len) {
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
throw new NotStrictlyPositiveException(LocalizedFormats.LENGTH, len);
|
throw new NotStrictlyPositiveException(LocalizedFormats.LENGTH, len);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ public class RandomDataImpl implements RandomData, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public int nextInt(int lower, int upper) throws NumberIsTooLargeException {
|
public int nextInt(int lower, int upper) {
|
||||||
if (lower >= upper) {
|
if (lower >= upper) {
|
||||||
throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
|
throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
|
||||||
lower, upper, false);
|
lower, upper, false);
|
||||||
|
@ -270,7 +270,7 @@ public class RandomDataImpl implements RandomData, Serializable {
|
||||||
* </ol>
|
* </ol>
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public String nextSecureHexString(int len) throws NotStrictlyPositiveException {
|
public String nextSecureHexString(int len) {
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
throw new NotStrictlyPositiveException(LocalizedFormats.LENGTH, len);
|
throw new NotStrictlyPositiveException(LocalizedFormats.LENGTH, len);
|
||||||
}
|
}
|
||||||
|
@ -332,8 +332,7 @@ public class RandomDataImpl implements RandomData, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public long nextSecureLong(long lower, long upper)
|
public long nextSecureLong(long lower, long upper) {
|
||||||
throws NumberIsTooLargeException {
|
|
||||||
|
|
||||||
if (lower >= upper) {
|
if (lower >= upper) {
|
||||||
throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
|
throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
|
||||||
|
@ -358,7 +357,7 @@ public class RandomDataImpl implements RandomData, Serializable {
|
||||||
* Devroye, Luc. (1981).<i>The Computer Generation of Poisson Random Variables</i>
|
* Devroye, Luc. (1981).<i>The Computer Generation of Poisson Random Variables</i>
|
||||||
* <strong>Computing</strong> vol. 26 pp. 197-207.</li></ul></p>
|
* <strong>Computing</strong> vol. 26 pp. 197-207.</li></ul></p>
|
||||||
*/
|
*/
|
||||||
public long nextPoisson(double mean) throws NotStrictlyPositiveException {
|
public long nextPoisson(double mean) {
|
||||||
if (mean <= 0) {
|
if (mean <= 0) {
|
||||||
throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
|
throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
|
||||||
}
|
}
|
||||||
|
@ -450,8 +449,7 @@ public class RandomDataImpl implements RandomData, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public double nextGaussian(double mu, double sigma)
|
public double nextGaussian(double mu, double sigma) {
|
||||||
throws NotStrictlyPositiveException {
|
|
||||||
|
|
||||||
if (sigma <= 0) {
|
if (sigma <= 0) {
|
||||||
throw new NotStrictlyPositiveException(LocalizedFormats.STANDARD_DEVIATION, sigma);
|
throw new NotStrictlyPositiveException(LocalizedFormats.STANDARD_DEVIATION, sigma);
|
||||||
|
@ -470,8 +468,7 @@ public class RandomDataImpl implements RandomData, Serializable {
|
||||||
* Communications of the ACM, 15, 873-882.
|
* Communications of the ACM, 15, 873-882.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public double nextExponential(double mean)
|
public double nextExponential(double mean) {
|
||||||
throws NotStrictlyPositiveException {
|
|
||||||
|
|
||||||
if (mean <= 0.0) {
|
if (mean <= 0.0) {
|
||||||
throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
|
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
|
* @throws MathIllegalArgumentException if one of the bounds is infinite or
|
||||||
* {@code NaN} or either bound is infinite or NaN
|
* {@code NaN} or either bound is infinite or NaN
|
||||||
*/
|
*/
|
||||||
public double nextUniform(double lower, double upper)
|
public double nextUniform(double lower, double upper) {
|
||||||
throws NumberIsTooLargeException, MathIllegalArgumentException {
|
|
||||||
|
|
||||||
return nextUniform(lower, upper, false);
|
return nextUniform(lower, upper, false);
|
||||||
}
|
}
|
||||||
|
@ -550,8 +546,7 @@ public class RandomDataImpl implements RandomData, Serializable {
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public double nextUniform(double lower, double upper,
|
public double nextUniform(double lower, double upper,
|
||||||
boolean lowerInclusive)
|
boolean lowerInclusive) {
|
||||||
throws NumberIsTooLargeException, MathIllegalArgumentException {
|
|
||||||
|
|
||||||
if (lower >= upper) {
|
if (lower >= upper) {
|
||||||
throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
|
throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
|
||||||
|
@ -969,8 +964,7 @@ public class RandomDataImpl implements RandomData, Serializable {
|
||||||
* here</a>
|
* here</a>
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public Object[] nextSample(Collection<?> c, int k)
|
public Object[] nextSample(Collection<?> c, int k) {
|
||||||
throws NumberIsTooLargeException, NotStrictlyPositiveException {
|
|
||||||
|
|
||||||
int len = c.size();
|
int len = c.size();
|
||||||
if (k > len) {
|
if (k > len) {
|
||||||
|
|
Loading…
Reference in New Issue