You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2010/07/09 23:40:19 UTC
svn commit: r962702 - in
/commons/proper/math/trunk/src/main/java/org/apache/commons/math:
analysis/polynomials/PolynomialFunction.java exception/NoDataException.java
Author: erans
Date: Fri Jul 9 21:40:19 2010
New Revision: 962702
URL: http://svn.apache.org/viewvc?rev=962702&view=rev
Log:
MATH-361
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java?rev=962702&r1=962701&r2=962702&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java Fri Jul 9 21:40:19 2010
@@ -19,7 +19,7 @@ package org.apache.commons.math.analysis
import java.io.Serializable;
import java.util.Arrays;
-import org.apache.commons.math.exception.NotStrictlyPositiveException;
+import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.util.LocalizedFormats;
@@ -58,20 +58,19 @@ public class PolynomialFunction implemen
*
* @param c polynomial coefficients
* @throws NullPointerException if c is null
- * @throws NotStrictlyPositiveException if c is empty
+ * @throws NoDataException if c is empty
*/
public PolynomialFunction(double c[]) {
super();
- if (c.length < 1) {
- throw new NotStrictlyPositiveException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY,
- c.length);
- }
- int l = c.length;
- while ((l > 1) && (c[l - 1] == 0)) {
- --l;
+ int n = c.length;
+ if (n == 0) {
+ throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
}
- this.coefficients = new double[l];
- System.arraycopy(c, 0, this.coefficients, 0, l);
+ while ((n > 1) && (c[n - 1] == 0)) {
+ --n;
+ }
+ this.coefficients = new double[n];
+ System.arraycopy(c, 0, this.coefficients, 0, n);
}
/**
@@ -118,14 +117,13 @@ public class PolynomialFunction implemen
* @param coefficients the coefficients of the polynomial to evaluate
* @param argument the input value
* @return the value of the polynomial
- * @throws NotStrictlyPositiveException if coefficients is empty
+ * @throws NoDataException if coefficients is empty
* @throws NullPointerException if coefficients is null
*/
protected static double evaluate(double[] coefficients, double argument) {
int n = coefficients.length;
- if (n < 1) {
- throw new NotStrictlyPositiveException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY,
- n);
+ if (n == 0) {
+ throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
}
double result = coefficients[n - 1];
for (int j = n -2; j >=0; j--) {
@@ -228,14 +226,13 @@ public class PolynomialFunction implemen
*
* @param coefficients the coefficients of the polynomial to differentiate
* @return the coefficients of the derivative or null if coefficients has length 1.
- * @throws NotStrictlyPositiveException if coefficients is empty
+ * @throws NoDataException if coefficients is empty
* @throws NullPointerException if coefficients is null
*/
protected static double[] differentiate(double[] coefficients) {
int n = coefficients.length;
- if (n < 1) {
- throw new NotStrictlyPositiveException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY,
- n);
+ if (n == 0) {
+ throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
}
if (n == 1) {
return new double[]{0};
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java?rev=962702&r1=962701&r2=962702&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java Fri Jul 9 21:40:19 2010
@@ -16,6 +16,7 @@
*/
package org.apache.commons.math.exception;
+import org.apache.commons.math.util.Localizable;
import org.apache.commons.math.util.LocalizedFormats;
/**
@@ -29,6 +30,14 @@ public class NoDataException extends Mat
* Construct the exception.
*/
public NoDataException() {
- super(LocalizedFormats.NO_DATA, null);
+ this(null);
+ }
+ /**
+ * Construct the exception with a specific context.
+ *
+ * @param specific Contextual information on what caused the exception.
+ */
+ public NoDataException(Localizable specific) {
+ super(specific, LocalizedFormats.NO_DATA, null);
}
}