Author: psteitz Date: Sun Sep 9 16:43:27 2012 New Revision: 1382537 URL: http://svn.apache.org/viewvc?rev=1382537&view=rev Log: Added missing throws declarations. JIRA: MATH-854.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Max.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Median.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Min.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Percentile.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Max.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Max.java?rev=1382537&r1=1382536&r2=1382537&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Max.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Max.java Sun Sep 9 16:43:27 2012 @@ -18,6 +18,7 @@ package org.apache.commons.math3.stat.de import java.io.Serializable; +import org.apache.commons.math3.exception.MathIllegalArgumentException; import org.apache.commons.math3.exception.NullArgumentException; import org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math3.util.MathUtils; @@ -63,8 +64,9 @@ public class Max extends AbstractStorele * to the {@code original} * * @param original the {@code Max} instance to copy + * @throws NullArgumentException if original is null */ - public Max(Max original) { + public Max(Max original) throws NullArgumentException { copy(original, this); } @@ -108,7 +110,7 @@ public class Max extends AbstractStorele * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> - * Throws <code>IllegalArgumentException</code> if the array is null or + * Throws <code>MathIllegalArgumentException</code> if the array is null or * the array index parameters are not valid.</p> * <p> * <ul> @@ -122,11 +124,12 @@ public class Max extends AbstractStorele * @param begin index of the first array element to include * @param length the number of elements to include * @return the maximum of the values or Double.NaN if length = 0 - * @throws IllegalArgumentException if the array is null or the array index + * @throws MathIllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override - public double evaluate(final double[] values, final int begin, final int length) { + public double evaluate(final double[] values, final int begin, final int length) + throws MathIllegalArgumentException { double max = Double.NaN; if (test(values, begin, length)) { max = values[begin]; @@ -145,6 +148,7 @@ public class Max extends AbstractStorele @Override public Max copy() { Max result = new Max(); + // No try-catch or advertised exception because args are non-null copy(this, result); return result; } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Median.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Median.java?rev=1382537&r1=1382536&r2=1382537&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Median.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Median.java Sun Sep 9 16:43:27 2012 @@ -18,6 +18,8 @@ package org.apache.commons.math3.stat.de import java.io.Serializable; +import org.apache.commons.math3.exception.NullArgumentException; + /** * Returns the median of the available values. This is the same as the 50th percentile. @@ -39,6 +41,7 @@ public class Median extends Percentile i * Default constructor. */ public Median() { + // No try-catch or advertised exception - arg is valid super(50.0); } @@ -47,8 +50,9 @@ public class Median extends Percentile i * to the {@code original} * * @param original the {@code Median} instance to copy + * @throws NullArgumentException if original is null */ - public Median(Median original) { + public Median(Median original) throws NullArgumentException { super(original); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Min.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Min.java?rev=1382537&r1=1382536&r2=1382537&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Min.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Min.java Sun Sep 9 16:43:27 2012 @@ -18,6 +18,7 @@ package org.apache.commons.math3.stat.de import java.io.Serializable; +import org.apache.commons.math3.exception.MathIllegalArgumentException; import org.apache.commons.math3.exception.NullArgumentException; import org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math3.util.MathUtils; @@ -63,8 +64,9 @@ public class Min extends AbstractStorele * to the {@code original} * * @param original the {@code Min} instance to copy + * @throws NullArgumentException if original is null */ - public Min(Min original) { + public Min(Min original) throws NullArgumentException { copy(original, this); } @@ -108,7 +110,7 @@ public class Min extends AbstractStorele * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> - * Throws <code>IllegalArgumentException</code> if the array is null or + * Throws <code>MathIllegalArgumentException</code> if the array is null or * the array index parameters are not valid.</p> * <p> * <ul> @@ -122,11 +124,12 @@ public class Min extends AbstractStorele * @param begin index of the first array element to include * @param length the number of elements to include * @return the minimum of the values or Double.NaN if length = 0 - * @throws IllegalArgumentException if the array is null or the array index + * @throws MathIllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override - public double evaluate(final double[] values,final int begin, final int length) { + public double evaluate(final double[] values,final int begin, final int length) + throws MathIllegalArgumentException { double min = Double.NaN; if (test(values, begin, length)) { min = values[begin]; @@ -145,6 +148,7 @@ public class Min extends AbstractStorele @Override public Min copy() { Min result = new Min(); + // No try-catch or advertised exception - args are non-null copy(this, result); return result; } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Percentile.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Percentile.java?rev=1382537&r1=1382536&r2=1382537&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Percentile.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Percentile.java Sun Sep 9 16:43:27 2012 @@ -19,6 +19,7 @@ package org.apache.commons.math3.stat.de import java.io.Serializable; import java.util.Arrays; +import org.apache.commons.math3.exception.MathIllegalArgumentException; import org.apache.commons.math3.exception.NullArgumentException; import org.apache.commons.math3.exception.OutOfRangeException; import org.apache.commons.math3.exception.util.LocalizedFormats; @@ -103,16 +104,17 @@ public class Percentile extends Abstract * value of 50.0. */ public Percentile() { + // No try-catch or advertised exception here - arg is valid this(50.0); } /** * Constructs a Percentile with the specific quantile value. * @param p the quantile - * @throws IllegalArgumentException if p is not greater than 0 and less + * @throws MathIllegalArgumentException if p is not greater than 0 and less * than or equal to 100 */ - public Percentile(final double p) { + public Percentile(final double p) throws MathIllegalArgumentException { setQuantile(p); cachedPivots = null; } @@ -122,8 +124,9 @@ public class Percentile extends Abstract * to the {@code original} * * @param original the {@code Percentile} instance to copy + * @throws NullArgumentException if original is null */ - public Percentile(Percentile original) { + public Percentile(Percentile original) throws NullArgumentException { copy(original, this); } @@ -141,7 +144,8 @@ public class Percentile extends Abstract /** {@inheritDoc} */ @Override - public void setData(final double[] values, final int begin, final int length) { + public void setData(final double[] values, final int begin, final int length) + throws MathIllegalArgumentException { if (values == null) { cachedPivots = null; } else { @@ -155,11 +159,14 @@ public class Percentile extends Abstract * Returns the result of evaluating the statistic over the stored data. * <p> * The stored array is the one which was set by previous calls to + * {@link #setData(double[])} * </p> * @param p the percentile value to compute * @return the value of the statistic applied to the stored data + * @throws MathIllegalArgumentException if p is not a valid quantile value + * (p must be greater than 0 and less than or equal to 100) */ - public double evaluate(final double p) { + public double evaluate(final double p) throws MathIllegalArgumentException { return evaluate(getDataRef(), p); } @@ -175,7 +182,7 @@ public class Percentile extends Abstract * <code>0</code></li> * <li>Returns (for any value of <code>p</code>) <code>values[0]</code> * if <code>values</code> has length <code>1</code></li> - * <li>Throws <code>IllegalArgumentException</code> if <code>values</code> + * <li>Throws <code>MathIllegalArgumentException</code> if <code>values</code> * is null or p is not a valid quantile value (p must be greater than 0 * and less than or equal to 100) </li> * </ul></p> @@ -186,10 +193,11 @@ public class Percentile extends Abstract * @param values input array of values * @param p the percentile value to compute * @return the percentile value or Double.NaN if the array is empty - * @throws IllegalArgumentException if <code>values</code> is null + * @throws MathIllegalArgumentException if <code>values</code> is null * or p is invalid */ - public double evaluate(final double[] values, final double p) { + public double evaluate(final double[] values, final double p) + throws MathIllegalArgumentException { test(values, 0, 0); return evaluate(values, 0, values.length, p); } @@ -203,9 +211,8 @@ public class Percentile extends Abstract * <li>Returns <code>Double.NaN</code> if <code>length = 0</code></li> * <li>Returns (for any value of <code>quantile</code>) * <code>values[begin]</code> if <code>length = 1 </code></li> - * <li>Throws <code>IllegalArgumentException</code> if <code>values</code> - * is null, or <code>start</code> or <code>length</code> - * is invalid</li> + * <li>Throws <code>MathIllegalArgumentException</code> if <code>values</code> + * is null, or <code>start</code> or <code>length</code> is invalid</li> * </ul></p> * <p> * See {@link Percentile} for a description of the percentile estimation @@ -215,11 +222,12 @@ public class Percentile extends Abstract * @param start index of the first array element to include * @param length the number of elements to include * @return the percentile value - * @throws IllegalArgumentException if the parameters are not valid + * @throws MathIllegalArgumentException if the parameters are not valid * */ @Override - public double evaluate( final double[] values, final int start, final int length) { + public double evaluate(final double[] values, final int start, final int length) + throws MathIllegalArgumentException { return evaluate(values, start, length, quantile); } @@ -236,7 +244,7 @@ public class Percentile extends Abstract * <li>Returns <code>Double.NaN</code> if <code>length = 0</code></li> * <li>Returns (for any value of <code>p</code>) <code>values[begin]</code> * if <code>length = 1 </code></li> - * <li>Throws <code>IllegalArgumentException</code> if <code>values</code> + * <li>Throws <code>MathIllegalArgumentException</code> if <code>values</code> * is null , <code>begin</code> or <code>length</code> is invalid, or * <code>p</code> is not a valid quantile value (p must be greater than 0 * and less than or equal to 100)</li> @@ -250,16 +258,17 @@ public class Percentile extends Abstract * @param begin the first (0-based) element to include in the computation * @param length the number of array elements to include * @return the percentile value - * @throws IllegalArgumentException if the parameters are not valid or the + * @throws MathIllegalArgumentException if the parameters are not valid or the * input array is null */ public double evaluate(final double[] values, final int begin, - final int length, final double p) { + final int length, final double p) throws MathIllegalArgumentException { test(values, begin, length); if ((p > 100) || (p <= 0)) { - throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p, 0, 100); + throw new OutOfRangeException( + LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p, 0, 100); } if (length == 0) { return Double.NaN; @@ -457,12 +466,13 @@ public class Percentile extends Abstract * computed when evaluate() is called with no quantile argument). * * @param p a value between 0 < p <= 100 - * @throws IllegalArgumentException if p is not greater than 0 and less + * @throws MathIllegalArgumentException if p is not greater than 0 and less * than or equal to 100 */ - public void setQuantile(final double p) { + public void setQuantile(final double p) throws MathIllegalArgumentException { if (p <= 0 || p > 100) { - throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p, 0, 100); + throw new OutOfRangeException( + LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p, 0, 100); } quantile = p; } @@ -473,6 +483,7 @@ public class Percentile extends Abstract @Override public Percentile copy() { Percentile result = new Percentile(); + //No try-catch or advertised exception because args are guaranteed non-null copy(this, result); return result; }