commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r920187 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/StringUtils.java test/java/org/apache/commons/lang3/StringUtilsTest.java
Date Mon, 08 Mar 2010 03:41:50 GMT
Author: ggregory
Date: Mon Mar  8 03:41:49 2010
New Revision: 920187

URL: http://svn.apache.org/viewvc?rev=920187&view=rev
Log:
Convert defaultIfEmpty from String to CharSequence.

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java?rev=920187&r1=920186&r2=920187&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java Mon
Mar  8 03:41:49 2010
@@ -5353,7 +5353,7 @@
     }
 
     /**
-     * <p>Returns either the passed in String, or if the String is
+     * <p>Returns either the passed in CharSequence, or if the CharSequence is
      * empty or <code>null</code>, the value of <code>defaultStr</code>.</p>
      *
      * <pre>
@@ -5364,12 +5364,12 @@
      * </pre>
      *
      * @see StringUtils#defaultString(String, String)
-     * @param str  the String to check, may be null
-     * @param defaultStr  the default String to return
+     * @param str  the CharSequence to check, may be null
+     * @param defaultStr  the default CharSequence to return
      *  if the input is empty ("") or <code>null</code>, may be null
-     * @return the passed in String, or the default
+     * @return the passed in CharSequence, or the default
      */
-    public static String defaultIfEmpty(String str, String defaultStr) {
+    public static CharSequence defaultIfEmpty(CharSequence str, CharSequence defaultStr)
{
         return StringUtils.isEmpty(str) ? defaultStr : str;
     }
 

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java?rev=920187&r1=920186&r2=920187&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
Mon Mar  8 03:41:49 2010
@@ -18,6 +18,7 @@
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
+import java.nio.CharBuffer;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
@@ -1404,6 +1405,24 @@
         assertNull(StringUtils.defaultIfEmpty("", null));
     }
 
+    public void testDefaultIfEmpty_StringBuilders() {
+        assertEquals("NULL", StringUtils.defaultIfEmpty(new StringBuilder(""), new StringBuilder("NULL")).toString());
+        assertEquals("abc", StringUtils.defaultIfEmpty(new StringBuilder("abc"), new StringBuilder("NULL")).toString());
+        assertNull(StringUtils.defaultIfEmpty(new StringBuilder(""), null));
+    }
+
+    public void testDefaultIfEmpty_StringBuffers() {
+        assertEquals("NULL", StringUtils.defaultIfEmpty(new StringBuffer(""), new StringBuffer("NULL")).toString());
+        assertEquals("abc", StringUtils.defaultIfEmpty(new StringBuffer("abc"), new StringBuffer("NULL")).toString());
+        assertNull(StringUtils.defaultIfEmpty(new StringBuffer(""), null));
+    }
+
+    public void testDefaultIfEmpty_CharBuffers() {
+        assertEquals("NULL", StringUtils.defaultIfEmpty(CharBuffer.wrap(""), CharBuffer.wrap("NULL")).toString());
+        assertEquals("abc", StringUtils.defaultIfEmpty(CharBuffer.wrap("abc"), CharBuffer.wrap("NULL")).toString());
+        assertNull(StringUtils.defaultIfEmpty(CharBuffer.wrap(""), null));
+    }
+
     //-----------------------------------------------------------------------
     public void testAbbreviate_StringInt() {
         assertEquals(null, StringUtils.abbreviate(null, 10));



Mime
View raw message