You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2011/11/23 08:13:09 UTC

svn commit: r1205308 - in /cayenne/main/trunk: docs/doc/src/main/resources/RELEASE-NOTES.txt framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/StringUtils.java

Author: aadamchik
Date: Wed Nov 23 07:13:09 2011
New Revision: 1205308

URL: http://svn.apache.org/viewvc?rev=1205308&view=rev
Log:
CAY-1607 [PATCH] add pluralize method to StringUtils for use in templates

patch by John Huss
changed static method to instance

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/StringUtils.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=1205308&r1=1205307&r2=1205308&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Wed Nov 23 07:13:09 2011
@@ -14,6 +14,7 @@ Date:
 Changes/New Features Since 3.1M3:
 
 CAY-1603 Improve custom ExtendedType registration API
+CAY-1607 [PATCH] add pluralize method to StringUtils for use in templates
 CAY-1608 Implement constructor injection support for DefaultAdhocObjectFactory
 CAY-1618 Create database adapters instances with proper injection
 CAY-1629 [PATCH] Can't add custom Hessian serializers to the client

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/StringUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/StringUtils.java?rev=1205308&r1=1205307&r2=1205308&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/StringUtils.java (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/StringUtils.java Wed Nov 23 07:13:09 2011
@@ -25,7 +25,6 @@ import org.apache.cayenne.util.Util;
 
 /**
  * Methods for mangling strings.
- * 
  */
 public class StringUtils {
 
@@ -115,4 +114,33 @@ public class StringUtils {
 
         return NameConverter.javaToUnderscored(name);
     }
+
+    /**
+     * Converts entity or property name to a plural form. For example:
+     * <ul>
+     * <li>pluralize("Word") == "Words"</li>
+     * <li>pluralize("Status") == "Statuses"</li>
+     * <li>pluralize("Index") == "Indexes"</li>
+     * <li>pluralize("Factory") == "Factories"</li>
+     * </ul>
+     * <p>
+     * As of 3.1 this method is not used in bundled templates, and is present here for
+     * user templates convenience.
+     * 
+     * @since 3.1
+     */
+    public String pluralize(String str) {
+        if (str == null || str.isEmpty()) {
+            return str;
+        }
+        else if (str.endsWith("s") || str.endsWith("x")) {
+            return str + "es";
+        }
+        else if (str.endsWith("y")) {
+            return str.substring(0, str.length() - 1) + "ies";
+        }
+        else {
+            return str + "s";
+        }
+    }
 }