Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update pluralizing method

  • Loading branch information...
commit 6f3c1e73d4eaedb43dded7dd850e72a7fb38e726 1 parent 9ecb3e8
@dgeraskov dgeraskov authored koentsje committed
View
13 src/java/org/hibernate/cfg/reveng/ReverseEngineeringStrategyUtil.java
@@ -128,14 +128,25 @@ public static String toUpperCamelCase(String s) {
static public String simplePluralize(String singular) {
char last = singular.charAt( singular.length()-1 );
+ Character prev = singular.length() > 1 ? singular.charAt( singular.length() - 2 ) : null;
+ String vowels = "aeiouy";
switch (last) {
case 'x':
case 's':
singular += "es";
break;
case 'y':
- singular = singular.substring( 0, singular.length()-1 ) + "ies";
+ if (prev != null && vowels.indexOf(prev) >= 0){
+ singular += "s";
+ } else {
+ singular = singular.substring( 0, singular.length()-1 ) + "ies";
+ }
break;
+ case 'h':
+ if (prev == 'c' || prev == 's'){
+ singular += "es";
+ break;
+ }
default:
singular += "s";
}
View
1  src/test/org/hibernate/tool/hbm2x/Hbm2XAllTests.java
@@ -12,6 +12,7 @@
public static Test suite() {
TestSuite suite = new TestSuite("Test for org.hibernate.tool.hbm2x");
//$JUnit-BEGIN$
+ suite.addTestSuite(PluralizeTest.class);
suite.addTestSuite(PropertiesTest.class);
suite.addTestSuite(Hbm2CfgTest.class);
suite.addTestSuite(Hbm2DaoTest.class);
View
26 src/test/org/hibernate/tool/hbm2x/PluralizeTest.java
@@ -0,0 +1,26 @@
+/*
+ * Created on 29.12.2011
+ */
+package org.hibernate.tool.hbm2x;
+
+import org.hibernate.cfg.reveng.ReverseEngineeringStrategyUtil;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Dmitry Geraskov (geraskov@gmail.com)
+ *
+ */
+public class PluralizeTest extends TestCase {
+
+ public void testPluralizeTest(){
+ assertEquals("boxes", ReverseEngineeringStrategyUtil.simplePluralize("box"));
+ assertEquals("buses", ReverseEngineeringStrategyUtil.simplePluralize("bus"));
+ assertEquals("keys", ReverseEngineeringStrategyUtil.simplePluralize("key"));
+ assertEquals("countries", ReverseEngineeringStrategyUtil.simplePluralize("country"));
+ assertEquals("churches", ReverseEngineeringStrategyUtil.simplePluralize("church"));
+ assertEquals("bushes", ReverseEngineeringStrategyUtil.simplePluralize("bush"));
+ assertEquals("roofs", ReverseEngineeringStrategyUtil.simplePluralize("roof"));
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.