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;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.util.FastMath;
@ -87,7 +87,7 @@ public abstract class BinaryFunction implements BivariateRealFunction {
};
/** {@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.
* @param fixedX fixed value of the first argument
@ -97,7 +97,7 @@ public abstract class BinaryFunction implements BivariateRealFunction {
return new ComposableFunction() {
@Override
/** {@inheritDoc} */
public double value(double x) throws MathUserException {
public double value(double x) throws FunctionEvaluationException {
return BinaryFunction.this.value(fixedX, x);
}
};
@ -111,7 +111,7 @@ public abstract class BinaryFunction implements BivariateRealFunction {
return new ComposableFunction() {
@Override
/** {@inheritDoc} */
public double value(double x) throws MathUserException {
public double value(double x) throws FunctionEvaluationException {
return BinaryFunction.this.value(x, fixedY);
}
};

View File

@ -17,7 +17,7 @@
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.
@ -32,9 +32,9 @@ public interface BivariateRealFunction {
* @param x Abscissa for which the function value should be computed.
* @param y Ordinate for which the function value should be computed.
* @return the value.
* @throws MathUserException if the function evaluation fails.
* @throws FunctionEvaluationException if the function evaluation fails.
*/
double value(double x, double y)
throws MathUserException;
throws FunctionEvaluationException;
}

View File

@ -17,7 +17,7 @@
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.
@ -33,8 +33,8 @@ public interface TrivariateRealFunction {
* @param y y-coordinate for which the function value should be computed.
* @param z z-coordinate for which the function value should be computed.
* @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)
throws MathUserException;
throws FunctionEvaluationException;
}

View File

@ -16,7 +16,7 @@
*/
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.
@ -30,8 +30,8 @@ public interface UnivariateMatrixFunction {
* Compute the value for the function.
* @param x the point for which the function value should be computed
* @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;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.FunctionEvaluationException;
/**
* An interface representing a univariate vectorial function.
@ -30,8 +30,8 @@ public interface UnivariateVectorialFunction {
* Compute the value for the function.
* @param x the point for which the function value should be computed
* @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;
import org.apache.commons.math.DimensionMismatchException;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.analysis.BivariateRealFunction;
import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.exception.OutOfRangeException;
@ -226,6 +227,7 @@ public class BicubicSplineInterpolatingFunction
* @param x x-coordinate.
* @param y y-coordinate.
* @return the value at point (x, y) of the selected partial derivative.
* @throws FunctionEvaluationException
*/
private double partialDerivative(int which, double x, double y) {
if (partialDerivatives == null) {
@ -244,10 +246,13 @@ public class BicubicSplineInterpolatingFunction
final double xN = (x - xval[i]) / (xval[i + 1] - xval[i]);
final double yN = (y - yval[j]) / (yval[j + 1] - yval[j]);
double result = Double.NaN;
result = partialDerivatives[which][i][j].value(xN, yN);
try {
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.MathRuntimeException;
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.util.FastMath;
@ -81,11 +81,11 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
}
/** {@inheritDoc} */
public double value(double z) throws MathUserException {
public double value(double z) throws FunctionEvaluationException {
try {
return evaluate(x, y, z);
} 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.analysis.UnivariateRealFunction;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.FunctionEvaluationException;
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
* @return the function value
* @throws MathUserException if a runtime error occurs
* @throws FunctionEvaluationException if a runtime error occurs
* @see UnivariateRealFunction#value(double)
*/
public double value(double z) throws MathUserException {
public double value(double z) throws FunctionEvaluationException {
return evaluate(a, c, z);
}
@ -153,11 +153,11 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* @param c the centers
* @param z the point at which the function value is to be computed
* @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
*/
public static double evaluate(double a[], double c[], double z)
throws MathUserException, IllegalArgumentException {
throws FunctionEvaluationException, IllegalArgumentException {
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.solvers.BrentSolver;
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.random.RandomDataImpl;
import org.apache.commons.math.util.FastMath;
@ -96,15 +96,15 @@ public abstract class AbstractContinuousDistribution
// subclasses can override if there is a better method.
UnivariateRealFunction rootFindingFunction =
new UnivariateRealFunction() {
public double value(double x) throws MathUserException {
public double value(double x) throws FunctionEvaluationException {
double ret = Double.NaN;
try {
ret = cumulativeProbability(x) - p;
} 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)) {
throw new MathUserException(LocalizedFormats.CUMULATIVE_PROBABILITY_RETURNED_NAN, x, p);
throw new FunctionEvaluationException(x, LocalizedFormats.CUMULATIVE_PROBABILITY_RETURNED_NAN, x, p);
}
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;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathException;
import org.apache.commons.math.DimensionMismatchException;
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>
*/
@Test
public void testSplinePartialDerivatives() {
public void testSplinePartialDerivatives() throws FunctionEvaluationException {
final int N = 4;
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.SinFunction;
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 junit.framework.TestCase;
@ -119,8 +119,8 @@ public final class NevilleInterpolatorTest extends TestCase {
double y[] = { 0.0, 4.0, 4.0, 2.5 };
UnivariateRealFunction p = interpolator.interpolate(x, y);
p.value(0.0);
fail("Expecting MathUserException - bad abscissas array");
} catch (MathUserException ex) {
fail("Expecting FunctionEvaluationException - bad abscissas array");
} catch (FunctionEvaluationException ex) {
// expected
}
}

View File

@ -16,6 +16,7 @@
*/
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.util.FastMath;
import org.apache.commons.math.analysis.TrivariateRealFunction;
@ -275,7 +276,7 @@ public final class TricubicSplineInterpolatingFunctionTest {
* </p>
*/
@Test
public void testPlane() {
public void testPlane() throws FunctionEvaluationException {
double[] xval = new double[] {3, 4, 5, 6.5};
double[] yval = new double[] {-4, -3, -1, 2, 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.
*/
@Test
public void testWave() {
public void testWave() throws FunctionEvaluationException {
double[] xval = new double[] {3, 4, 5, 6.5};
double[] yval = new double[] {-4, -3, -1, 2, 2.5};
double[] zval = new double[] {-12, -8, -5.5, -3, 0, 4};

View File

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

View File

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