From 67ef6efb61f3c07e1359e083bbac5d90953cfe43 Mon Sep 17 00:00:00 2001 From: Hang Park Date: Thu, 15 Jun 2017 21:17:06 +0900 Subject: [PATCH] MATH-1419: Invalid usage of exception in PolynomialSplineFunction Fix order of parameter for NumberIsTooSmallException when length of knots is less than 2 in the constructor of PolynomialSplineFunction to be fit with the definition of the exception. Moreover, boundedIsAllowed value is changed to true since 2 is also allowed value. Change the error message format for this exception appropriately in English and French. Since this does not affect any error during using the library, but to make the code more concrete, following definition strictly is important things to implement functionalities. --- .../math4/analysis/polynomials/PolynomialSplineFunction.java | 2 +- .../apache/commons/math4/exception/util/LocalizedFormats.java | 2 +- .../commons/math4/exception/util/LocalizedFormats_fr.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialSplineFunction.java b/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialSplineFunction.java index b842a407f..d7263c2fd 100644 --- a/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialSplineFunction.java +++ b/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialSplineFunction.java @@ -105,7 +105,7 @@ public class PolynomialSplineFunction implements UnivariateDifferentiableFunctio } if (knots.length < 2) { throw new NumberIsTooSmallException(LocalizedFormats.NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION, - 2, knots.length, false); + knots.length, 2, true); } if (knots.length - 1 != polynomials.length) { throw new DimensionMismatchException(polynomials.length, knots.length); diff --git a/src/main/java/org/apache/commons/math4/exception/util/LocalizedFormats.java b/src/main/java/org/apache/commons/math4/exception/util/LocalizedFormats.java index dabe9a751..54b3efbb0 100644 --- a/src/main/java/org/apache/commons/math4/exception/util/LocalizedFormats.java +++ b/src/main/java/org/apache/commons/math4/exception/util/LocalizedFormats.java @@ -199,7 +199,7 @@ public enum LocalizedFormats implements Localizable { NOT_DECREASING_NUMBER_OF_POINTS("points {0} and {1} are not decreasing ({2} < {3})"), NOT_DECREASING_SEQUENCE("points {3} and {2} are not decreasing ({1} < {0})"), /* keep */ NOT_ENOUGH_DATA_FOR_NUMBER_OF_PREDICTORS("not enough data ({0} rows) for this many predictors ({1} predictors)"), - NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION("spline partition must have at least {0} points, got {1}"), + NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION("spline partition must have at least {1} points, got {0}"), NOT_INCREASING_NUMBER_OF_POINTS("points {0} and {1} are not increasing ({2} > {3})"), NOT_INCREASING_SEQUENCE("points {3} and {2} are not increasing ({1} > {0})"), /* keep */ NOT_MULTIPLICATION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not multiplication compatible"), diff --git a/src/main/resources/assets/org/apache/commons/math4/exception/util/LocalizedFormats_fr.properties b/src/main/resources/assets/org/apache/commons/math4/exception/util/LocalizedFormats_fr.properties index 5e0a9f110..b8a89a8a0 100644 --- a/src/main/resources/assets/org/apache/commons/math4/exception/util/LocalizedFormats_fr.properties +++ b/src/main/resources/assets/org/apache/commons/math4/exception/util/LocalizedFormats_fr.properties @@ -172,7 +172,7 @@ NOT_CONVEX_HYPERPLANES = les hyperplans ne d\u00e9finissent pas une r\u00e9gion NOT_DECREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas d\u00e9croissants ({2} < {3}) NOT_DECREASING_SEQUENCE = les points {3} et {2} ne sont pas d\u00e9croissants ({1} < {0}) NOT_ENOUGH_DATA_FOR_NUMBER_OF_PREDICTORS = pas assez de donn\u00e9es ({0} lignes) pour {1} pr\u00e9dicteurs -NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION = une partition spline n\u00e9cessite au moins {0} points, seuls {1} ont \u00e9t\u00e9 fournis +NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION = une partition spline n\u00e9cessite au moins {1} points, seuls {0} ont \u00e9t\u00e9 fournis NOT_INCREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas croissants ({2} > {3}) NOT_INCREASING_SEQUENCE = les points {3} et {2} ne sont pas croissants ({1} > {0}) NOT_MULTIPLICATION_COMPATIBLE_MATRICES = les dimensions {0}x{1} et {2}x{3} sont incompatibles pour la multiplication matricielle