hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r934619 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/util/StringUtils.java src/test/core/org/apache/hadoop/util/TestStringUtils.java
Date Thu, 15 Apr 2010 22:06:52 GMT
Author: stevel
Date: Thu Apr 15 22:06:52 2010
New Revision: 934619

URL: http://svn.apache.org/viewvc?rev=934619&view=rev
Log:
HADOOP-6657. Add a capitalization method to StringUtils for MAPREDUCE-1545

Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/util/StringUtils.java
    hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestStringUtils.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=934619&r1=934618&r2=934619&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Thu Apr 15 22:06:52 2010
@@ -69,6 +69,9 @@ Trunk (unreleased changes)
     for RPC (boryas)
 
     HADOOP-6580. UGI should contain authentication method. (jnp via boryas)
+    
+    HADOOP-6657. Add a capitalization method to StringUtils for MAPREDUCE-1545.
+    (Luke Lu via Steve Loughran)
 
   IMPROVEMENTS
 

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/util/StringUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/util/StringUtils.java?rev=934619&r1=934618&r2=934619&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/util/StringUtils.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/util/StringUtils.java Thu Apr 15 22:06:52
2010
@@ -720,4 +720,20 @@ public class StringUtils {
     }
     return sb.toString();
   }
+
+  /**
+   * Convert SOME_STUFF to SomeStuff
+   *
+   * @param s input string
+   * @return camelized string
+   */
+  public static String camelize(String s) {
+    StringBuilder sb = new StringBuilder();
+    String[] words = split(s.toLowerCase(Locale.US), ESCAPE_CHAR, '_');
+
+    for (String word : words)
+      sb.append(org.apache.commons.lang.StringUtils.capitalize(word));
+
+    return sb.toString();
+  }
 }

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestStringUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestStringUtils.java?rev=934619&r1=934618&r2=934619&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestStringUtils.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestStringUtils.java Thu Apr
15 22:06:52 2010
@@ -153,4 +153,39 @@ public class TestStringUtils extends Tes
     assertArrayEquals(emptyArray, StringUtils.getTrimmedStrings(emptyList1));
     assertArrayEquals(emptyArray, StringUtils.getTrimmedStrings(emptyList2));
   } 
+
+  public void testCamelize() {
+    // common use cases
+    assertEquals("Map", StringUtils.camelize("MAP"));
+    assertEquals("JobSetup", StringUtils.camelize("JOB_SETUP"));
+    assertEquals("SomeStuff", StringUtils.camelize("some_stuff"));
+
+    // sanity checks for ascii alphabet against unexpected locale issues.
+    assertEquals("Aa", StringUtils.camelize("aA"));
+    assertEquals("Bb", StringUtils.camelize("bB"));
+    assertEquals("Cc", StringUtils.camelize("cC"));
+    assertEquals("Dd", StringUtils.camelize("dD"));
+    assertEquals("Ee", StringUtils.camelize("eE"));
+    assertEquals("Ff", StringUtils.camelize("fF"));
+    assertEquals("Gg", StringUtils.camelize("gG"));
+    assertEquals("Hh", StringUtils.camelize("hH"));
+    assertEquals("Ii", StringUtils.camelize("iI"));
+    assertEquals("Jj", StringUtils.camelize("jJ"));
+    assertEquals("Kk", StringUtils.camelize("kK"));
+    assertEquals("Ll", StringUtils.camelize("lL"));
+    assertEquals("Mm", StringUtils.camelize("mM"));
+    assertEquals("Nn", StringUtils.camelize("nN"));
+    assertEquals("Oo", StringUtils.camelize("oO"));
+    assertEquals("Pp", StringUtils.camelize("pP"));
+    assertEquals("Qq", StringUtils.camelize("qQ"));
+    assertEquals("Rr", StringUtils.camelize("rR"));
+    assertEquals("Ss", StringUtils.camelize("sS"));
+    assertEquals("Tt", StringUtils.camelize("tT"));
+    assertEquals("Uu", StringUtils.camelize("uU"));
+    assertEquals("Vv", StringUtils.camelize("vV"));
+    assertEquals("Ww", StringUtils.camelize("wW"));
+    assertEquals("Xx", StringUtils.camelize("xX"));
+    assertEquals("Yy", StringUtils.camelize("yY"));
+    assertEquals("Zz", StringUtils.camelize("zZ"));
+  }
 }



Mime
View raw message