View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  package org.hipparchus.migration;
23  
24  import java.util.Locale;
25  import java.util.MissingResourceException;
26  import java.util.ResourceBundle;
27  
28  import org.hipparchus.exception.Localizable;
29  import org.hipparchus.exception.UTF8Control;
30  
31  /**
32   * Enumeration for localized messages formats used in exceptions messages.
33   * <p>
34   * The constants in this enumeration represent the available
35   * formats as localized strings. These formats are intended to be
36   * localized using simple properties files, using the constant
37   * name as the key and the property value as the message format.
38   * The source English format is provided in the constants themselves
39   * to serve both as a reminder for developers to understand the parameters
40   * needed by each format, as a basis for translators to create
41   * localized properties files, and as a default format if some
42   * translation is missing.
43   * </p>
44   * @deprecated these formats are not used at all, they are intended only
45   * as a migration help from Apache Commons Math
46   */
47  @Deprecated
48  public enum LocalizedMigrationFormats implements Localizable {
49  
50      /** ARGUMENT_OUTSIDE_DOMAIN. */
51      ARGUMENT_OUTSIDE_DOMAIN("Argument {0} outside domain [{1} ; {2}]"),
52  
53      /** ASSYMETRIC_EIGEN_NOT_SUPPORTED. */
54      ASSYMETRIC_EIGEN_NOT_SUPPORTED("eigen decomposition of assymetric matrices not supported yet"),
55  
56      /** BOBYQA_BOUND_DIFFERENCE_CONDITION. */
57      BOBYQA_BOUND_DIFFERENCE_CONDITION("the difference between the upper and lower bound must be larger than twice the initial trust region radius ({0})"),
58  
59      /** CANNOT_CLEAR_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS. */
60      CANNOT_CLEAR_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS("statistics constructed from external moments cannot be cleared"),
61  
62      /** CANNOT_FORMAT_INSTANCE_AS_3D_VECTOR. */
63      CANNOT_FORMAT_INSTANCE_AS_3D_VECTOR("cannot format a {0} instance as a 3D vector"),
64  
65      /** CANNOT_FORMAT_INSTANCE_AS_REAL_VECTOR. */
66      CANNOT_FORMAT_INSTANCE_AS_REAL_VECTOR("cannot format a {0} instance as a real vector"),
67  
68      /** CANNOT_INCREMENT_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS. */
69      CANNOT_INCREMENT_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS("statistics constructed from external moments cannot be incremented"),
70  
71      /** CANNOT_RETRIEVE_AT_NEGATIVE_INDEX. */
72      CANNOT_RETRIEVE_AT_NEGATIVE_INDEX("elements cannot be retrieved from a negative array index {0}"),
73  
74      /** CANNOT_SET_AT_NEGATIVE_INDEX. */
75      CANNOT_SET_AT_NEGATIVE_INDEX("cannot set an element at a negative index {0}"),
76  
77      /** CANNOT_TRANSFORM_TO_DOUBLE. */
78      CANNOT_TRANSFORM_TO_DOUBLE("Conversion Exception in Transformation: {0}"),
79  
80      /** CARDAN_ANGLES_SINGULARITY. */
81      CARDAN_ANGLES_SINGULARITY("Cardan angles singularity"),
82  
83      /** CLASS_DOESNT_IMPLEMENT_COMPARABLE. */
84      CLASS_DOESNT_IMPLEMENT_COMPARABLE("class ({0}) does not implement Comparable"),
85  
86      /** COLUMN_INDEX_OUT_OF_RANGE. */
87      COLUMN_INDEX_OUT_OF_RANGE("column index {0} out of allowed range [{1}, {2}]"),
88  
89      /** DIMENSIONS_MISMATCH_SIMPLE. */
90      DIMENSIONS_MISMATCH_SIMPLE("{0} != {1}"),
91  
92      /** EMPTY_STRING_FOR_IMAGINARY_CHARACTER. */
93      EMPTY_STRING_FOR_IMAGINARY_CHARACTER("empty string for imaginary character"),
94  
95      /** EULER_ANGLES_SINGULARITY. */
96      EULER_ANGLES_SINGULARITY("Euler angles singularity"),
97  
98      /** FUNCTION_NOT_DIFFERENTIABLE. */
99      FUNCTION_NOT_DIFFERENTIABLE("function is not differentiable"),
100 
101     /** FUNCTION_NOT_POLYNOMIAL. */
102     FUNCTION_NOT_POLYNOMIAL("function is not polynomial"),
103 
104     /** INDEX_OUT_OF_RANGE. */
105     INDEX_OUT_OF_RANGE("index {0} out of allowed range [{1}, {2}]"),
106 
107     /** INVALID_BRACKETING_PARAMETERS. */
108     INVALID_BRACKETING_PARAMETERS("invalid bracketing parameters:  lower bound={0},  initial={1}, upper bound={2}"),
109 
110     /** INVALID_INTERVAL_INITIAL_VALUE_PARAMETERS. */
111     INVALID_INTERVAL_INITIAL_VALUE_PARAMETERS("invalid interval, initial value parameters:  lower={0}, initial={1}, upper={2}"),
112 
113     /** INVALID_ITERATIONS_LIMITS. */
114     INVALID_ITERATIONS_LIMITS("invalid iteration limits: min={0}, max={1}"),
115 
116     /** INVALID_REGRESSION_ARRAY. */
117     INVALID_REGRESSION_ARRAY("input data array length = {0} does not match the number of observations = {1} and the number of regressors = {2}"),
118 
119     /** ITERATOR_EXHAUSTED. */
120     ITERATOR_EXHAUSTED("iterator exhausted"),
121 
122     /** LOESS_EXPECTS_AT_LEAST_ONE_POINT. */
123     LOESS_EXPECTS_AT_LEAST_ONE_POINT("Loess expects at least 1 point"),
124 
125     /** MAP_MODIFIED_WHILE_ITERATING. */
126     MAP_MODIFIED_WHILE_ITERATING("map has been modified while iterating"),
127 
128     /** MAX_ITERATIONS_EXCEEDED. */
129     MAX_ITERATIONS_EXCEEDED("maximal number of iterations ({0}) exceeded"),
130 
131     /** MISMATCHED_LOESS_ABSCISSA_ORDINATE_ARRAYS. */
132     MISMATCHED_LOESS_ABSCISSA_ORDINATE_ARRAYS("Loess expects the abscissa and ordinate arrays to be of the same size, but got {0} abscissae and {1} ordinatae"),
133 
134     /** NEGATIVE_BRIGHTNESS_EXPONENT. */
135     NEGATIVE_BRIGHTNESS_EXPONENT("brightness exponent should be positive or null, but got {0}"),
136 
137     /** NEGATIVE_ELEMENT_AT_2D_INDEX. */
138     NEGATIVE_ELEMENT_AT_2D_INDEX("element ({0}, {1}) is negative: {2}"),
139 
140     /** NEGATIVE_NUMBER_OF_SUCCESSES. */
141     NEGATIVE_NUMBER_OF_SUCCESSES("number of successes must be non-negative ({0})"),
142 
143     /** NEGATIVE_NUMBER_OF_TRIALS. */
144     NEGATIVE_NUMBER_OF_TRIALS("number of trials must be non-negative ({0})"),
145 
146     /** NON_POSITIVE_DEFINITE_MATRIX. */
147     NON_POSITIVE_DEFINITE_MATRIX("not positive definite matrix: diagonal element at ({1},{1}) is smaller than {2} ({0})"),
148 
149     /** NON_POSITIVE_MICROSPHERE_ELEMENTS. */
150     NON_POSITIVE_MICROSPHERE_ELEMENTS("number of microsphere elements must be positive, but got {0}"),
151 
152     /** NON_POSITIVE_POLYNOMIAL_DEGREE. */
153     NON_POSITIVE_POLYNOMIAL_DEGREE("polynomial degree must be positive: degree={0}"),
154 
155     /** NON_REAL_FINITE_ABSCISSA. */
156     NON_REAL_FINITE_ABSCISSA("all abscissae must be finite real numbers, but {0}-th is {1}"),
157 
158     /** NON_REAL_FINITE_ORDINATE. */
159     NON_REAL_FINITE_ORDINATE("all ordinatae must be finite real numbers, but {0}-th is {1}"),
160 
161     /** NON_REAL_FINITE_WEIGHT. */
162     NON_REAL_FINITE_WEIGHT("all weights must be finite real numbers, but {0}-th is {1}"),
163 
164     /** NOT_ADDITION_COMPATIBLE_MATRICES. */
165     NOT_ADDITION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not addition compatible"),
166 
167     /** NOT_DECREASING_NUMBER_OF_POINTS. */
168     NOT_DECREASING_NUMBER_OF_POINTS("points {0} and {1} are not decreasing ({2} < {3})"),
169 
170     /** NOT_INCREASING_NUMBER_OF_POINTS. */
171     NOT_INCREASING_NUMBER_OF_POINTS("points {0} and {1} are not increasing ({2} > {3})"),
172 
173     /** NOT_MULTIPLICATION_COMPATIBLE_MATRICES. */
174     NOT_MULTIPLICATION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not multiplication compatible"),
175 
176     /** NOT_POSITIVE_DEGREES_OF_FREEDOM. */
177     NOT_POSITIVE_DEGREES_OF_FREEDOM("degrees of freedom must be positive ({0})"),
178 
179     /** NOT_POSITIVE_ELEMENT_AT_INDEX. */
180     NOT_POSITIVE_ELEMENT_AT_INDEX("element {0} is not positive: {1}"),
181 
182     /** NOT_POSITIVE_LENGTH. */
183     NOT_POSITIVE_LENGTH("length must be positive ({0})"),
184 
185     /** NOT_POSITIVE_MEAN. */
186     NOT_POSITIVE_MEAN("mean must be positive ({0})"),
187 
188     /** NOT_POSITIVE_PERMUTATION. */
189     NOT_POSITIVE_PERMUTATION("permutation k ({0}) must be positive"),
190 
191     /** NOT_POSITIVE_POISSON_MEAN. */
192     NOT_POSITIVE_POISSON_MEAN("the Poisson mean must be positive ({0})"),
193 
194     /** NOT_POSITIVE_POPULATION_SIZE. */
195     NOT_POSITIVE_POPULATION_SIZE("population size must be positive ({0})"),
196 
197     /** NOT_POSITIVE_ROW_DIMENSION. */
198     NOT_POSITIVE_ROW_DIMENSION("invalid row dimension: {0} (must be positive)"),
199 
200     /** NOT_POSITIVE_SAMPLE_SIZE. */
201     NOT_POSITIVE_SAMPLE_SIZE("sample size must be positive ({0})"),
202 
203     /** NOT_POSITIVE_SHAPE. */
204     NOT_POSITIVE_SHAPE("shape must be positive ({0})"),
205 
206     /** NOT_POSITIVE_STANDARD_DEVIATION. */
207     NOT_POSITIVE_STANDARD_DEVIATION("standard deviation must be positive ({0})"),
208 
209     /** NOT_POSITIVE_UPPER_BOUND. */
210     NOT_POSITIVE_UPPER_BOUND("upper bound must be positive ({0})"),
211 
212     /** NOT_STRICTLY_DECREASING_NUMBER_OF_POINTS. */
213     NOT_STRICTLY_DECREASING_NUMBER_OF_POINTS("points {0} and {1} are not strictly decreasing ({2} <= {3})"),
214 
215     /** NOT_STRICTLY_INCREASING_KNOT_VALUES. */
216     NOT_STRICTLY_INCREASING_KNOT_VALUES("knot values must be strictly increasing"),
217 
218     /** NOT_STRICTLY_INCREASING_NUMBER_OF_POINTS. */
219     NOT_STRICTLY_INCREASING_NUMBER_OF_POINTS("points {0} and {1} are not strictly increasing ({2} >= {3})"),
220 
221     /** NOT_SUBTRACTION_COMPATIBLE_MATRICES. */
222     NOT_SUBTRACTION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not subtraction compatible"),
223 
224     /** NOT_SYMMETRIC_MATRIX. */
225     NOT_SYMMETRIC_MATRIX("not symmetric matrix"),
226 
227     /** NO_BIN_SELECTED. */
228     NO_BIN_SELECTED("no bin selected"),
229 
230     /** NO_DEGREES_OF_FREEDOM. */
231     NO_DEGREES_OF_FREEDOM("no degrees of freedom ({0} measurements, {1} parameters)"),
232 
233     /** NO_DENSITY_FOR_THIS_DISTRIBUTION. */
234     NO_DENSITY_FOR_THIS_DISTRIBUTION("This distribution does not have a density function implemented"),
235 
236     /** NO_RESULT_AVAILABLE. */
237     NO_RESULT_AVAILABLE("no result available"),
238 
239     /** NO_SUCH_MATRIX_ENTRY. */
240     NO_SUCH_MATRIX_ENTRY("no entry at indices ({0}, {1}) in a {2}x{3} matrix"),
241 
242     /** N_POINTS_GAUSS_LEGENDRE_INTEGRATOR_NOT_SUPPORTED. */
243     N_POINTS_GAUSS_LEGENDRE_INTEGRATOR_NOT_SUPPORTED("{0} points Legendre-Gauss integrator not supported, number of points must be in the {1}-{2} range"),
244 
245     /** OBJECT_TRANSFORMATION. */
246     OBJECT_TRANSFORMATION("conversion exception in transformation"),
247 
248     /** OBSERVED_COUNTS_ALL_ZERO. */
249     OBSERVED_COUNTS_ALL_ZERO("observed counts are all 0 in observed array {0}"),
250 
251     /** OUT_OF_ORDER_ABSCISSA_ARRAY. */
252     OUT_OF_ORDER_ABSCISSA_ARRAY("the abscissae array must be sorted in a strictly increasing order, but the {0}-th element is {1} whereas {2}-th is {3}"),
253 
254     /** OUT_OF_RANGE_RIGHT. */
255     OUT_OF_RANGE_RIGHT("{0} out of [{1}, {2}) range"),
256 
257     /** POLYNOMIAL_INTERPOLANTS_MISMATCH_SEGMENTS. */
258     POLYNOMIAL_INTERPOLANTS_MISMATCH_SEGMENTS("number of polynomial interpolants must match the number of segments ({0} != {1} - 1)"),
259 
260     /** POWER_NEGATIVE_PARAMETERS. */
261     POWER_NEGATIVE_PARAMETERS("cannot raise an integral value to a negative power ({0}^{1})"),
262 
263     /** ROW_INDEX_OUT_OF_RANGE. */
264     ROW_INDEX_OUT_OF_RANGE("row index {0} out of allowed range [{1}, {2}]"),
265 
266     /** SAME_SIGN_AT_ENDPOINTS. */
267     SAME_SIGN_AT_ENDPOINTS("function values at endpoints do not have different signs, endpoints: [{0}, {1}], values: [{2}, {3}]"),
268 
269     /** UNABLE_TO_BRACKET_OPTIMUM_IN_LINE_SEARCH. */
270     UNABLE_TO_BRACKET_OPTIMUM_IN_LINE_SEARCH("unable to bracket optimum in line search"),
271 
272     /** UNABLE_TO_COMPUTE_COVARIANCE_SINGULAR_PROBLEM. */
273     UNABLE_TO_COMPUTE_COVARIANCE_SINGULAR_PROBLEM("unable to compute covariances: singular problem"),
274 
275     /** UNABLE_TO_FIRST_GUESS_HARMONIC_COEFFICIENTS. */
276     UNABLE_TO_FIRST_GUESS_HARMONIC_COEFFICIENTS("unable to first guess the harmonic coefficients"),
277 
278     /** UNPARSEABLE_3D_VECTOR. */
279     UNPARSEABLE_3D_VECTOR("unparseable 3D vector: \"{0}\""),
280 
281     /** UNPARSEABLE_COMPLEX_NUMBER. */
282     UNPARSEABLE_COMPLEX_NUMBER("unparseable complex number: \"{0}\""),
283 
284     /** UNPARSEABLE_REAL_VECTOR. */
285     UNPARSEABLE_REAL_VECTOR("unparseable real vector: \"{0}\""),
286 
287     /** UNSUPPORTED_EXPANSION_MODE. */
288     UNSUPPORTED_EXPANSION_MODE("unsupported expansion mode {0}, supported modes are {1} ({2}) and {3} ({4})"),
289 
290     /** VECTOR_LENGTH_MISMATCH. */
291     VECTOR_LENGTH_MISMATCH("vector length mismatch: got {0} but expected {1}"),
292 
293     /** WRONG_BLOCK_LENGTH. */
294     WRONG_BLOCK_LENGTH("wrong array shape (block length = {0}, expected {1})");
295 
296     /** Source English format. */
297     private final String sourceFormat;
298 
299     /** Simple constructor.
300      * @param sourceFormat source English format to use when no
301      * localized version is available
302      */
303     LocalizedMigrationFormats(final String sourceFormat) {
304         this.sourceFormat = sourceFormat;
305     }
306 
307     /** {@inheritDoc} */
308     @Override
309     public String getSourceString() {
310         return sourceFormat;
311     }
312 
313     /** {@inheritDoc} */
314     @Override
315     public String getLocalizedString(final Locale locale) {
316         try {
317             final String path = LocalizedMigrationFormats.class.getName().replaceAll("\\.", "/");
318             ResourceBundle bundle =
319                     ResourceBundle.getBundle("assets/" + path, locale, new UTF8Control());
320             if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
321                 final String translated = bundle.getString(name());
322                 if ((translated != null) &&
323                     (translated.length() > 0) &&
324                     (!translated.toLowerCase(locale).contains("missing translation"))) {
325                     // the value of the resource is the translated format
326                     return translated;
327                 }
328             }
329 
330         } catch (MissingResourceException mre) { // NOPMD
331             // do nothing here
332         }
333 
334         // either the locale is not supported or the resource is unknown
335         // don't translate and fall back to using the source format
336         return sourceFormat;
337 
338     }
339 
340 }