[email protected] wrote: > Author: erans > Date: Thu Jul 8 23:45:06 2010 > New Revision: 962306 > > URL: http://svn.apache.org/viewvc?rev=962306&view=rev > Log: > MATH-361
Please include more detailed log messages with commits. A commit log message should include a summary of the changes made. Reference to associated JIRA tickets are necessary, but not sufficient for commit log messages. In this case, assuming I understand the changes correctly, the following would be better. It would be great to edit the commit log for the commit below to include something like the following: * Modified NumberIsTooSmallException to enable specification of whether or not the bound is included * Modified MathIllegalArgumentException and MathIllegalNumberException to separate general and specific message patterns * Modified interpolation classes using these exceptions to use the new message formats It would also help our consensus-building around exceptions refactoring if you made some specific proposals describing these changes before committing them. Phil * > > Modified:: > > commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/LinearInterpolator.java > > commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java > > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java > > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java > > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java > > commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/LocalizedFormats.java > > commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties > > Modified: > commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/LinearInterpolator.java > URL: > http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/LinearInterpolator.java?rev=962306&r1=962305&r2=962306&view=diff > ============================================================================== > --- > commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/LinearInterpolator.java > (original) > +++ > commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/LinearInterpolator.java > Thu Jul 8 23:45:06 2010 > @@ -21,6 +21,7 @@ import org.apache.commons.math.exception > import org.apache.commons.math.analysis.polynomials.PolynomialFunction; > import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; > import org.apache.commons.math.util.MathUtils; > +import org.apache.commons.math.util.LocalizedFormats; > > /** > * Implements a linear function for interpolation of real univariate > functions. > @@ -44,7 +45,8 @@ public class LinearInterpolator implemen > } > > if (x.length < 2) { > - throw new NumberIsTooSmallException(x.length, 2, true); > + throw new > NumberIsTooSmallException(LocalizedFormats.NUMBER_OF_POINTS, > + x.length, 2, true); > } > > // Number of intervals. The number of data points is n + 1. > @@ -68,5 +70,4 @@ public class LinearInterpolator implemen > > return new PolynomialSplineFunction(x, polynomials); > } > - > } > > Modified: > commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java > URL: > http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java?rev=962306&r1=962305&r2=962306&view=diff > ============================================================================== > --- > commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java > (original) > +++ > commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java > Thu Jul 8 23:45:06 2010 > @@ -21,6 +21,7 @@ import org.apache.commons.math.exception > import org.apache.commons.math.analysis.polynomials.PolynomialFunction; > import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; > import org.apache.commons.math.util.MathUtils; > +import org.apache.commons.math.util.LocalizedFormats; > > /** > * Computes a natural (also known as "free", "unclamped") cubic spline > interpolation for the data set. > @@ -69,7 +70,8 @@ public class SplineInterpolator implemen > } > > if (x.length < 3) { > - throw new NumberIsTooSmallException(x.length, 3, true); > + throw new > NumberIsTooSmallException(LocalizedFormats.NUMBER_OF_POINTS, > + x.length, 3, true); > } > > // Number of intervals. The number of data points is n + 1. > > Modified: > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java > URL: > http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java?rev=962306&r1=962305&r2=962306&view=diff > ============================================================================== > --- > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java > (original) > +++ > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java > Thu Jul 8 23:45:06 2010 > @@ -33,34 +33,66 @@ import org.apache.commons.math.util.Loca > */ > public class MathIllegalArgumentException extends IllegalArgumentException { > /** > - * Pattern used to build the message. > + * Pattern used to build the message (specific context). > */ > - private final Localizable pattern; > + private final Localizable specific; > + /** > + * Pattern used to build the message (general problem description). > + */ > + private final Localizable general; > /** > * Arguments used to build the message. > */ > private final Object[] arguments; > > /** > - * @param pattern Message pattern. > + * @param specific Message pattern providing the specific context of > + * the error. > + * @param general Message pattern explaining the cause of the error. > * @param args Arguments. > */ > - protected MathIllegalArgumentException(Localizable pattern, > + protected MathIllegalArgumentException(Localizable specific, > + Localizable general, > Object ... args) { > - this.pattern = pattern; > + this.specific = specific; > + this.general = general; > arguments = flatten(args).toArray(); > } > + /** > + * @param general Message pattern explaining the cause of the error. > + * @param args Arguments. > + */ > + protected MathIllegalArgumentException(Localizable general, > + Object ... args) { > + this(null, general, args); > + } > > /** {...@inheritdoc} */ > @Override > public String getMessage() { > - return MessageFactory.buildMessage(Locale.US, pattern, arguments); > + final StringBuilder sb = new StringBuilder(); > + > + if (specific != null) { > + sb.append(MessageFactory.buildMessage(Locale.US, specific, > arguments)); > + sb.append(": "); > + } > + sb.append(MessageFactory.buildMessage(Locale.US, general, > arguments)); > + > + return sb.toString(); > } > > /** {...@inheritdoc} */ > @Override > public String getLocalizedMessage() { > - return MessageFactory.buildMessage(Locale.getDefault(), pattern, > arguments); > + final StringBuilder sb = new StringBuilder(); > + > + if (specific != null) { > + sb.append(MessageFactory.buildMessage(Locale.getDefault(), > specific, arguments)); > + sb.append(": "); > + } > + sb.append(MessageFactory.buildMessage(Locale.getDefault(), general, > arguments)); > + > + return sb.toString(); > } > > /** > > Modified: > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java > URL: > http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java?rev=962306&r1=962305&r2=962306&view=diff > ============================================================================== > --- > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java > (original) > +++ > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java > Thu Jul 8 23:45:06 2010 > @@ -34,14 +34,30 @@ public class MathIllegalNumberException > /** > * Construct an exception. > * > - * @param pattern Localizable pattern. > + * @param specific Localizable pattern. > + * @param general Localizable pattern. > * @param arguments Arguments. The first element must be the requested > * value that raised the exception. > */ > - protected MathIllegalNumberException(Localizable pattern, > + protected MathIllegalNumberException(Localizable specific, > + Localizable general, > Number wrong, > Object ... arguments) { > - super(pattern, wrong, arguments); > + super(specific, general, wrong, arguments); > + argument = wrong; > + } > + > + /** > + * Construct an exception. > + * > + * @param general Localizable pattern. > + * @param arguments Arguments. The first element must be the requested > + * value that raised the exception. > + */ > + protected MathIllegalNumberException(Localizable general, > + Number wrong, > + Object ... arguments) { > + super(general, wrong, arguments); > argument = wrong; > } > > > Modified: > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java > URL: > http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java?rev=962306&r1=962305&r2=962306&view=diff > ============================================================================== > --- > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java > (original) > +++ > commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java > Thu Jul 8 23:45:06 2010 > @@ -16,6 +16,7 @@ > */ > package org.apache.commons.math.exception; > > +import org.apache.commons.math.util.Localizable; > import org.apache.commons.math.util.LocalizedFormats; > > /** > @@ -39,11 +40,28 @@ public class NumberIsTooSmallException e > * > * @param wrong Value that is smaller than the minimum. > * @param min minimum. > + * @param boundIsAllowed Whether {...@code min} is included in the > allowed range. > */ > public NumberIsTooSmallException(Number wrong, > Number min, > boolean boundIsAllowed) { > - super((boundIsAllowed ? > + this(null, wrong, min, boundIsAllowed); > + } > + > + /** > + * Construct the exception with a specific context. > + * > + * @param specific Specific contexte pattern . > + * @param wrong Value that is smaller than the minimum. > + * @param min minimum. > + * @param boundIsAllowed Whether {...@code min} is included in the > allowed range. > + */ > + public NumberIsTooSmallException(Localizable specific, > + Number wrong, > + Number min, > + boolean boundIsAllowed) { > + super(specific, > + (boundIsAllowed ? > LocalizedFormats.NUMBER_TOO_SMALL : > LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED), > wrong, min); > > 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=962306&r1=962305&r2=962306&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 > Thu Jul 8 23:45:06 2010 > @@ -279,6 +279,7 @@ public enum LocalizedFormats implements > WEIGHT_AT_LEAST_ONE_NON_ZERO("weigth array must contain at least one > non-zero value"), > WRONG_BLOCK_LENGTH("wrong array shape (block length = {0}, expected > {1})"), > WRONG_NUMBER_OF_POINTS("{0} points are required, got only {1}"), > + NUMBER_OF_POINTS("number of points ({0})"), /* keep */ > ZERO_DENOMINATOR("denominator must be different from 0"), > ZERO_DENOMINATOR_IN_FRACTION("zero denominator in fraction {0}/{1}"), > ZERO_FRACTION_TO_DIVIDE_BY("the fraction to divide by must not be zero: > {0}/{1}"), > > 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=962306&r1=962305&r2=962306&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 > Thu Jul 8 23:45:06 2010 > @@ -251,6 +251,7 @@ VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT = > WEIGHT_AT_LEAST_ONE_NON_ZERO = le tableau des poids doit contenir au moins > une valeur non nulle > WRONG_BLOCK_LENGTH = forme de tableau erron\u00e9e (bloc de longueur {0} au > lieu des {1} attendus > WRONG_NUMBER_OF_POINTS = {0} sont n\u00e9cessaires, seuls {1} ont > \u00e9t\u00e9 fournis > +NUMBER_OF_POINTS = nombre de points ({0}) > ZERO_DENOMINATOR = le d\u00e9nominateur doit \u00eatre diff\u00e9rent de 0 > ZERO_DENOMINATOR_IN_FRACTION = d\u00e9nominateur null dans le nombre > rationnel {0}/{1} > ZERO_FRACTION_TO_DIVIDE_BY = division par un nombre rationnel nul : {0}/{1} > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
