From 2dbc66e4fdcfa51cea40f74db6e97b37a247a815 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Tue, 4 Oct 2011 14:14:02 +0000 Subject: [PATCH] Replaced obsolete exceptions. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1178806 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/math/exception/ZeroException.java | 5 +++-- .../math/genetics/RandomKeyMutation.java | 6 +++--- .../optimization/direct/BOBYQAOptimizer.java | 1 - .../math/random/EmpiricalDistributionImpl.java | 17 +++++++++-------- .../apache/commons/math/random/ValueServer.java | 10 +++++----- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/apache/commons/math/exception/ZeroException.java b/src/main/java/org/apache/commons/math/exception/ZeroException.java index f4798dc09..d82d3836f 100644 --- a/src/main/java/org/apache/commons/math/exception/ZeroException.java +++ b/src/main/java/org/apache/commons/math/exception/ZeroException.java @@ -41,8 +41,9 @@ public class ZeroException extends MathIllegalNumberException { * Construct the exception with a specific context. * * @param specific Specific context pattern. + * @param arguments Arguments. */ - public ZeroException(Localizable specific) { - super(specific, 0); + public ZeroException(Localizable specific, Object ... arguments) { + super(specific, 0, arguments); } } diff --git a/src/main/java/org/apache/commons/math/genetics/RandomKeyMutation.java b/src/main/java/org/apache/commons/math/genetics/RandomKeyMutation.java index 116d0f7c0..4ff2a444f 100644 --- a/src/main/java/org/apache/commons/math/genetics/RandomKeyMutation.java +++ b/src/main/java/org/apache/commons/math/genetics/RandomKeyMutation.java @@ -19,7 +19,7 @@ package org.apache.commons.math.genetics; import java.util.ArrayList; import java.util.List; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.MathIllegalArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; /** @@ -34,12 +34,12 @@ public class RandomKeyMutation implements MutationPolicy { /** * {@inheritDoc} * - * @throws IllegalArgumentException if original is not a + * @throws MathIllegalArgumentException if original is not a * {@link RandomKey} instance */ public Chromosome mutate(Chromosome original) { if (!(original instanceof RandomKey)) { - throw MathRuntimeException.createIllegalArgumentException( + throw new MathIllegalArgumentException( LocalizedFormats.RANDOMKEY_MUTATION_WRONG_CLASS, original.getClass().getSimpleName()); } diff --git a/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java b/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java index 96030e78d..2fcd836bd 100644 --- a/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java @@ -22,7 +22,6 @@ import java.util.Arrays; import org.apache.commons.math.analysis.MultivariateRealFunction; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.MathIllegalStateException; -import org.apache.commons.math.exception.MathInternalError; import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.OutOfRangeException; import org.apache.commons.math.exception.util.LocalizedFormats; diff --git a/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java b/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java index 2eff4d24b..463080ff0 100644 --- a/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java @@ -27,8 +27,10 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.MathIllegalArgumentException; +import org.apache.commons.math.exception.MathIllegalStateException; import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.exception.ZeroException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.stat.descriptive.StatisticalSummary; import org.apache.commons.math.stat.descriptive.SummaryStatistics; @@ -176,7 +178,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib da.computeStats(); fillBinStats(in); } catch (IOException e) { - throw new MathRuntimeException(e); + throw new MathIllegalStateException(e, LocalizedFormats.SIMPLE_MESSAGE, e.getLocalizedMessage()); } loaded = true; @@ -197,8 +199,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib DataAdapter da = new StreamDataAdapter(in); da.computeStats(); if (sampleStats.getN() == 0) { - throw MathRuntimeException.createEOFException(LocalizedFormats.URL_CONTAINS_NO_DATA, - url); + throw new ZeroException(LocalizedFormats.URL_CONTAINS_NO_DATA, url); } in = new BufferedReader(new InputStreamReader(url.openStream())); fillBinStats(in); @@ -279,7 +280,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib double[] inputArray = (double[]) in; return new ArrayDataAdapter(inputArray); } else { - throw MathRuntimeException.createIllegalArgumentException( + throw new MathIllegalArgumentException( LocalizedFormats.INPUT_DATA_FROM_UNSUPPORTED_DATASOURCE, in.getClass().getName(), BufferedReader.class.getName(), double[].class.getName()); @@ -427,12 +428,12 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib * Generates a random value from this distribution. * * @return the random value. - * @throws IllegalStateException if the distribution has not been loaded + * @throws MathIllegalStateException if the distribution has not been loaded */ public double getNextValue() throws IllegalStateException { if (!loaded) { - throw MathRuntimeException.createIllegalStateException(LocalizedFormats.DISTRIBUTION_NOT_LOADED); + throw new MathIllegalStateException(LocalizedFormats.DISTRIBUTION_NOT_LOADED); } // Start with a uniformly distributed random number in (0,1) @@ -452,7 +453,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib } } } - throw new MathRuntimeException(LocalizedFormats.NO_BIN_SELECTED); + throw new MathIllegalStateException(LocalizedFormats.NO_BIN_SELECTED); } /** diff --git a/src/main/java/org/apache/commons/math/random/ValueServer.java b/src/main/java/org/apache/commons/math/random/ValueServer.java index 04c4860fb..046c7e023 100644 --- a/src/main/java/org/apache/commons/math/random/ValueServer.java +++ b/src/main/java/org/apache/commons/math/random/ValueServer.java @@ -22,7 +22,7 @@ import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.MathIllegalStateException; import org.apache.commons.math.exception.util.LocalizedFormats; /** @@ -120,7 +120,7 @@ public class ValueServer { case EXPONENTIAL_MODE: return getNextExponential(); case GAUSSIAN_MODE: return getNextGaussian(); case CONSTANT_MODE: return mu; - default: throw MathRuntimeException.createIllegalStateException( + default: throw new MathIllegalStateException( LocalizedFormats.UNKNOWN_MODE, mode, "DIGEST_MODE", DIGEST_MODE, "REPLAY_MODE", REPLAY_MODE, @@ -352,7 +352,7 @@ public class ValueServer { private double getNextDigest() { if ((empiricalDistribution == null) || (empiricalDistribution.getBinStats().size() == 0)) { - throw MathRuntimeException.createIllegalStateException(LocalizedFormats.DIGEST_NOT_INITIALIZED); + throw new MathIllegalStateException(LocalizedFormats.DIGEST_NOT_INITIALIZED); } return empiricalDistribution.getNextValue(); } @@ -385,8 +385,8 @@ public class ValueServer { closeReplayFile(); resetReplayFile(); if ((str = filePointer.readLine()) == null) { - throw MathRuntimeException.createEOFException(LocalizedFormats.URL_CONTAINS_NO_DATA, - valuesFileURL); + throw new MathIllegalStateException(LocalizedFormats.URL_CONTAINS_NO_DATA, + valuesFileURL); } } return Double.valueOf(str).doubleValue();