You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2012/09/17 00:11:15 UTC

svn commit: r1385386 - in /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive: ./ moment/ summary/

Author: psteitz
Date: Sun Sep 16 22:11:15 2012
New Revision: 1385386

URL: http://svn.apache.org/viewvc?rev=1385386&view=rev
Log:
Added missing throws declarations and fixed javadoc to match what is actually thrown.  JIRA: MATH-854.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatistics.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/moment/SemiVariance.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/moment/StandardDeviation.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/Product.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/Sum.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/SumOfLogs.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/SumOfSquares.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatistics.java?rev=1385386&r1=1385385&r2=1385386&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatistics.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatistics.java Sun Sep 16 22:11:15 2012
@@ -175,9 +175,15 @@ public class DescriptiveStatistics imple
 
     /**
      * Removes the most recent value from the dataset.
+     *
+     * @throws MathIllegalStateException if there are no elements stored
      */
-    public void removeMostRecentValue() {
-        eDA.discardMostRecentElements(1);
+    public void removeMostRecentValue() throws MathIllegalStateException {
+        try {
+            eDA.discardMostRecentElements(1);
+        } catch (MathIllegalArgumentException ex) {
+            throw new MathIllegalStateException(LocalizedFormats.NO_DATA);
+        }
     }
 
     /**
@@ -186,8 +192,9 @@ public class DescriptiveStatistics imple
      *
      * @param v the value to replace the most recent stored value
      * @return replaced value
+     * @throws MathIllegalStateException if there are no elements stored
      */
-    public double replaceMostRecentValue(double v) {
+    public double replaceMostRecentValue(double v) throws MathIllegalStateException {
         return eDA.substituteMostRecentElement(v);
     }
 
@@ -407,7 +414,7 @@ public class DescriptiveStatistics imple
      * </p><p>
      * <strong>Preconditions</strong>:<ul>
      * <li><code>0 &lt; p &le; 100</code> (otherwise an
-     * <code>IllegalArgumentException</code> is thrown)</li>
+     * <code>MathIllegalArgumentException</code> is thrown)</li>
      * <li>at least one value must be stored (returns <code>Double.NaN
      *     </code> otherwise)</li>
      * </ul></p>
@@ -416,8 +423,9 @@ public class DescriptiveStatistics imple
      * @return An estimate for the pth percentile of the stored data
      * @throws MathIllegalStateException if percentile implementation has been
      *  overridden and the supplied implementation does not support setQuantile
+     * @throws MathIllegalArgumentException if p is not a valid quantile
      */
-    public double getPercentile(double p) throws MathIllegalStateException {
+    public double getPercentile(double p) throws MathIllegalStateException, MathIllegalArgumentException {
         if (percentileImpl instanceof Percentile) {
             ((Percentile) percentileImpl).setQuantile(p);
         } else {
@@ -459,6 +467,7 @@ public class DescriptiveStatistics imple
         outBuffer.append("std dev: ").append(getStandardDeviation())
             .append(endl);
         try {
+            // No catch for MIAE because actual parameter is valid below
             outBuffer.append("median: ").append(getPercentile(50)).append(endl);
         } catch (MathIllegalStateException ex) {
             outBuffer.append("median: unavailable").append(endl);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/moment/SemiVariance.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/moment/SemiVariance.java?rev=1385386&r1=1385385&r2=1385386&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/moment/SemiVariance.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/moment/SemiVariance.java Sun Sep 16 22:11:15 2012
@@ -213,14 +213,15 @@ public class SemiVariance extends Abstra
        * instance properties variancDirection and biasCorrection.</p>
        *
        * <p>Returns <code>NaN</code> if the array is empty and throws
-       * <code>IllegalArgumentException</code> if the array is null.</p>
+       * <code>MathIllegalArgumentException</code> if the array is null.</p>
        *
        * @param values the input array
        * @param cutoff the reference point
        * @return the SemiVariance
-       * @throws IllegalArgumentException if values is null
+       * @throws MathIllegalArgumentException if values is null
        */
-      public double evaluate(final double[] values, final double cutoff) {
+      public double evaluate(final double[] values, final double cutoff)
+      throws MathIllegalArgumentException {
           return evaluate(values, cutoff, varianceDirection, biasCorrected, 0, values.length);
       }
 
@@ -229,15 +230,16 @@ public class SemiVariance extends Abstra
        * given direction, using the current value of the biasCorrection instance property.</p>
        *
        * <p>Returns <code>NaN</code> if the array is empty and throws
-       * <code>IllegalArgumentException</code> if the array is null.</p>
+       * <code>MathIllegalArgumentException</code> if the array is null.</p>
        *
        * @param values the input array
        * @param cutoff the reference point
        * @param direction the {@link Direction} of the semivariance
        * @return the SemiVariance
-       * @throws IllegalArgumentException if values is null
+       * @throws MathIllegalArgumentException if values is null
        */
-      public double evaluate(final double[] values, final double cutoff, final Direction direction) {
+      public double evaluate(final double[] values, final double cutoff, final Direction direction)
+      throws MathIllegalArgumentException {
           return evaluate(values, cutoff, direction, biasCorrected, 0, values.length);
       }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/moment/StandardDeviation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/moment/StandardDeviation.java?rev=1385386&r1=1385385&r2=1385386&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/moment/StandardDeviation.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/moment/StandardDeviation.java Sun Sep 16 22:11:15 2012
@@ -72,8 +72,9 @@ public class StandardDeviation extends A
      * to the {@code original}
      *
      * @param original the {@code StandardDeviation} instance to copy
+     * @throws NullArgumentException if original is null
      */
-    public StandardDeviation(StandardDeviation original) {
+    public StandardDeviation(StandardDeviation original) throws NullArgumentException {
         copy(original, this);
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/Product.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/Product.java?rev=1385386&r1=1385385&r2=1385386&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/Product.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/Product.java Sun Sep 16 22:11:15 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.stat.descriptive.WeightedEvaluation;
@@ -64,8 +65,9 @@ public class Product extends AbstractSto
      * to the {@code original}
      *
      * @param original the {@code Product} instance to copy
+     * @throws NullArgumentException  if original is null
      */
-    public Product(Product original) {
+    public Product(Product original) throws NullArgumentException {
         copy(original, this);
     }
 
@@ -107,17 +109,18 @@ public class Product extends AbstractSto
      * the input array, or <code>Double.NaN</code> if the designated subarray
      * is empty.
      * <p>
-     * Throws <code>IllegalArgumentException</code> if the array is null.</p>
+     * Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
      *
      * @param values the input array
      * @param begin index of the first array element to include
      * @param length the number of elements to include
      * @return the product of the values or 1 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 product = Double.NaN;
         if (test(values, begin, length, true)) {
             product = 1.0;
@@ -133,7 +136,7 @@ public class Product extends AbstractSto
      * the input array, or <code>Double.NaN</code> if the designated subarray
      * is empty.</p>
      *
-     * <p>Throws <code>IllegalArgumentException</code> if any of the following are true:
+     * <p>Throws <code>MathIllegalArgumentException</code> if any of the following are true:
      * <ul><li>the values array is null</li>
      *     <li>the weights array is null</li>
      *     <li>the weights array does not have the same length as the values array</li>
@@ -153,11 +156,11 @@ public class Product extends AbstractSto
      * @param begin index of the first array element to include
      * @param length the number of elements to include
      * @return the product of the values or 1 if length = 0
-     * @throws IllegalArgumentException if the parameters are not valid
+     * @throws MathIllegalArgumentException if the parameters are not valid
      * @since 2.1
      */
     public double evaluate(final double[] values, final double[] weights,
-                           final int begin, final int length) {
+        final int begin, final int length) throws MathIllegalArgumentException {
         double product = Double.NaN;
         if (test(values, weights, begin, length, true)) {
             product = 1.0;
@@ -171,7 +174,7 @@ public class Product extends AbstractSto
     /**
      * <p>Returns the weighted product of the entries in the input array.</p>
      *
-     * <p>Throws <code>IllegalArgumentException</code> if any of the following are true:
+     * <p>Throws <code>MathIllegalArgumentException</code> if any of the following are true:
      * <ul><li>the values array is null</li>
      *     <li>the weights array is null</li>
      *     <li>the weights array does not have the same length as the values array</li>
@@ -188,10 +191,11 @@ public class Product extends AbstractSto
      * @param values the input array
      * @param weights the weights array
      * @return the product of the values or Double.NaN if length = 0
-     * @throws IllegalArgumentException if the parameters are not valid
+     * @throws MathIllegalArgumentException if the parameters are not valid
      * @since 2.1
      */
-    public double evaluate(final double[] values, final double[] weights) {
+    public double evaluate(final double[] values, final double[] weights)
+    throws MathIllegalArgumentException {
         return evaluate(values, weights, 0, values.length);
     }
 
@@ -202,6 +206,7 @@ public class Product extends AbstractSto
     @Override
     public Product copy() {
         Product result = new Product();
+        // No try-catch or advertised exception because args are valid
         copy(this, result);
         return result;
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/Sum.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/Sum.java?rev=1385386&r1=1385385&r2=1385386&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/Sum.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/Sum.java Sun Sep 16 22:11:15 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 Sum extends AbstractStorele
      * to the {@code original}
      *
      * @param original the {@code Sum} instance to copy
+     * @throws NullArgumentException if original is null
      */
-    public Sum(Sum original) {
+    public Sum(Sum original) throws NullArgumentException {
         copy(original, this);
     }
 
@@ -106,17 +108,18 @@ public class Sum extends AbstractStorele
      * the input array, or 0 if the designated subarray
      * is empty.
      * <p>
-     * Throws <code>IllegalArgumentException</code> if the array is null.</p>
+     * Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
      *
      * @param values the input array
      * @param begin index of the first array element to include
      * @param length the number of elements to include
      * @return the sum of the values or 0 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 sum = Double.NaN;
         if (test(values, begin, length, true)) {
             sum = 0.0;
@@ -132,7 +135,7 @@ public class Sum extends AbstractStorele
      * the input array, or 0 if the designated subarray
      * is empty.
      * <p>
-     * Throws <code>IllegalArgumentException</code> if any of the following are true:
+     * Throws <code>MathIllegalArgumentException</code> if any of the following are true:
      * <ul><li>the values array is null</li>
      *     <li>the weights array is null</li>
      *     <li>the weights array does not have the same length as the values array</li>
@@ -151,11 +154,11 @@ public class Sum extends AbstractStorele
      * @param begin index of the first array element to include
      * @param length the number of elements to include
      * @return the sum of the values or 0 if length = 0
-     * @throws IllegalArgumentException if the parameters are not valid
+     * @throws MathIllegalArgumentException if the parameters are not valid
      * @since 2.1
      */
     public double evaluate(final double[] values, final double[] weights,
-                           final int begin, final int length) {
+        final int begin, final int length) throws MathIllegalArgumentException {
         double sum = Double.NaN;
         if (test(values, weights, begin, length, true)) {
             sum = 0.0;
@@ -169,7 +172,7 @@ public class Sum extends AbstractStorele
     /**
      * The weighted sum of the entries in the the input array.
      * <p>
-     * Throws <code>IllegalArgumentException</code> if any of the following are true:
+     * Throws <code>MathIllegalArgumentException</code> if any of the following are true:
      * <ul><li>the values array is null</li>
      *     <li>the weights array is null</li>
      *     <li>the weights array does not have the same length as the values array</li>
@@ -185,10 +188,11 @@ public class Sum extends AbstractStorele
      * @param values the input array
      * @param weights the weights array
      * @return the sum of the values or Double.NaN if length = 0
-     * @throws IllegalArgumentException if the parameters are not valid
+     * @throws MathIllegalArgumentException if the parameters are not valid
      * @since 2.1
      */
-    public double evaluate(final double[] values, final double[] weights) {
+    public double evaluate(final double[] values, final double[] weights)
+    throws MathIllegalArgumentException {
         return evaluate(values, weights, 0, values.length);
     }
 
@@ -198,6 +202,7 @@ public class Sum extends AbstractStorele
     @Override
     public Sum copy() {
         Sum result = new Sum();
+        // No try-catch or advertised exception because args are valid
         copy(this, result);
         return result;
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/SumOfLogs.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/SumOfLogs.java?rev=1385386&r1=1385385&r2=1385386&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/SumOfLogs.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/SumOfLogs.java Sun Sep 16 22:11:15 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.FastMath;
@@ -71,8 +72,9 @@ public class SumOfLogs extends AbstractS
      * to the {@code original}
      *
      * @param original the {@code SumOfLogs} instance to copy
+     * @throws NullArgumentException if original is null
      */
-    public SumOfLogs(SumOfLogs original) {
+    public SumOfLogs(SumOfLogs original) throws NullArgumentException {
         copy(original, this);
     }
 
@@ -114,7 +116,7 @@ public class SumOfLogs extends AbstractS
      * the input array, or <code>Double.NaN</code> if the designated subarray
      * is empty.
      * <p>
-     * Throws <code>IllegalArgumentException</code> if the array is null.</p>
+     * Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
      * <p>
      * See {@link SumOfLogs}.</p>
      *
@@ -123,11 +125,12 @@ public class SumOfLogs extends AbstractS
      * @param length the number of elements to include
      * @return the sum of the natural logs of the values or 0 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 sumLog = Double.NaN;
         if (test(values, begin, length, true)) {
             sumLog = 0.0;
@@ -144,6 +147,7 @@ public class SumOfLogs extends AbstractS
     @Override
     public SumOfLogs copy() {
         SumOfLogs result = new SumOfLogs();
+        // No try-catch or advertised exception here because args are valid
         copy(this, result);
         return result;
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/SumOfSquares.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/SumOfSquares.java?rev=1385386&r1=1385385&r2=1385386&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/SumOfSquares.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/summary/SumOfSquares.java Sun Sep 16 22:11:15 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;
@@ -62,8 +63,9 @@ public class SumOfSquares extends Abstra
      * to the {@code original}
      *
      * @param original the {@code SumOfSquares} instance to copy
+     * @throws NullArgumentException if original is null
      */
-    public SumOfSquares(SumOfSquares original) {
+    public SumOfSquares(SumOfSquares original) throws NullArgumentException {
         copy(original, this);
     }
 
@@ -105,17 +107,18 @@ public class SumOfSquares extends Abstra
      * the input array, or <code>Double.NaN</code> if the designated subarray
      * is empty.
      * <p>
-     * Throws <code>IllegalArgumentException</code> if the array is null.</p>
+     * Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
      *
      * @param values the input array
      * @param begin index of the first array element to include
      * @param length the number of elements to include
      * @return the sum of the squares of the values or 0 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 sumSq = Double.NaN;
         if (test(values, begin, length, true)) {
             sumSq = 0.0;
@@ -132,6 +135,7 @@ public class SumOfSquares extends Abstra
     @Override
     public SumOfSquares copy() {
         SumOfSquares result = new SumOfSquares();
+        // no try-catch or advertised exception here because args are valid
         copy(this, result);
         return result;
     }