Author: erans Date: Mon Sep 27 12:18:22 2010 New Revision: 1001700 URL: http://svn.apache.org/viewvc?rev=1001700&view=rev Log: Removed deprecated code.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java?rev=1001700&r1=1001699&r2=1001700&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java Mon Sep 27 12:18:22 2010 @@ -29,25 +29,19 @@ package org.apache.commons.math.distribu * * @version $Revision$ $Date$ */ -public interface ExponentialDistribution extends ContinuousDistribution, HasDensity<Double> { - /** - * Modify the mean. - * @param mean the new mean. - * @deprecated as of v2.1 - */ - @Deprecated - void setMean(double mean); - +public interface ExponentialDistribution extends ContinuousDistribution { /** * Access the mean. + * * @return the mean. */ double getMean(); /** * Return the probability density for a particular point. - * @param x The point at which the density should be computed. - * @return The pdf at point x. + * + * @param x Point at which the density should be computed. + * @return the pdf at point {...@code x}. */ - double density(Double x); + double density(double x); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java?rev=1001700&r1=1001699&r2=1001700&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java Mon Sep 27 12:18:22 2010 @@ -19,7 +19,8 @@ package org.apache.commons.math.distribu import java.io.Serializable; import org.apache.commons.math.MathException; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NotStrictlyPositiveException; +import org.apache.commons.math.exception.OutOfRangeException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.FastMath; @@ -30,19 +31,15 @@ import org.apache.commons.math.util.Fast */ public class ExponentialDistributionImpl extends AbstractContinuousDistribution implements ExponentialDistribution, Serializable { - /** * Default inverse cumulative probability accuracy * @since 2.1 */ public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9; - /** Serializable version identifier */ private static final long serialVersionUID = 2401296428283614780L; - /** The mean of this distribution. */ private double mean; - /** Inverse cumulative probability accuracy */ private final double solverAbsoluteAccuracy; @@ -57,41 +54,23 @@ public class ExponentialDistributionImpl /** * Create a exponential distribution with the given mean. * @param mean mean of this distribution. - * @param inverseCumAccuracy the maximum absolute error in inverse cumulative probability estimates - * (defaults to {...@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}) + * @param inverseCumAccuracy the maximum absolute error in inverse + * cumulative probability estimates (defaults to + * {...@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}). + * @throws NotStrictlyPositiveException if {...@code mean <= 0}. * @since 2.1 */ public ExponentialDistributionImpl(double mean, double inverseCumAccuracy) { - super(); - setMeanInternal(mean); - solverAbsoluteAccuracy = inverseCumAccuracy; - } - - /** - * Modify the mean. - * @param mean the new mean. - * @throws IllegalArgumentException if <code>mean</code> is not positive. - * @deprecated as of 2.1 (class will become immutable in 3.0) - */ - @Deprecated - public void setMean(double mean) { - setMeanInternal(mean); - } - /** - * Modify the mean. - * @param newMean the new mean. - * @throws IllegalArgumentException if <code>newMean</code> is not positive. - */ - private void setMeanInternal(double newMean) { - if (newMean <= 0.0) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NOT_POSITIVE_MEAN, newMean); + if (mean <= 0) { + throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean); } - this.mean = newMean; + this.mean = mean; + solverAbsoluteAccuracy = inverseCumAccuracy; } /** * Access the mean. + * * @return the mean. */ public double getMean() { @@ -101,19 +80,8 @@ public class ExponentialDistributionImpl /** * Return the probability density for a particular point. * - * @param x The point at which the density should be computed. - * @return The pdf at point x. - * @deprecated - use density(double) - */ - public double density(Double x) { - return density(x.doubleValue()); - } - - /** - * Return the probability density for a particular point. - * - * @param x The point at which the density should be computed. - * @return The pdf at point x. + * @param x Point at which the density should be computed. + * @return the pdf at point {...@code x}. * @since 2.1 */ @Override @@ -135,11 +103,11 @@ public class ExponentialDistributionImpl * </ul> * * @param x the value at which the CDF is evaluated. - * @return CDF for this distribution. + * @return the CDF for this distribution. * @throws MathException if the cumulative probability can not be - * computed due to convergence or other numerical errors. + * computed due to convergence or other numerical errors. */ - public double cumulativeProbability(double x) throws MathException{ + public double cumulativeProbability(double x) throws MathException { double ret; if (x <= 0.0) { ret = 0.0; @@ -151,23 +119,21 @@ public class ExponentialDistributionImpl /** * For this distribution, X, this method returns the critical point x, such - * that P(X < x) = <code>p</code>. - * <p> - * Returns 0 for p=0 and <code>Double.POSITIVE_INFINITY</code> for p=1.</p> + * that {...@code P(X < x) = p}. + * Returns 0 when p = 0 and {...@code Double.POSITIVE_INFINITY} when p = 1. * * @param p the desired probability - * @return x, such that P(X < x) = <code>p</code> + * @return {...@code x}, such that {...@code P(X < x) = p}. * @throws MathException if the inverse cumulative probability can not be - * computed due to convergence or other numerical errors. - * @throws IllegalArgumentException if p < 0 or p > 1. + * computed due to convergence or other numerical errors. + * @throws OutOfRangeException if {...@code p < 0} or {...@code p > 1}. */ @Override public double inverseCumulativeProbability(double p) throws MathException { double ret; if (p < 0.0 || p > 1.0) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0); + throw new OutOfRangeException(p, 0.0, 1.0); } else if (p == 1.0) { ret = Double.POSITIVE_INFINITY; } else { @@ -183,11 +149,11 @@ public class ExponentialDistributionImpl * <p><strong>Algorithm Description</strong>: Uses the <a * href="http://www.jesus.ox.ac.uk/~clifford/a5/chap1/node5.html"> Inversion * Method</a> to generate exponentially distributed random values from - * uniform deviates. </p> + * uniform deviates.</p> * - * @return random value + * @return a random value. + * @throws MathException if an error occurs generating the random value. * @since 2.2 - * @throws MathException if an error occurs generating the random value */ @Override public double sample() throws MathException { @@ -195,12 +161,11 @@ public class ExponentialDistributionImpl } /** - * Access the domain value lower bound, based on <code>p</code>, used to + * Access the domain value lower bound, based on {...@code p}, used to * bracket a CDF root. * - * @param p the desired probability for the critical value - * @return domain value lower bound, i.e. - * P(X < <i>lower bound</i>) < <code>p</code> + * @param p Desired probability for the critical value. + * @return the domain value lower bound, i.e. {...@code P(X < 'lower bound') < p}. */ @Override protected double getDomainLowerBound(double p) { @@ -211,16 +176,15 @@ public class ExponentialDistributionImpl * Access the domain value upper bound, based on <code>p</code>, used to * bracket a CDF root. * - * @param p the desired probability for the critical value - * @return domain value upper bound, i.e. - * P(X < <i>upper bound</i>) > <code>p</code> + * @param p Desired probability for the critical value. + * @return the domain value upper bound, i.e. {...@code P(X < 'upper bound') > p}. */ @Override protected double getDomainUpperBound(double p) { // NOTE: exponential is skewed to the left // NOTE: therefore, P(X < μ) > .5 - if (p < .5) { + if (p < 0.5) { // use mean return mean; } else { @@ -230,11 +194,11 @@ public class ExponentialDistributionImpl } /** - * Access the initial domain value, based on <code>p</code>, used to + * Access the initial domain value, based on {...@code p}, used to * bracket a CDF root. * - * @param p the desired probability for the critical value - * @return initial domain value + * @param p Desired probability for the critical value. + * @return the initial domain value. */ @Override protected double getInitialDomain(double p) { @@ -242,9 +206,9 @@ public class ExponentialDistributionImpl // TODO: what should really happen here is not derive from AbstractContinuousDistribution // TODO: because the inverse cumulative distribution is simple. // Exponential is skewed to the left, therefore, P(X < μ) > .5 - if (p < .5) { + if (p < 0.5) { // use 1/2 mean - return mean * .5; + return mean * 0.5; } else { // use mean return mean; @@ -255,7 +219,7 @@ public class ExponentialDistributionImpl * Return the absolute accuracy setting of the solver used to estimate * inverse cumulative probabilities. * - * @return the solver absolute accuracy + * @return the solver absolute accuracy. * @since 2.1 */ @Override Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java?rev=1001700&r1=1001699&r2=1001700&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java Mon Sep 27 12:18:22 2010 @@ -17,6 +17,7 @@ package org.apache.commons.math.distribution; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.exception.NotStrictlyPositiveException; /** * Test cases for ExponentialDistribution. @@ -111,14 +112,13 @@ public class ExponentialDistributionTest public void testMeanAccessors() { ExponentialDistribution distribution = (ExponentialDistribution) getDistribution(); assertEquals(5d, distribution.getMean(), Double.MIN_VALUE); - distribution.setMean(2d); - assertEquals(2d, distribution.getMean(), Double.MIN_VALUE); + } + + public void testPreconditions() { try { - distribution.setMean(0); - fail("Expecting IllegalArgumentException for 0 mean"); - } catch (IllegalArgumentException ex) { - // expected + ExponentialDistribution distribution = new ExponentialDistributionImpl(0); + } catch (NotStrictlyPositiveException e) { + // Expected. } } - }