Repository: cayenne
Updated Branches:
  refs/heads/master 1460aae0f -> 832401b32


remove repetitive code


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/f3856f3c
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/f3856f3c
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/f3856f3c

Branch: refs/heads/master
Commit: f3856f3cc6d5de754a9797e1c5f5d510b04647cf
Parents: 1460aae
Author: sarvaratchagan <sarvaratcha...@outlook.com>
Authored: Sun Dec 18 00:58:00 2016 +0530
Committer: sarvaratchagan <sarvaratcha...@outlook.com>
Committed: Sun Dec 18 00:58:00 2016 +0530

----------------------------------------------------------------------
 .../apache/cayenne/dbsync/naming/NameUtil.java  | 27 ++++++--------------
 1 file changed, 8 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/f3856f3c/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/NameUtil.java
----------------------------------------------------------------------
diff --git 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/NameUtil.java 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/NameUtil.java
index fb47bcb..47e6fd2 100644
--- 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/NameUtil.java
+++ 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/NameUtil.java
@@ -22,14 +22,15 @@ package org.apache.cayenne.dbsync.naming;
  * @since 4.0
  */
 final class NameUtil {
-    static String uncapitalize(String string) {
+
+    private static String prepare(String string, boolean capitalize){
         int len;
         if (string == null || (len = string.length()) == 0) {
             return string;
         }
 
         final char firstChar = string.charAt(0);
-        final char newChar = Character.toLowerCase(firstChar);
+        final char newChar = capitalize ? Character.toTitleCase(firstChar) : 
Character.toLowerCase(firstChar);
         if (firstChar == newChar) {
             // already capitalized
             return string;
@@ -42,24 +43,12 @@ final class NameUtil {
         return String.valueOf(newChars);
     }
 
-    static String capitalize(String string) {
-        int len;
-        if (string == null || (len = string.length()) == 0) {
-            return string;
-        }
-
-        final char firstChar = string.charAt(0);
-        final char newChar = Character.toTitleCase(firstChar);
-        if (firstChar == newChar) {
-            // already capitalized
-            return string;
-        }
-
-        char[] newChars = new char[len];
-        newChars[0] = newChar;
-        string.getChars(1, len, newChars, 1);
+    static String uncapitalize(String string) {
+        return prepare(string,false);
+    }
 
-        return String.valueOf(newChars);
+    static String capitalize(String string) {
+        return prepare(string,true);
     }
 
 }

Reply via email to