removed remaining bits of incompatible exception changes

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_X@1073498 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2011-02-22 20:57:26 +00:00
parent dedda82d12
commit 8b5a48e102
15 changed files with 54 additions and 198 deletions

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.analysis; package org.apache.commons.math.analysis;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
@ -87,7 +87,7 @@ public abstract class BinaryFunction implements BivariateRealFunction {
}; };
/** {@inheritDoc} */ /** {@inheritDoc} */
public abstract double value(double x, double y) throws MathUserException; public abstract double value(double x, double y) throws FunctionEvaluationException;
/** Get a composable function by fixing the first argument of the instance. /** Get a composable function by fixing the first argument of the instance.
* @param fixedX fixed value of the first argument * @param fixedX fixed value of the first argument
@ -97,7 +97,7 @@ public abstract class BinaryFunction implements BivariateRealFunction {
return new ComposableFunction() { return new ComposableFunction() {
@Override @Override
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) throws MathUserException { public double value(double x) throws FunctionEvaluationException {
return BinaryFunction.this.value(fixedX, x); return BinaryFunction.this.value(fixedX, x);
} }
}; };
@ -111,7 +111,7 @@ public abstract class BinaryFunction implements BivariateRealFunction {
return new ComposableFunction() { return new ComposableFunction() {
@Override @Override
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) throws MathUserException { public double value(double x) throws FunctionEvaluationException {
return BinaryFunction.this.value(x, fixedY); return BinaryFunction.this.value(x, fixedY);
} }
}; };

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.analysis; package org.apache.commons.math.analysis;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.FunctionEvaluationException;
/** /**
* An interface representing a bivariate real function. * An interface representing a bivariate real function.
@ -32,9 +32,9 @@ public interface BivariateRealFunction {
* @param x Abscissa for which the function value should be computed. * @param x Abscissa for which the function value should be computed.
* @param y Ordinate for which the function value should be computed. * @param y Ordinate for which the function value should be computed.
* @return the value. * @return the value.
* @throws MathUserException if the function evaluation fails. * @throws FunctionEvaluationException if the function evaluation fails.
*/ */
double value(double x, double y) double value(double x, double y)
throws MathUserException; throws FunctionEvaluationException;
} }

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.analysis; package org.apache.commons.math.analysis;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.FunctionEvaluationException;
/** /**
* An interface representing a trivariate real function. * An interface representing a trivariate real function.
@ -33,8 +33,8 @@ public interface TrivariateRealFunction {
* @param y y-coordinate for which the function value should be computed. * @param y y-coordinate for which the function value should be computed.
* @param z z-coordinate for which the function value should be computed. * @param z z-coordinate for which the function value should be computed.
* @return the value. * @return the value.
* @throws MathUserException if the function evaluation fails. * @throws FunctionEvaluationException if the function evaluation fails.
*/ */
double value(double x, double y, double z) double value(double x, double y, double z)
throws MathUserException; throws FunctionEvaluationException;
} }

View File

@ -16,7 +16,7 @@
*/ */
package org.apache.commons.math.analysis; package org.apache.commons.math.analysis;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.FunctionEvaluationException;
/** /**
* An interface representing a univariate matrix function. * An interface representing a univariate matrix function.
@ -30,8 +30,8 @@ public interface UnivariateMatrixFunction {
* Compute the value for the function. * Compute the value for the function.
* @param x the point for which the function value should be computed * @param x the point for which the function value should be computed
* @return the value * @return the value
* @throws MathUserException if the function evaluation fails * @throws FunctionEvaluationException if the function evaluation fails
*/ */
double[][] value(double x) throws MathUserException; double[][] value(double x) throws FunctionEvaluationException;
} }

View File

@ -16,7 +16,7 @@
*/ */
package org.apache.commons.math.analysis; package org.apache.commons.math.analysis;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.FunctionEvaluationException;
/** /**
* An interface representing a univariate vectorial function. * An interface representing a univariate vectorial function.
@ -30,8 +30,8 @@ public interface UnivariateVectorialFunction {
* Compute the value for the function. * Compute the value for the function.
* @param x the point for which the function value should be computed * @param x the point for which the function value should be computed
* @return the value * @return the value
* @throws MathUserException if the function evaluation fails * @throws FunctionEvaluationException if the function evaluation fails
*/ */
double[] value(double x) throws MathUserException; double[] value(double x) throws FunctionEvaluationException;
} }

