From 9e69a3400847abbff912f1848e29d7eee6643f5d Mon Sep 17 00:00:00 2001
From: Phil Steitz
- * Throws
*
- * Throws
*
* The stored array is the one which was set by previous calls to
+ * {@link #setData(double[])}
* Double.NaN
if the designated subarray
* is empty.
* IllegalArgumentException
if the array is null or
+ * Throws MathIllegalArgumentException
if the array is null or
* the array index parameters are not valid.
@@ -122,11 +124,12 @@ public class Max extends AbstractStorelessUnivariateStatistic implements Seriali
* @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 AbstractStorelessUnivariateStatistic implements Seriali
@Override
public Max copy() {
Max result = new Max();
+ // No try-catch or advertised exception because args are non-null
copy(this, result);
return result;
}
diff --git a/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Median.java b/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Median.java
index 2c88ea080..b6ea2905f 100644
--- a/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Median.java
+++ b/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Median.java
@@ -18,6 +18,8 @@ package org.apache.commons.math3.stat.descriptive.rank;
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 implements Serializable {
* 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 implements Serializable {
* 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);
}
diff --git a/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Min.java b/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Min.java
index 1c3cd72d7..3dc4eb586 100644
--- a/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Min.java
+++ b/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Min.java
@@ -18,6 +18,7 @@ package org.apache.commons.math3.stat.descriptive.rank;
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 AbstractStorelessUnivariateStatistic implements Seriali
* 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 AbstractStorelessUnivariateStatistic implements Seriali
* the input array, or
Double.NaN
if the designated subarray
* is empty.
* IllegalArgumentException
if the array is null or
+ * Throws MathIllegalArgumentException
if the array is null or
* the array index parameters are not valid.
@@ -122,11 +124,12 @@ public class Min extends AbstractStorelessUnivariateStatistic implements Seriali
* @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 AbstractStorelessUnivariateStatistic implements Seriali
@Override
public Min copy() {
Min result = new Min();
+ // No try-catch or advertised exception - args are non-null
copy(this, result);
return result;
}
diff --git a/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Percentile.java b/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Percentile.java
index 2095c3bde..db447aa8e 100644
--- a/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Percentile.java
+++ b/src/main/java/org/apache/commons/math3/stat/descriptive/rank/Percentile.java
@@ -19,6 +19,7 @@ package org.apache.commons.math3.stat.descriptive.rank;
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 AbstractUnivariateStatistic implements Serializa
* 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 AbstractUnivariateStatistic implements Serializa
* 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 AbstractUnivariateStatistic implements Serializa
/** {@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 AbstractUnivariateStatistic implements Serializa
* Returns the result of evaluating the statistic over the stored data.
*
0
* p
) values[0]
* if values
has length 1
IllegalArgumentException
if values
+ * MathIllegalArgumentException
if values
* is null or p is not a valid quantile value (p must be greater than 0
* and less than or equal to 100)
values
is null
+ * @throws MathIllegalArgumentException if values
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 AbstractUnivariateStatistic implements Serializa
* Double.NaN
if length = 0
quantile
)
* values[begin]
if length = 1
IllegalArgumentException
if values
- * is null, or start
or length
- * is invalidMathIllegalArgumentException
if values
+ * is null, or start
or length
is invalid* See {@link Percentile} for a description of the percentile estimation @@ -215,11 +222,12 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa * @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 AbstractUnivariateStatistic implements Serializa *
Double.NaN
if length = 0
p
) values[begin]
* if length = 1
IllegalArgumentException
if values
+ * MathIllegalArgumentException
if values
* is null , begin
or length
is invalid, or
* p
is not a valid quantile value (p must be greater than 0
* and less than or equal to 100)