From 8d01241820c093ab1fffa46b8c386f27009c4e27 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Wed, 23 Feb 2011 09:45:42 +0000 Subject: [PATCH] another round of exception incompatibilities squashing git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_X@1073658 13f79535-47bb-0310-9956-ffa450edef68 --- .../math/exception/NoDataException.java | 2 +- .../commons/math/fraction/BigFraction.java | 29 +++++++++---------- .../optimization/UnivariateRealOptimizer.java | 1 + .../commons/math/util/DefaultTransformer.java | 4 +-- .../math/fraction/BigFractionTest.java | 25 ++++++++-------- .../math/util/DefaultTransformerTest.java | 5 ++-- 6 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/apache/commons/math/exception/NoDataException.java b/src/main/java/org/apache/commons/math/exception/NoDataException.java index f87de1c2c..c1b4d5666 100644 --- a/src/main/java/org/apache/commons/math/exception/NoDataException.java +++ b/src/main/java/org/apache/commons/math/exception/NoDataException.java @@ -25,7 +25,7 @@ import org.apache.commons.math.exception.util.LocalizedFormats; * @since 2.2 * @version $Revision$ $Date$ */ -public class NoDataException extends MathIllegalArgumentException { +public class NoDataException extends MathIllegalStateException { /** Serializable version Id. */ private static final long serialVersionUID = -3629324471511904459L; diff --git a/src/main/java/org/apache/commons/math/fraction/BigFraction.java b/src/main/java/org/apache/commons/math/fraction/BigFraction.java index 52498af38..2bcce28e3 100644 --- a/src/main/java/org/apache/commons/math/fraction/BigFraction.java +++ b/src/main/java/org/apache/commons/math/fraction/BigFraction.java @@ -23,7 +23,6 @@ import java.math.BigInteger; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.util.LocalizedFormats; -import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.util.FastMath; @@ -115,10 +114,10 @@ public class BigFraction */ public BigFraction(BigInteger num, BigInteger den) { if (num == null) { - throw new NullArgumentException(LocalizedFormats.NUMERATOR); + throw new NullPointerException(LocalizedFormats.NUMERATOR.getSourceString()); } if (den == null) { - throw new NullArgumentException(LocalizedFormats.DENOMINATOR); + throw new NullPointerException(LocalizedFormats.DENOMINATOR.getSourceString()); } if (BigInteger.ZERO.equals(den)) { throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); @@ -501,11 +500,11 @@ public class BigFraction * @param fraction * the {@link BigFraction} to add, must not be null. * @return a {@link BigFraction} instance with the resulting values. - * @throws NullArgumentException if the {@link BigFraction} is {@code null}. + * @throws NullPointerException if the {@link BigFraction} is {@code null}. */ public BigFraction add(final BigFraction fraction) { if (fraction == null) { - throw new NullArgumentException(LocalizedFormats.FRACTION); + throw new NullPointerException(LocalizedFormats.FRACTION.getSourceString()); } if (ZERO.equals(fraction)) { return this; @@ -657,12 +656,12 @@ public class BigFraction * * @param fraction Fraction to divide by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. - * @throws NullArgumentException if the {@code fraction} is {@code null}. + * @throws NullPointerException if the {@code fraction} is {@code null}. * @throws ArithmeticException if the fraction to divide by is zero. */ public BigFraction divide(final BigFraction fraction) { if (fraction == null) { - throw new NullArgumentException(LocalizedFormats.FRACTION); + throw new NullPointerException(LocalizedFormats.FRACTION.getSourceString()); } if (BigInteger.ZERO.equals(fraction.numerator)) { throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); @@ -844,11 +843,11 @@ public class BigFraction * * @param bg the {@code BigInteger} to multiply by. * @return a {@code BigFraction} instance with the resulting values. - * @throws NullArgumentException if {@code bg} is {@code null}. + * @throws NullPointerException if {@code bg} is {@code null}. */ public BigFraction multiply(final BigInteger bg) { if (bg == null) { - throw new NullArgumentException(); + throw new NullPointerException(); } return new BigFraction(bg.multiply(numerator), denominator); } @@ -889,11 +888,11 @@ public class BigFraction * * @param fraction Fraction to multiply by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. - * @throws NullArgumentException if {@code fraction} is {@code null}. + * @throws NullPointerException if {@code fraction} is {@code null}. */ public BigFraction multiply(final BigFraction fraction) { if (fraction == null) { - throw new NullArgumentException(LocalizedFormats.FRACTION); + throw new NullPointerException(LocalizedFormats.FRACTION.getSourceString()); } if (numerator.equals(BigInteger.ZERO) || fraction.numerator.equals(BigInteger.ZERO)) { @@ -1031,11 +1030,11 @@ public class BigFraction * * @param bg the {@link BigInteger} to subtract, cannot be {@code null}. * @return a {@code BigFraction} instance with the resulting values. - * @throws NullArgumentException if the {@link BigInteger} is {@code null}. + * @throws NullPointerException if the {@link BigInteger} is {@code null}. */ public BigFraction subtract(final BigInteger bg) { if (bg == null) { - throw new NullArgumentException(); + throw new NullPointerException(); } return new BigFraction(numerator.subtract(denominator.multiply(bg)), denominator); } @@ -1077,11 +1076,11 @@ public class BigFraction * * @param fraction {@link BigFraction} to subtract, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values - * @throws NullArgumentException if the {@code fraction} is {@code null}. + * @throws NullPointerException if the {@code fraction} is {@code null}. */ public BigFraction subtract(final BigFraction fraction) { if (fraction == null) { - throw new NullArgumentException(LocalizedFormats.FRACTION); + throw new NullPointerException(LocalizedFormats.FRACTION.getSourceString()); } if (ZERO.equals(fraction)) { return this; diff --git a/src/main/java/org/apache/commons/math/optimization/UnivariateRealOptimizer.java b/src/main/java/org/apache/commons/math/optimization/UnivariateRealOptimizer.java index 11a70fa66..38ecc9476 100644 --- a/src/main/java/org/apache/commons/math/optimization/UnivariateRealOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/UnivariateRealOptimizer.java @@ -88,6 +88,7 @@ public interface UnivariateRealOptimizer extends ConvergingAlgorithm { * @throws FunctionEvaluationException if an error occurs evaluating the function. * @throws IllegalArgumentException if min > max or the arguments do not * satisfy the requirements specified by the optimizer. + * @throws IllegalStateException if there are no data. */ double optimize(UnivariateRealFunction f, GoalType goalType, double min, double max, double startValue) diff --git a/src/main/java/org/apache/commons/math/util/DefaultTransformer.java b/src/main/java/org/apache/commons/math/util/DefaultTransformer.java index e37184172..6699792bb 100644 --- a/src/main/java/org/apache/commons/math/util/DefaultTransformer.java +++ b/src/main/java/org/apache/commons/math/util/DefaultTransformer.java @@ -21,7 +21,6 @@ import java.io.Serializable; import org.apache.commons.math.MathException; import org.apache.commons.math.exception.util.LocalizedFormats; -import org.apache.commons.math.exception.NullArgumentException; /** * A Default NumberTransformer for java.lang.Numbers and Numeric Strings. This @@ -40,12 +39,11 @@ public class DefaultTransformer implements NumberTransformer, Serializable { * @param o the object that gets transformed. * @return a double primitive representation of the Object o. * @throws MathException if it cannot successfully be transformed. - * @throws NullArgumentException if is {@code null}. * @see Commons Collections Transformer */ public double transform(Object o) throws MathException { if (o == null) { - throw new NullArgumentException(LocalizedFormats.OBJECT_TRANSFORMATION); + throw new MathException(LocalizedFormats.OBJECT_TRANSFORMATION); } if (o instanceof Number) { diff --git a/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java b/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java index c15e0ecc7..70096e253 100644 --- a/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java +++ b/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java @@ -21,7 +21,6 @@ import java.math.BigInteger; import org.apache.commons.math.ConvergenceException; import org.apache.commons.math.TestUtils; -import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.util.FastMath; import junit.framework.TestCase; @@ -66,14 +65,14 @@ public class BigFractionTest extends TestCase { assertFraction(1055531162664967l, 70368744177664l, new BigFraction(15.0000000000001)); try { new BigFraction(null, BigInteger.ONE); - fail("Expecting NullArgumentException"); - } catch (NullArgumentException npe) { + fail("Expecting NullPointerException"); + } catch (NullPointerException npe) { // expected } try { new BigFraction(BigInteger.ONE, null); - fail("Expecting NullArgumentException"); - } catch (NullArgumentException npe) { + fail("Expecting NullPointerException"); + } catch (NullPointerException npe) { // expected } try { @@ -330,8 +329,8 @@ public class BigFractionTest extends TestCase { try { f.add((BigFraction) null); - fail("expecting NullArgumentException"); - } catch (NullArgumentException ex) { + fail("expecting NullPointerException"); + } catch (NullPointerException ex) { } // if this fraction is added naively, it will overflow. @@ -418,8 +417,8 @@ public class BigFractionTest extends TestCase { try { f.divide((BigFraction) null); - fail("expecting NullArgumentException"); - } catch (NullArgumentException ex) { + fail("expecting NullPointerException"); + } catch (NullPointerException ex) { } f1 = new BigFraction(Integer.MIN_VALUE, Integer.MAX_VALUE); @@ -464,8 +463,8 @@ public class BigFractionTest extends TestCase { try { f.multiply((BigFraction) null); - fail("expecting NullArgumentException"); - } catch (NullArgumentException ex) { + fail("expecting NullPointerException"); + } catch (NullPointerException ex) { } } @@ -482,8 +481,8 @@ public class BigFractionTest extends TestCase { BigFraction f = new BigFraction(1, 1); try { f.subtract((BigFraction) null); - fail("expecting NullArgumentException"); - } catch (NullArgumentException ex) { + fail("expecting NullPointerException"); + } catch (NullPointerException ex) { } // if this fraction is subtracted naively, it will overflow. diff --git a/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java b/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java index 627a221d9..4951f6fbf 100644 --- a/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java +++ b/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java @@ -23,7 +23,6 @@ import junit.framework.TestCase; import org.apache.commons.math.MathException; import org.apache.commons.math.TestUtils; -import org.apache.commons.math.exception.NullArgumentException; /** * @version $Revision$ $Date$ @@ -46,8 +45,8 @@ public class DefaultTransformerTest extends TestCase { DefaultTransformer t = new DefaultTransformer(); try { t.transform(null); - fail("Expecting NullArgumentException"); - } catch (NullArgumentException e) { + fail("Expecting MathException"); + } catch (MathException e) { // expected } }