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.geometry;
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   */
45  public enum LocalizedGeometryFormats implements Localizable {
46  
47      /** CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR. */
48      CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR("cannot normalize a zero norm vector"),
49  
50      /** CLOSE_VERTICES. */
51      CLOSE_VERTICES("too close vertices near point ({0}, {1}, {2})"),
52  
53      /** CLOSEST_ORTHOGONAL_MATRIX_HAS_NEGATIVE_DETERMINANT. */
54      CLOSEST_ORTHOGONAL_MATRIX_HAS_NEGATIVE_DETERMINANT("the closest orthogonal matrix has a negative determinant {0}"),
55  
56      /** CROSSING_BOUNDARY_LOOPS. */
57      CROSSING_BOUNDARY_LOOPS("some outline boundary loops cross each other"),
58  
59      /** EDGE_CONNECTED_TO_ONE_FACET. */
60      EDGE_CONNECTED_TO_ONE_FACET("edge joining points ({0}, {1}, {2}) and ({3}, {4}, {5}) is connected to one facet only"),
61  
62      /** FACET_ORIENTATION_MISMATCH. */
63      FACET_ORIENTATION_MISMATCH("facets orientation mismatch around edge joining points ({0}, {1}, {2}) and ({3}, {4}, {5})"),
64  
65      /** INCONSISTENT_STATE_AT_2_PI_WRAPPING. */
66      INCONSISTENT_STATE_AT_2_PI_WRAPPING("inconsistent state at 2\u03c0 wrapping"),
67  
68      /** NON_INVERTIBLE_TRANSFORM. */
69      NON_INVERTIBLE_TRANSFORM("non-invertible affine transform collapses some lines into single points"),
70  
71      /** NOT_CONVEX. */
72      NOT_CONVEX("vertices do not form a convex hull in CCW winding"),
73  
74      /** NOT_CONVEX_HYPERPLANES. */
75      NOT_CONVEX_HYPERPLANES("hyperplanes do not define a convex region"),
76  
77      /** NOT_SUPPORTED_IN_DIMENSION_N. */
78      NOT_SUPPORTED_IN_DIMENSION_N("method not supported in dimension {0}"),
79  
80      /** OUTLINE_BOUNDARY_LOOP_OPEN. */
81      OUTLINE_BOUNDARY_LOOP_OPEN("an outline boundary loop is open"),
82  
83      /** FACET_WITH_SEVERAL_BOUNDARY_LOOPS. */
84      FACET_WITH_SEVERAL_BOUNDARY_LOOPS("a facet has several boundary loops"),
85  
86      /** OUT_OF_PLANE. */
87      OUT_OF_PLANE("point ({0}, {1}, {2}) is out of plane"),
88  
89      /** ROTATION_MATRIX_DIMENSIONS. */
90      ROTATION_MATRIX_DIMENSIONS("a {0}x{1} matrix cannot be a rotation matrix"),
91  
92      /** UNABLE_TO_ORTHOGONOLIZE_MATRIX. */
93      UNABLE_TO_ORTHOGONOLIZE_MATRIX("unable to orthogonalize matrix in {0} iterations"),
94  
95      /** ZERO_NORM_FOR_ROTATION_AXIS. */
96      ZERO_NORM_FOR_ROTATION_AXIS("zero norm for rotation axis"),
97  
98      /** ZERO_NORM_FOR_ROTATION_DEFINING_VECTOR. */
99      ZERO_NORM_FOR_ROTATION_DEFINING_VECTOR("zero norm for rotation defining vector"),
100 
101     /** TOO_SMALL_TOLERANCE. */
102     TOO_SMALL_TOLERANCE("tolerance {0,number,0.00000E00} is not computationally feasible, it is smaller than {1} ({2,number,0.00000E00})"),
103 
104     /** INVALID_ROTATION_ORDER_NAME. */
105     INVALID_ROTATION_ORDER_NAME("the value {0} does not correspond to a rotation order");
106 
107     /** Source English format. */
108     private final String sourceFormat;
109 
110     /** Simple constructor.
111      * @param sourceFormat source English format to use when no
112      * localized version is available
113      */
114     LocalizedGeometryFormats(final String sourceFormat) {
115         this.sourceFormat = sourceFormat;
116     }
117 
118     /** {@inheritDoc} */
119     @Override
120     public String getSourceString() {
121         return sourceFormat;
122     }
123 
124     /** {@inheritDoc} */
125     @Override
126     public String getLocalizedString(final Locale locale) {
127         try {
128             final String path = LocalizedGeometryFormats.class.getName().replaceAll("\\.", "/");
129             ResourceBundle bundle =
130                     ResourceBundle.getBundle("assets/" + path, locale, new UTF8Control());
131             if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
132                 final String translated = bundle.getString(name());
133                 if ((translated != null) &&
134                     (translated.length() > 0) &&
135                     (!translated.toLowerCase(locale).contains("missing translation"))) {
136                     // the value of the resource is the translated format
137                     return translated;
138                 }
139             }
140 
141         } catch (MissingResourceException mre) { // NOPMD
142             // do nothing here
143         }
144 
145         // either the locale is not supported or the resource is unknown
146         // don't translate and fall back to using the source format
147         return sourceFormat;
148 
149     }
150 
151 }