View File

@ -17,6 +17,7 @@
package org.apache.commons.math.analysis.interpolation; package org.apache.commons.math.analysis.interpolation;
import org.apache.commons.math.DimensionMismatchException; import org.apache.commons.math.DimensionMismatchException;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.analysis.BivariateRealFunction; import org.apache.commons.math.analysis.BivariateRealFunction;
import org.apache.commons.math.exception.NoDataException; import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.exception.OutOfRangeException; import org.apache.commons.math.exception.OutOfRangeException;
@ -226,6 +227,7 @@ public class BicubicSplineInterpolatingFunction
* @param x x-coordinate. * @param x x-coordinate.
* @param y y-coordinate. * @param y y-coordinate.
* @return the value at point (x, y) of the selected partial derivative. * @return the value at point (x, y) of the selected partial derivative.
* @throws FunctionEvaluationException
*/ */
private double partialDerivative(int which, double x, double y) { private double partialDerivative(int which, double x, double y) {
if (partialDerivatives == null) { if (partialDerivatives == null) {
@ -244,10 +246,13 @@ public class BicubicSplineInterpolatingFunction
final double xN = (x - xval[i]) / (xval[i + 1] - xval[i]); final double xN = (x - xval[i]) / (xval[i + 1] - xval[i]);
final double yN = (y - yval[j]) / (yval[j + 1] - yval[j]); final double yN = (y - yval[j]) / (yval[j + 1] - yval[j]);
double result = Double.NaN; try {
result = partialDerivatives[which][i][j].value(xN, yN); return partialDerivatives[which][i][j].value(xN, yN);
} catch (FunctionEvaluationException fee) {
// this should never happen
throw new RuntimeException(fee);
}
return result;
} }
/** /**

View File

@ -19,7 +19,7 @@ package org.apache.commons.math.analysis.polynomials;
import org.apache.commons.math.DuplicateSampleAbscissaException; import org.apache.commons.math.DuplicateSampleAbscissaException;
import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
@ -81,11 +81,11 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double z) throws MathUserException { public double value(double z) throws FunctionEvaluationException {
try { try {
return evaluate(x, y, z); return evaluate(x, y, z);
} catch (DuplicateSampleAbscissaException e) { } catch (DuplicateSampleAbscissaException e) {
throw new MathUserException(e, e.getSpecificPattern(), e.getGeneralPattern(), e.getArguments()); throw new FunctionEvaluationException(z, e.getSpecificPattern(), e.getGeneralPattern(), e.getArguments());
} }
} }

View File

@ -18,7 +18,7 @@ package org.apache.commons.math.analysis.polynomials;
import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.exception.util.LocalizedFormats;
/** /**
@ -86,10 +86,10 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* *
* @param z the point at which the function value is to be computed * @param z the point at which the function value is to be computed
* @return the function value * @return the function value
* @throws MathUserException if a runtime error occurs * @throws FunctionEvaluationException if a runtime error occurs
* @see UnivariateRealFunction#value(double) * @see UnivariateRealFunction#value(double)
*/ */
public double value(double z) throws MathUserException { public double value(double z) throws FunctionEvaluationException {
return evaluate(a, c, z); return evaluate(a, c, z);
} }
@ -153,11 +153,11 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* @param c the centers * @param c the centers
* @param z the point at which the function value is to be computed * @param z the point at which the function value is to be computed
* @return the function value * @return the function value
* @throws MathUserException if a runtime error occurs * @throws FunctionEvaluationException if a runtime error occurs
* @throws IllegalArgumentException if inputs are not valid * @throws IllegalArgumentException if inputs are not valid
*/ */
public static double evaluate(double a[], double c[], double z) public static double evaluate(double a[], double c[], double z)
throws MathUserException, IllegalArgumentException { throws FunctionEvaluationException, IllegalArgumentException {
verifyInputArray(a, c); verifyInputArray(a, c);

View File

@ -24,7 +24,7 @@ import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.solvers.BrentSolver; import org.apache.commons.math.analysis.solvers.BrentSolver;
import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils; import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.random.RandomDataImpl; import org.apache.commons.math.random.RandomDataImpl;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
@ -96,15 +96,15 @@ public abstract class AbstractContinuousDistribution
// subclasses can override if there is a better method. // subclasses can override if there is a better method.
UnivariateRealFunction rootFindingFunction = UnivariateRealFunction rootFindingFunction =
new UnivariateRealFunction() { new UnivariateRealFunction() {
public double value(double x) throws MathUserException { public double value(double x) throws FunctionEvaluationException {
double ret = Double.NaN; double ret = Double.NaN;
try { try {
ret = cumulativeProbability(x) - p; ret = cumulativeProbability(x) - p;
} catch (MathException ex) { } catch (MathException ex) {
throw new MathUserException(ex, ex.getSpecificPattern(), ex.getGeneralPattern(), ex.getArguments()); throw new FunctionEvaluationException(x, ex.getSpecificPattern(), ex.getGeneralPattern(), ex.getArguments());
} }
if (Double.isNaN(ret)) { if (Double.isNaN(ret)) {
throw new MathUserException(LocalizedFormats.CUMULATIVE_PROBABILITY_RETURNED_NAN, x, p); throw new FunctionEvaluationException(x, LocalizedFormats.CUMULATIVE_PROBABILITY_RETURNED_NAN, x, p);
} }
return ret; return ret;
} }

View File

@ -1,155 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math.exception;
import java.util.Locale;
import org.apache.commons.math.exception.util.ArgUtils;
import org.apache.commons.math.exception.util.Localizable;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.exception.util.MessageFactory;
/**
* This class is intended as a sort of communication channel between
* layers of <em>user</em> code separated from each other by calls to
* the Commons-Math library.
* The Commons-Math code will never catch such an exception.
*
* @since 2.2
* @version $Revision$ $Date$
*/
public class MathUserException extends RuntimeException implements MathThrowable {
/** Serializable version Id. */
private static final long serialVersionUID = -6024911025449780478L;
/**
* Pattern used to build the specific part of the message (problem description).
*/
private final Localizable specific;
/**
* Pattern used to build the general part of the message (problem description).
*/
private final Localizable general;
/**
* Arguments used to build the message.
*/
private final Object[] arguments;
/**
* Build an exception with a default message.
*/
public MathUserException() {
this((Throwable) null);
}
/**
* Build an exception with a default message.
* @param cause Cause of the error (may be null).
*/
public MathUserException(final Throwable cause) {
this(cause, LocalizedFormats.USER_EXCEPTION);
}
/**
* Build an exception with a localizable message.
* @param pattern Format specifier.
* @param arguments Format arguments.
*/
public MathUserException(final Localizable pattern, final Object ... arguments) {
this((Throwable) null, pattern, arguments);
}
/**
* Build an exception with a localizable message.
* @param cause Cause of the error (may be null).
* @param pattern Format specifier.
* @param arguments Format arguments.
*/
public MathUserException(final Throwable cause,
final Localizable pattern, final Object ... arguments) {
this(cause, (Localizable) null, pattern, arguments);
}
/**
* Builds an exception from two patterns (specific and general) and
* an argument list.
*
* @param specific Format specifier for the specific part (may be null).
* @param general Format specifier for the general part (may be null).
* @param arguments Format arguments. They will be substituted in
* <em>both</em> the {@code general} and {@code specific} format specifiers.
*/
public MathUserException(final Localizable specific, final Localizable general,
final Object ... arguments) {
this((Throwable) null, specific, general, arguments);
}
/**
* Builds an exception from two patterns (specific and general) and
* an argument list.
*
* @param cause Cause of the error (may be null).
* @param specific Format specifier for the specific part (may be null).
* @param general Format specifier for the general part (may be null).
* @param arguments Format arguments. They will be substituted in
* <em>both</em> the {@code general} and {@code specific} format specifiers.
*/
public MathUserException(final Throwable cause,
final Localizable specific, final Localizable general,
final Object ... arguments) {
super(cause);
this.specific = specific;
this.general = general;
this.arguments = ArgUtils.flatten(arguments);
}
/** {@inheritDoc} */
public Localizable getSpecificPattern() {
return specific;
}
/** {@inheritDoc} */
public Localizable getGeneralPattern() {
return general;
}
/** {@inheritDoc} */
public Object[] getArguments() {
return arguments.clone();
}
/**
* Get the message in a specified locale.
*
* @param locale Locale in which the message should be translated.
* @return the localized message.
*/
public String getMessage(final Locale locale) {
return MessageFactory.buildMessage(locale, specific, general, arguments);
}
/** {@inheritDoc} */
@Override
public String getMessage() {
return getMessage(Locale.US);
}
/** {@inheritDoc} */
@Override
public String getLocalizedMessage() {
return getMessage(Locale.getDefault());
}
}

View File

@ -16,6 +16,7 @@
*/ */
package org.apache.commons.math.analysis.interpolation; package org.apache.commons.math.analysis.interpolation;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathException; import org.apache.commons.math.MathException;
import org.apache.commons.math.DimensionMismatchException; import org.apache.commons.math.DimensionMismatchException;
import org.apache.commons.math.analysis.BivariateRealFunction; import org.apache.commons.math.analysis.BivariateRealFunction;
@ -265,7 +266,7 @@ public final class BicubicSplineInterpolatingFunctionTest {
* f(x, y) = &Sigma;<sub>i</sub>&Sigma;<sub>j</sub> (i+1) (j+2) x<sup>i</sup> y<sup>j</sup> * f(x, y) = &Sigma;<sub>i</sub>&Sigma;<sub>j</sub> (i+1) (j+2) x<sup>i</sup> y<sup>j</sup>
*/ */
@Test @Test
public void testSplinePartialDerivatives() { public void testSplinePartialDerivatives() throws FunctionEvaluationException {
final int N = 4; final int N = 4;
final double[] coeff = new double[16]; final double[] coeff = new double[16];

View File

@ -20,7 +20,7 @@ import org.apache.commons.math.MathException;
import org.apache.commons.math.analysis.Expm1Function; import org.apache.commons.math.analysis.Expm1Function;
import org.apache.commons.math.analysis.SinFunction; import org.apache.commons.math.analysis.SinFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -119,8 +119,8 @@ public final class NevilleInterpolatorTest extends TestCase {
double y[] = { 0.0, 4.0, 4.0, 2.5 }; double y[] = { 0.0, 4.0, 4.0, 2.5 };
UnivariateRealFunction p = interpolator.interpolate(x, y); UnivariateRealFunction p = interpolator.interpolate(x, y);
p.value(0.0); p.value(0.0);
fail("Expecting MathUserException - bad abscissas array"); fail("Expecting FunctionEvaluationException - bad abscissas array");
} catch (MathUserException ex) { } catch (FunctionEvaluationException ex) {
// expected // expected
} }
} }

View File

@ -16,6 +16,7 @@
*/ */
package org.apache.commons.math.analysis.interpolation; package org.apache.commons.math.analysis.interpolation;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.analysis.TrivariateRealFunction; import org.apache.commons.math.analysis.TrivariateRealFunction;
@ -275,7 +276,7 @@ public final class TricubicSplineInterpolatingFunctionTest {
* </p> * </p>
*/ */
@Test @Test
public void testPlane() { public void testPlane() throws FunctionEvaluationException {
double[] xval = new double[] {3, 4, 5, 6.5}; double[] xval = new double[] {3, 4, 5, 6.5};
double[] yval = new double[] {-4, -3, -1, 2, 2.5}; double[] yval = new double[] {-4, -3, -1, 2, 2.5};
double[] zval = new double[] {-12, -8, -5.5, -3, 0, 2.5}; double[] zval = new double[] {-12, -8, -5.5, -3, 0, 2.5};
@ -380,7 +381,7 @@ public final class TricubicSplineInterpolatingFunctionTest {
* with A = 0.2, &omega; = 0.5, k<sub>x</sub> = 2, k<sub>y</sub> = 1. * with A = 0.2, &omega; = 0.5, k<sub>x</sub> = 2, k<sub>y</sub> = 1.
*/ */
@Test @Test
public void testWave() { public void testWave() throws FunctionEvaluationException {
double[] xval = new double[] {3, 4, 5, 6.5}; double[] xval = new double[] {3, 4, 5, 6.5};
double[] yval = new double[] {-4, -3, -1, 2, 2.5}; double[] yval = new double[] {-4, -3, -1, 2, 2.5};
double[] zval = new double[] {-12, -8, -5.5, -3, 0, 4}; double[] zval = new double[] {-12, -8, -5.5, -3, 0, 4};

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.math.analysis.polynomials; package org.apache.commons.math.analysis.polynomials;
import org.apache.commons.math.FunctionEvaluationException;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
@ -32,7 +34,7 @@ public final class PolynomialFunctionLagrangeFormTest extends TestCase {
/** /**
* Test of polynomial for the linear function. * Test of polynomial for the linear function.
*/ */
public void testLinearFunction() { public void testLinearFunction() throws FunctionEvaluationException {
PolynomialFunctionLagrangeForm p; PolynomialFunctionLagrangeForm p;
double c[], z, expected, result, tolerance = 1E-12; double c[], z, expected, result, tolerance = 1E-12;
@ -61,7 +63,7 @@ public final class PolynomialFunctionLagrangeFormTest extends TestCase {
/** /**
* Test of polynomial for the quadratic function. * Test of polynomial for the quadratic function.
*/ */
public void testQuadraticFunction() { public void testQuadraticFunction() throws FunctionEvaluationException {
PolynomialFunctionLagrangeForm p; PolynomialFunctionLagrangeForm p;
double c[], z, expected, result, tolerance = 1E-12; double c[], z, expected, result, tolerance = 1E-12;
@ -91,7 +93,7 @@ public final class PolynomialFunctionLagrangeFormTest extends TestCase {
/** /**
* Test of polynomial for the quintic function. * Test of polynomial for the quintic function.
*/ */
public void testQuinticFunction() { public void testQuinticFunction() throws FunctionEvaluationException {
PolynomialFunctionLagrangeForm p; PolynomialFunctionLagrangeForm p;
double c[], z, expected, result, tolerance = 1E-12; double c[], z, expected, result, tolerance = 1E-12;

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.math.analysis.polynomials; package org.apache.commons.math.analysis.polynomials;
import org.apache.commons.math.FunctionEvaluationException;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
@ -30,7 +32,7 @@ public final class PolynomialFunctionNewtonFormTest extends TestCase {
/** /**
* Test of polynomial for the linear function. * Test of polynomial for the linear function.
*/ */
public void testLinearFunction() { public void testLinearFunction() throws FunctionEvaluationException {
PolynomialFunctionNewtonForm p; PolynomialFunctionNewtonForm p;
double coefficients[], z, expected, result, tolerance = 1E-12; double coefficients[], z, expected, result, tolerance = 1E-12;
@ -59,7 +61,7 @@ public final class PolynomialFunctionNewtonFormTest extends TestCase {
/** /**
* Test of polynomial for the quadratic function. * Test of polynomial for the quadratic function.
*/ */
public void testQuadraticFunction() { public void testQuadraticFunction() throws FunctionEvaluationException {
PolynomialFunctionNewtonForm p; PolynomialFunctionNewtonForm p;
double coefficients[], z, expected, result, tolerance = 1E-12; double coefficients[], z, expected, result, tolerance = 1E-12;
@ -89,7 +91,7 @@ public final class PolynomialFunctionNewtonFormTest extends TestCase {
/** /**
* Test of polynomial for the quintic function. * Test of polynomial for the quintic function.
*/ */
public void testQuinticFunction() { public void testQuinticFunction() throws FunctionEvaluationException {
PolynomialFunctionNewtonForm p; PolynomialFunctionNewtonForm p;
double coefficients[], z, expected, result, tolerance = 1E-12; double coefficients[], z, expected, result, tolerance = 1E-12;