hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdoug...@apache.org
Subject svn commit: r752534 - in /hadoop/core/trunk: CHANGES.txt src/core/org/apache/hadoop/util/StringUtils.java src/test/org/apache/hadoop/util/TestStringUtils.java
Date Wed, 11 Mar 2009 17:22:33 GMT
Author: cdouglas
Date: Wed Mar 11 17:22:32 2009
New Revision: 752534

URL: http://svn.apache.org/viewvc?rev=752534&view=rev
Log:
Revert HADOOP-5307

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

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=752534&r1=752533&r2=752534&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Wed Mar 11 17:22:32 2009
@@ -993,9 +993,6 @@
     HADOOP-5392. Fixes a problem to do with JT crashing during recovery when
     the job files are garbled. (Amar Kamat vi ddas)
 
-    HADOOP-5307. Fix null value handling in StringUtils#arrayToString() and 
-    #getStrings(). (enis)
-
     HADOOP-5332. Appending to files is not allowed (by default) unless
     dfs.support.append is set to true. (dhruba)
  

Modified: hadoop/core/trunk/src/core/org/apache/hadoop/util/StringUtils.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/core/org/apache/hadoop/util/StringUtils.java?rev=752534&r1=752533&r2=752534&view=diff
==============================================================================
--- hadoop/core/trunk/src/core/org/apache/hadoop/util/StringUtils.java (original)
+++ hadoop/core/trunk/src/core/org/apache/hadoop/util/StringUtils.java Wed Mar 11 17:22:32
2009
@@ -118,24 +118,20 @@
     return percentFormat.format(rounded / scale);
   }
   
-  private static final String NULL_STR_VALUE = "__null__";
-  
   /**
    * Given an array of strings, return a comma-separated list of its elements.
    * @param strs Array of strings
    * @return Empty string if strs.length is 0, comma separated list of strings
    * otherwise
    */
+  
   public static String arrayToString(String[] strs) {
     if (strs.length == 0) { return ""; }
     StringBuffer sbuf = new StringBuffer();
-    for (int idx = 0; idx < strs.length; idx++) {
-      if(idx != 0)
-        sbuf.append(",");
-      if(strs[idx] == null)
-        sbuf.append(NULL_STR_VALUE);
-      else
-        sbuf.append(strs[idx]);
+    sbuf.append(strs[0]);
+    for (int idx = 1; idx < strs.length; idx++) {
+      sbuf.append(",");
+      sbuf.append(strs[idx]);
     }
     return sbuf.toString();
   }
@@ -317,11 +313,7 @@
     StringTokenizer tokenizer = new StringTokenizer (str,",");
     values = new ArrayList<String>();
     while (tokenizer.hasMoreTokens()) {
-      String value = tokenizer.nextToken();
-      if(value.equals(NULL_STR_VALUE))
-        values.add(null);
-      else
-        values.add(value);
+      values.add(tokenizer.nextToken());
     }
     return values;
   }
@@ -549,7 +541,6 @@
       );
 
     Runtime.getRuntime().addShutdownHook(new Thread() {
-      @Override
       public void run() {
         LOG.info(toStartupShutdownString("SHUTDOWN_MSG: ", new String[]{
           "Shutting down " + classname + " at " + hostname}));

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/util/TestStringUtils.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/util/TestStringUtils.java?rev=752534&r1=752533&r2=752534&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/util/TestStringUtils.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/util/TestStringUtils.java Wed Mar 11 17:22:32
2009
@@ -118,89 +118,4 @@
     assertEquals(-1259520L, StringUtils.TraditionalBinaryPrefix.string2long("-1230k"));
     assertEquals(956703965184L, StringUtils.TraditionalBinaryPrefix.string2long("891g"));
   }
-  
-  private <T> void assertEquals(T[] expected, T[] actual) {
-    assertEquals(expected.length, actual.length);
-    for (int i = 0; i < expected.length; i++) {
-      assertEquals(expected[i], actual[i]);
-    }
-  }
-  
-  //internal to StringUtils
-  private static final String NULL_STR_VALUE = "__null__";
-  
-  public void testArrayToString() {
-    
-    //normal test
-    String[] arr1 = new String[] {"1", "2", "3", "4", "5", "6" }; 
-    String expected1 = "1,2,3,4,5,6";
-    assertEquals(expected1, StringUtils.arrayToString(arr1));
-    
-    //test with whitespace
-    String[] arr2 = new String[] {"1 ", "2 ", "3 ", "4 ", "5 ", "6 " }; 
-    String expected2 = "1 ,2 ,3 ,4 ,5 ,6 ";
-    assertEquals(expected2, StringUtils.arrayToString(arr2));
-    
-    //test with empty array
-    String[] emptyArr = new String[0];
-    assertEquals("", StringUtils.arrayToString(emptyArr));
-    
-    //test with null
-    try {
-      StringUtils.arrayToString(null);
-      fail("Should have thrown NPE");
-    }catch(NullPointerException ex) {
-    }
-    
-    //test with one element 
-    assertEquals("1", StringUtils.arrayToString(new String[] {"1"}));
-    assertEquals("", StringUtils.arrayToString(new String[] {""}));
-    assertEquals(" ", StringUtils.arrayToString(new String[] {" "}));
-    
-    
-    assertEquals(" ,1", StringUtils.arrayToString(new String[] {" ", "1"}));
-    
-    //test with null values
-    assertEquals(NULL_STR_VALUE, StringUtils.arrayToString(new String[] {null}));
-    assertEquals(NULL_STR_VALUE+",1", StringUtils.arrayToString(new String[] {null,"1"}));
-    assertEquals("1," + NULL_STR_VALUE, StringUtils.arrayToString(new String[] {"1",null}));
-    
-  }
-  
-  public void testArrayToStringToArray() {
-    
-    //normal test
-    String[] arr1 = new String[] {"1", "2", "3", "4", "5", "6" };
-    assertEquals(arr1, StringUtils.getStrings(StringUtils.arrayToString(arr1)));
-    
-    //test with whitespace
-    String[] arr2 = new String[] {"1 ", "2 ", "3 ", "4 ", "5 ", "6 " }; 
-    assertEquals(arr2, StringUtils.getStrings(StringUtils.arrayToString(arr2)));
-    
-    //test with empty array
-    String[] emptyArr = new String[0];
-    //actually returns null for empty array
-    assertNull(StringUtils.getStrings(StringUtils.arrayToString(emptyArr)));
-    
-    //test with one element 
-    String[] one = new String[] {"1"};
-    String[] empty = new String[] {""};
-    String[] ws = new String[] {" "};
-    assertEquals(one, StringUtils.getStrings(StringUtils.arrayToString(one)));
-    assertNull(StringUtils.getStrings(StringUtils.arrayToString(empty)));
-    assertEquals(ws, StringUtils.getStrings(StringUtils.arrayToString(ws)));
-    
-    String[] wsone = new String[] {" ", "1"};
-    assertEquals(wsone, StringUtils.getStrings(StringUtils.arrayToString(wsone)));
-    
-    //test with null values
-    String[] nullArr = new String[] {null};
-    String[] nullArr2 =  new String[] {null, "1"};
-    String[] nullArr3 =  new String[] {null, "null", null};
-    String[] nullArr4 =  new String[] {null, null, null};
-    assertEquals(nullArr, StringUtils.getStrings(StringUtils.arrayToString(nullArr)));
-    assertEquals(nullArr2, StringUtils.getStrings(StringUtils.arrayToString(nullArr2)));
-    assertEquals(nullArr4, StringUtils.getStrings(StringUtils.arrayToString(nullArr4)));
-  }
-  
 }



Mime
View raw message