From commits-return-13181-apmail-commons-commits-archive=commons.apache.org@commons.apache.org Sun Aug 01 16:11:16 2010 Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 22302 invoked from network); 1 Aug 2010 16:11:16 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 Aug 2010 16:11:16 -0000 Received: (qmail 27108 invoked by uid 500); 1 Aug 2010 16:11:15 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 27027 invoked by uid 500); 1 Aug 2010 16:11:15 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 27020 invoked by uid 99); 1 Aug 2010 16:11:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 01 Aug 2010 16:11:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 01 Aug 2010 16:11:13 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 627CE23889EB; Sun, 1 Aug 2010 16:09:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r981254 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/genetics/ main/java/org/apache/commons/math/util/ main/resources/META-INF/localization/ test/java/org/apache/commons/math/util/ Date: Sun, 01 Aug 2010 16:09:57 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100801160957.627CE23889EB@eris.apache.org> Author: luc Date: Sun Aug 1 16:09:56 2010 New Revision: 981254 URL: http://svn.apache.org/viewvc?rev=981254&view=rev Log: improved error messages Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/ListPopulation.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/ListPopulation.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/ListPopulation.java?rev=981254&r1=981253&r2=981254&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/ListPopulation.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/ListPopulation.java Sun Aug 1 16:09:56 2010 @@ -20,6 +20,10 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.apache.commons.math.exception.NotPositiveException; +import org.apache.commons.math.exception.NumberIsTooLargeException; +import org.apache.commons.math.util.LocalizedFormats; + /** * Population of chromosomes represented by a {@link List}. * @@ -43,10 +47,11 @@ public abstract class ListPopulation imp */ public ListPopulation (List chromosomes, int populationLimit) { if (chromosomes.size() > populationLimit) { - throw new IllegalArgumentException("List of chromosomes bigger than maxPopulationSize."); + throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE, + chromosomes.size(), populationLimit, false); } if (populationLimit < 0) { - throw new IllegalArgumentException("Population limit has to be >= 0"); + throw new NotPositiveException(LocalizedFormats.POPULATION_LIMIT_NOT_POSITIVE, populationLimit); } this.chromosomes = chromosomes; @@ -61,7 +66,7 @@ public abstract class ListPopulation imp */ public ListPopulation (int populationLimit) { if (populationLimit < 0) { - throw new IllegalArgumentException("Population limit has to be >= 0"); + throw new NotPositiveException(LocalizedFormats.POPULATION_LIMIT_NOT_POSITIVE, populationLimit); } this.populationLimit = populationLimit; this.chromosomes = new ArrayList(populationLimit); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java?rev=981254&r1=981253&r2=981254&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java Sun Aug 1 16:09:56 2010 @@ -131,6 +131,7 @@ public enum LocalizedFormats implements ITERATOR_EXHAUSTED("iterator exhausted"), LCM_OVERFLOW_32_BITS("overflow: lcm({0}, {1}) is 2^31"), LCM_OVERFLOW_64_BITS("overflow: lcm({0}, {1}) is 2^63"), + LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE("list of chromosomes bigger than maxPopulationSize"), LOESS_EXPECTS_AT_LEAST_ONE_POINT("Loess expects at least 1 point"), LOWER_BOUND_NOT_BELOW_UPPER_BOUND("lower bound ({0}) must be strictly less than upper bound ({1})"), /* keep */ LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT("lower endpoint ({0}) must be less than or equal to upper endpoint ({1})"), @@ -238,10 +239,13 @@ public enum LocalizedFormats implements OUT_OF_RANGE_ROOT_OF_UNITY_INDEX("out of range root of unity index {0} (must be in [{1};{2}])"), OUT_OF_RANGE_SIMPLE("{0} out of [{1}, {2}] range"), /* keep */ OVERFLOW_IN_FRACTION("overflow in fraction {0}/{1}, cannot negate"), + OVERFLOW_IN_ADDITION("overflow in addition: {0} + {1}"), + OVERFLOW_IN_SUBTRACTION("overflow in subtraction: {0} - {1}"), PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD("cannot access {0} method in percentile implementation {1}"), PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD("percentile implementation {0} does not support {1}"), PERMUTATION_EXCEEDS_N("permutation size ({0}) exceeds permuation domain ({1})"), /* keep */ POLYNOMIAL_INTERPOLANTS_MISMATCH_SEGMENTS("number of polynomial interpolants must match the number of segments ({0} != {1} - 1)"), + POPULATION_LIMIT_NOT_POSITIVE("population limit has to be positive"), POSITION_SIZE_MISMATCH_INPUT_ARRAY("position {0} and size {1} don't fit to the size of the input array {2}"), POWER_NEGATIVE_PARAMETERS("cannot raise an integral value to a negative power ({0}^{1})"), PROPAGATION_DIRECTION_MISMATCH("propagation direction mismatch"), Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java?rev=981254&r1=981253&r2=981254&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java Sun Aug 1 16:09:56 2010 @@ -99,7 +99,7 @@ public final class MathUtils { public static int addAndCheck(int x, int y) { long s = (long)x + (long)y; if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) { - throw new ArithmeticException("overflow: add"); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, x, y); } return (int)s; } @@ -115,7 +115,7 @@ public final class MathUtils { * @since 1.2 */ public static long addAndCheck(long a, long b) { - return addAndCheck(a, b, "overflow: add"); + return addAndCheck(a, b, LocalizedFormats.OVERFLOW_IN_ADDITION); } /** @@ -123,17 +123,17 @@ public final class MathUtils { * * @param a an addend * @param b an addend - * @param msg the message to use for any thrown exception. + * @param pattern the pattern to use for any thrown exception. * @return the sum a+b * @throws ArithmeticException if the result can not be represented as an * long * @since 1.2 */ - private static long addAndCheck(long a, long b, String msg) { + private static long addAndCheck(long a, long b, Localizable pattern) { long ret; if (a > b) { // use symmetry to reduce boundary cases - ret = addAndCheck(b, a, msg); + ret = addAndCheck(b, a, pattern); } else { // assert a <= b @@ -143,7 +143,7 @@ public final class MathUtils { if (Long.MIN_VALUE - b <= a) { ret = a + b; } else { - throw new ArithmeticException(msg); + throw MathRuntimeException.createArithmeticException(pattern, a, b); } } else { // opposite sign addition is always safe @@ -157,7 +157,7 @@ public final class MathUtils { if (a <= Long.MAX_VALUE - b) { ret = a + b; } else { - throw new ArithmeticException(msg); + throw MathRuntimeException.createArithmeticException(pattern, a, b); } } } @@ -1544,7 +1544,7 @@ public final class MathUtils { public static int subAndCheck(int x, int y) { long s = (long)x - (long)y; if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) { - throw new ArithmeticException("overflow: subtract"); + throw MathRuntimeException.createArithmeticException(LocalizedFormats.OVERFLOW_IN_SUBTRACTION, x, y); } return (int)s; } @@ -1570,7 +1570,7 @@ public final class MathUtils { } } else { // use additive inverse - ret = addAndCheck(a, -b, msg); + ret = addAndCheck(a, -b, LocalizedFormats.OVERFLOW_IN_ADDITION); } return ret; } Modified: commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties?rev=981254&r1=981253&r2=981254&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties (original) +++ commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties Sun Aug 1 16:09:56 2010 @@ -102,6 +102,7 @@ INVALID_ROUNDING_METHOD = m\u00e9thode d ITERATOR_EXHAUSTED = it\u00e9ration achev\u00e9e LCM_OVERFLOW_32_BITS = d\u00e9passement de capacit\u00e9 : le MCM de {0} et {1} vaut 2^31 LCM_OVERFLOW_64_BITS = d\u00e9passement de capacit\u00e9 : le MCM de {0} et {1} vaut 2^63 +LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE = la liste des chromosomes d\u00e9passe maxPopulationSize LOESS_EXPECTS_AT_LEAST_ONE_POINT = la r\u00e9gression Loess n\u00e9cessite au moins un point LOWER_BOUND_NOT_BELOW_UPPER_BOUND = la borne inf\u00e9rieure ({0}) doit \u00eatre strictement plus petite que la borne sup\u00e9rieure ({1}) LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT = la borne inf\u00e9rieure ({0}) devrait \u00eatre inf\u00e9rieure @@ -198,7 +199,7 @@ NUMBER_TOO_LARGE = {0} est plus grand qu NUMBER_TOO_SMALL = {0} est plus petit que le minimum ({1}) NUMBER_TOO_LARGE_BOUND_EXCLUDED = {0} n''est pas strictement plus grand que le maximum ({1}) NUMBER_TOO_SMALL_BOUND_EXCLUDED = {0} n''est pas strictement plus petit que le minimum ({1}) -NUMBER_OF_SUCCESS_LARGER_THAN_POPULATION_SIZE = le nombre de succ\u00e8s doit \u00eatre inf\u00e9rieur +NUMBER_OF_SUCCESS_LARGER_THAN_POPULATION_SIZE = le nombre de succ\u00e8s ({0}) doit \u00eatre inf\u00e9rieur ou \u00e9gal \u00e0 la taille de la population ({1}) NUMERATOR_OVERFLOW_AFTER_MULTIPLY = d\u00e9passement de capacit\u00e9 pour le num\u00e9rateur apr\u00e8s multiplication : {0} N_POINTS_GAUSS_LEGENDRE_INTEGRATOR_NOT_SUPPORTED = l''int\u00e9grateur de Legendre-Gauss en {0} points n''est pas disponible, le nombre de points doit \u00eatre entre {1} et {2} OBSERVED_COUNTS_ALL_ZERO = aucune occurrence dans le tableau des observations {0} @@ -209,10 +210,13 @@ OUT_OF_ORDER_ABSCISSA_ARRAY = les abscis OUT_OF_RANGE_ROOT_OF_UNITY_INDEX = l''indice de racine de l''unit\u00e9 {0} est hors du domaine autoris\u00e9 [{1};{2}] OUT_OF_RANGE_SIMPLE = {0} hors du domaine [{1}, {2}] OVERFLOW_IN_FRACTION = d\u00e9passement de capacit\u00e9 pour la fraction {0}/{1}, son signe ne peut \u00eatre chang\u00e9 +OVERFLOW_IN_ADDITION = d\u00e9passement de capacit\u00e9 pour l''addition : {0} + {1} +OVERFLOW_IN_SUBTRACTION = d\u00e9passement de capacit\u00e9 pour la soustraction : {0} - {1} PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD = acc\u00e8s impossible \u00e0 la m\u00e9thode {0} PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD = l''implantation de pourcentage {0} ne dispose pas de la m\u00e9thode {1} PERMUTATION_EXCEEDS_N = la taille de la permutation ({0}) d\u00e9passe le domaine de la permutation ({1}) POLYNOMIAL_INTERPOLANTS_MISMATCH_SEGMENTS = le nombre d''interpolants polyn\u00f4miaux doit correspondre au nombre de segments ({0} != {1} - 1) +POPULATION_LIMIT_NOT_POSITIVE = la limite de population doit \u00eatre positive POSITION_SIZE_MISMATCH_INPUT_ARRAY = la position {0} et la taille {1} sont incompatibles avec la taille du tableau d''entr\u00e9e {2} POWER_NEGATIVE_PARAMETERS = impossible d''\u00e9lever une valeur enti\u00e8re PROPAGATION_DIRECTION_MISMATCH = directions de propagation incoh\u00e9rentes Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java?rev=981254&r1=981253&r2=981254&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java Sun Aug 1 16:09:56 2010 @@ -18,6 +18,7 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import junit.framework.TestCase; @@ -1328,7 +1329,7 @@ public final class MathUtilsTest extends MathUtils.subAndCheck(big, -1); fail("Expecting ArithmeticException"); } catch (ArithmeticException ex) { - assertEquals("overflow: subtract", ex.getMessage()); + assertTrue(ex.getMessage().length() > 1); } }