@@ -61,60 +61,6 @@ public abstract class AbstractModelloGenerator implements ModelloGenerator {
6161
6262 private static final Map <String , String > PLURAL_EXCEPTIONS = new HashMap <>();
6363
64- static {
65- // Irregular names
66- PLURAL_EXCEPTIONS .put ("children" , "child" );
67- PLURAL_EXCEPTIONS .put ("feet" , "foot" );
68- PLURAL_EXCEPTIONS .put ("geese" , "goose" );
69- PLURAL_EXCEPTIONS .put ("indices" , "index" );
70- PLURAL_EXCEPTIONS .put ("men" , "man" );
71- PLURAL_EXCEPTIONS .put ("mice" , "mouse" );
72- PLURAL_EXCEPTIONS .put ("people" , "person" );
73- PLURAL_EXCEPTIONS .put ("teeth" , "tooth" );
74- PLURAL_EXCEPTIONS .put ("women" , "woman" );
75-
76- // Invariant names
77- PLURAL_EXCEPTIONS .put ("aircraft" , "aircraft" );
78- PLURAL_EXCEPTIONS .put ("bison" , "bison" );
79- PLURAL_EXCEPTIONS .put ("deer" , "deer" );
80- PLURAL_EXCEPTIONS .put ("elk" , "elk" );
81- PLURAL_EXCEPTIONS .put ("fish" , "fish" );
82- PLURAL_EXCEPTIONS .put ("series" , "series" );
83- PLURAL_EXCEPTIONS .put ("sheep" , "sheep" );
84- PLURAL_EXCEPTIONS .put ("species" , "species" );
85-
86- // Special "oes" exceptions
87- PLURAL_EXCEPTIONS .put ("buffaloes" , "buffalo" );
88- PLURAL_EXCEPTIONS .put ("cargoes" , "cargo" );
89- PLURAL_EXCEPTIONS .put ("echoes" , "echo" );
90- PLURAL_EXCEPTIONS .put ("goes" , "go" );
91- PLURAL_EXCEPTIONS .put ("haloes" , "halo" );
92- PLURAL_EXCEPTIONS .put ("heroes" , "hero" );
93- PLURAL_EXCEPTIONS .put ("mosquitoes" , "mosquito" );
94- PLURAL_EXCEPTIONS .put ("noes" , "no" );
95- PLURAL_EXCEPTIONS .put ("potatoes" , "potato" );
96- PLURAL_EXCEPTIONS .put ("tomatoes" , "tomato" );
97- PLURAL_EXCEPTIONS .put ("torpedoes" , "torpedo" );
98- PLURAL_EXCEPTIONS .put ("vetoes" , "veto" );
99- PLURAL_EXCEPTIONS .put ("volcanoes" , "volcano" );
100-
101- // Special "ses" exceptions
102- PLURAL_EXCEPTIONS .put ("horses" , "horse" );
103- PLURAL_EXCEPTIONS .put ("licenses" , "license" );
104- PLURAL_EXCEPTIONS .put ("phases" , "phase" );
105-
106- // Special "zzes" exceptions
107- PLURAL_EXCEPTIONS .put ("fezzes" , "fez" );
108- PLURAL_EXCEPTIONS .put ("whizzes" , "whiz" );
109-
110- // Special "ies" exceptions
111- PLURAL_EXCEPTIONS .put ("movies" , "movie" );
112-
113- // Special "ves" exceptions
114- PLURAL_EXCEPTIONS .put ("archives" , "archive" );
115- PLURAL_EXCEPTIONS .put ("relatives" , "relative" );
116- }
117-
11864 private Model model ;
11965
12066 private File outputDirectory ;
@@ -257,67 +203,27 @@ protected String capitalise(String str) {
257203 }
258204
259205 public static String singular (String name ) {
260- if (name == null || name .isEmpty ()) return name ;
261-
262- String lower = name .toLowerCase ();
263-
264- if (!lower .equals (name )) {
265- // we can have a case like otherArchives
266- String [] split = splitByUpperCase (name );
267- if (split != null && PLURAL_EXCEPTIONS .containsKey (split [1 ])) {
268- String plural = PLURAL_EXCEPTIONS .get (split [1 ]);
269- return split [0 ] + Character .toUpperCase (plural .charAt (0 )) + plural .substring (1 );
270- }
206+ if (StringUtils .isEmpty (name )) {
207+ return name ;
271208 }
272209
273- if (PLURAL_EXCEPTIONS .containsKey (lower )) {
274- return PLURAL_EXCEPTIONS .get (lower );
210+ if (PLURAL_EXCEPTIONS .containsKey (name )) {
211+ return PLURAL_EXCEPTIONS .get (name );
275212 }
276213
277- // Suffix-based rules
278- if (lower .endsWith ("ies" ) && name .length () > 3 ) {
214+ if (name .endsWith ("ies" )) {
279215 return name .substring (0 , name .length () - 3 ) + "y" ;
280- }
281- if (lower .endsWith ("aves" ) || lower .endsWith ("lves" ) || lower .endsWith ("rves" )) {
282- return name .substring (0 , name .length () - 3 ) + "f" ;
283- }
284- if (lower .endsWith ("ves" ) && !lower .endsWith ("fves" )) {
285- return name .substring (0 , name .length () - 3 ) + "fe" ;
286- }
287- if (lower .endsWith ("zzes" )) {
288- return name .substring (0 , name .length () - 2 );
289- }
290- if (lower .endsWith ("sses" )) {
291- return name .substring (0 , name .length () - 2 );
292- }
293- if (lower .endsWith ("ses" )) {
294- return name .substring (0 , name .length () - 2 );
295- }
296- if (lower .endsWith ("ches" ) || lower .endsWith ("shes" )) {
216+ } else if (name .endsWith ("es" ) && name .endsWith ("ches" )) {
297217 return name .substring (0 , name .length () - 2 );
298- }
299- if (lower .endsWith ("xes" )) {
218+ } else if (name .endsWith ("xes" )) {
300219 return name .substring (0 , name .length () - 2 );
301- }
302- if (lower .endsWith ("oes" )) {
303- return name .substring (0 , name .length () - 1 );
304- }
305- if (lower .endsWith ("s" ) && name .length () > 1 ) {
220+ } else if (name .endsWith ("s" ) && (name .length () != 1 )) {
306221 return name .substring (0 , name .length () - 1 );
307222 }
308223
309224 return name ;
310225 }
311226
312- private static String [] splitByUpperCase (String name ) {
313- for (int i = name .length () - 1 ; i >= 0 ; i --) {
314- if (Character .isUpperCase (name .charAt (i ))) {
315- return new String [] {name .substring (0 , i ), name .substring (i ).toLowerCase ()};
316- }
317- }
318- return null ;
319- }
320-
321227 public static String uncapitalise (String str ) {
322228 if (StringUtils .isEmpty (str )) {
323229 return str ;
0 commit comments