Author: bayard
Date: Wed Mar 16 06:18:42 2011
New Revision: 1082066

URL: http://svn.apache.org/viewvc?rev=1082066&view=rev
Log:
Moving indexOf(String, String) and indexOf(String, String, int) over to 
CharSequence. LANG-687

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/StringUtilsEqualsIndexOfTest.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=1082066&r1=1082065&r2=1082066&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 06:18:42 2011
@@ -858,10 +858,10 @@ public class StringUtils {
     }
 
     /**
-     * <p>Finds the first index within a String, handling {@code null}.
-     * This method uses {@link String#indexOf(String)}.</p>
+     * <p>Finds the first index within a CharSequence, handling {@code null}.
+     * This method uses {@link String#indexOf(String, int)} if possible.</p>
      *
-     * <p>A {@code null} String will return {@code -1}.</p>
+     * <p>A {@code null} CharSequence will return {@code -1}.</p>
      *
      * <pre>
      * StringUtils.indexOf(null, *)          = -1
@@ -874,28 +874,28 @@ public class StringUtils {
      * StringUtils.indexOf("aabaabaa", "")   = 0
      * </pre>
      *
-     * @param str  the String to check, may be null
-     * @param searchStr  the String to find, may be null
-     * @return the first index of the search String,
+     * @param seq  the CharSequence to check, may be null
+     * @param searchSeq  the CharSequence to find, may be null
+     * @return the first index of the search CharSequence,
      *  -1 if no match or {@code null} string input
      * @since 2.0
      */
-    public static int indexOf(String str, String searchStr) {
-        if (str == null || searchStr == null) {
+    public static int indexOf(CharSequence seq, CharSequence searchSeq) {
+        if (seq == null || searchSeq == null) {
             return INDEX_NOT_FOUND;
         }
-        return str.indexOf(searchStr);
+        return StringUtils.indexOfSequence(seq, searchSeq, 0);
     }
 
     /**
-     * <p>Finds the first index within a String, handling {@code null}.
-     * This method uses {@link String#indexOf(String, int)}.</p>
+     * <p>Finds the first index within a CharSequence, handling {@code null}.
+     * This method uses {@link String#indexOf(String, int)} if possible.</p>
      *
-     * <p>A {@code null} String will return {@code -1}.
+     * <p>A {@code null} CharSequence will return {@code -1}.
      * A negative start position is treated as zero.
-     * An empty ("") search String always matches.
+     * An empty ("") search CharSequence always matches.
      * A start position greater than the string length only matches
-     * an empty search String.</p>
+     * an empty search CharSequence.</p>
      *
      * <pre>
      * StringUtils.indexOf(null, *, *)          = -1
@@ -912,18 +912,18 @@ public class StringUtils {
      * StringUtils.indexOf("abc", "", 9)        = 3
      * </pre>
      *
-     * @param str  the String to check, may be null
-     * @param searchStr  the String to find, may be null
+     * @param seq  the CharSequence to check, may be null
+     * @param searchSeq  the CharSequence to find, may be null
      * @param startPos  the start position, negative treated as zero
-     * @return the first index of the search String,
+     * @return the first index of the search CharSequence,
      *  -1 if no match or {@code null} string input
      * @since 2.0
      */
-    public static int indexOf(String str, String searchStr, int startPos) {
-        if (str == null || searchStr == null) {
+    public static int indexOf(CharSequence seq, CharSequence searchSeq, int 
startPos) {
+        if (seq == null || searchSeq == null) {
             return INDEX_NOT_FOUND;
         }
-        return str.indexOf(searchStr, startPos);
+        return StringUtils.indexOfSequence(seq, searchSeq, startPos);
     }
 
     /**

Modified: 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java?rev=1082066&r1=1082065&r2=1082066&view=diff
==============================================================================
--- 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
 (original)
+++ 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
 Wed Mar 16 06:18:42 2011
@@ -493,6 +493,8 @@ public class StringUtilsEqualsIndexOfTes
         assertEquals(2, StringUtils.indexOf("aabaabaa", "b"));
         assertEquals(1, StringUtils.indexOf("aabaabaa", "ab"));
         assertEquals(0, StringUtils.indexOf("aabaabaa", ""));
+
+        assertEquals(2, StringUtils.indexOf(new StringBuilder("aabaabaa"), 
"b"));
     }
 
     public void testIndexOf_StringInt() {
@@ -516,6 +518,8 @@ public class StringUtilsEqualsIndexOfTes
         assertEquals(-1, StringUtils.indexOf("aabaabaa", "b", 9));
         assertEquals(2, StringUtils.indexOf("aabaabaa", "b", -1));
         assertEquals(2,StringUtils.indexOf("aabaabaa", "", 2));
+
+        assertEquals(5, StringUtils.indexOf(new StringBuilder("aabaabaa"), 
"b", 3));
     }
 
     public void testIndexOfAny_StringCharArray() {


Reply via email to