commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r1082046 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/ test/java/org/apache/commons/lang3/
Date Wed, 16 Mar 2011 04:39:17 GMT
Author: bayard
Date: Wed Mar 16 04:39:17 2011
New Revision: 1082046

URL: http://svn.apache.org/viewvc?rev=1082046&view=rev
Log:
Removing CharSequenceUtils in favour of putting the code in StringUtils

Removed:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java
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/StringUtilsSubstringTest.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=1082046&r1=1082045&r2=1082046&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 Wed
Mar 16 04:39:17 2011
@@ -5021,7 +5021,7 @@ public class StringUtils {
         }
         return new StringBuilder(strLen)
             .append(Character.toTitleCase(cs.charAt(0)))
-            .append(CharSequenceUtils.subSequence(cs, 1))
+            .append(StringUtils.subSequence(cs, 1))
             .toString();
     }
 
@@ -5056,7 +5056,7 @@ public class StringUtils {
         }
         return new StringBuilder(strLen)
             .append(Character.toLowerCase(cs.charAt(0)))
-            .append(CharSequenceUtils.subSequence(cs, 1))
+            .append(StringUtils.subSequence(cs, 1))
             .toString();
     }
 
@@ -6384,4 +6384,24 @@ public class StringUtils {
         }
         return false;
     }
+
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Returns a new {@code CharSequence} that is a subsequence of this
+     * sequence starting with the {@code char} value at the specified index.</p>
+     * 
+     * <p>This provides the {@code CharSequence} equivalent to {@link String#substring(int)}.
+     * The length (in {@code char}) of the returned sequence is {@code length() - start},
+     * so if {@code start == end} then an empty sequence is returned.</p>
+     *
+     * @param cs  the specified subsequence, null returns null
+     * @param start  the start index, inclusive, valid
+     * @return a new subsequence, may be null
+     * @throws IndexOutOfBoundsException if {@code start} is negative or if 
+     *  {@code start} is greater than {@code length()}
+     */
+    public static CharSequence subSequence(CharSequence cs, int start) {
+        return cs == null ? null : cs.subSequence(start, cs.length());
+    }
+
 }

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java?rev=1082046&r1=1082045&r2=1082046&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java
Wed Mar 16 04:39:17 2011
@@ -17,6 +17,7 @@
 package org.apache.commons.lang3;
 
 import junit.framework.TestCase;
+import org.junit.Assert;
 
 /**
  * Unit tests {@link org.apache.commons.lang3.StringUtils} - Substring methods
@@ -312,4 +313,38 @@ public class StringUtilsSubstringTest ex
         assertEquals(4, 
              StringUtils.countMatches("oooooooooooo", "ooo"));
     }
+
+    //-----------------------------------------------------------------------
+    public void testSubSequence() {
+        //
+        // null input
+        //
+        Assert.assertEquals(null, StringUtils.subSequence(null, -1));
+        Assert.assertEquals(null, StringUtils.subSequence(null, 0));
+        Assert.assertEquals(null, StringUtils.subSequence(null, 1));
+        //
+        // non-null input
+        //
+        Assert.assertEquals(StringUtils.EMPTY, StringUtils.subSequence(StringUtils.EMPTY,
0));
+        Assert.assertEquals("012", StringUtils.subSequence("012", 0));
+        Assert.assertEquals("12", StringUtils.subSequence("012", 1));
+        Assert.assertEquals("2", StringUtils.subSequence("012", 2));
+        Assert.assertEquals(StringUtils.EMPTY, StringUtils.subSequence("012", 3));
+        //
+        // Exception expected
+        //
+        try {
+            Assert.assertEquals(null, StringUtils.subSequence(StringUtils.EMPTY, -1));
+            Assert.fail("Expected " + IndexOutOfBoundsException.class.getName());
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+        try {
+            Assert.assertEquals(null, StringUtils.subSequence(StringUtils.EMPTY, 1));
+            Assert.fail("Expected " + IndexOutOfBoundsException.class.getName());
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+    }
+
 }



Mime
View raw message