commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [lang] More Javadoc and tests
Date Fri, 11 Dec 2015 23:10:38 GMT
Repository: commons-lang
Updated Branches:
  refs/heads/master a5ad80d75 -> bfcdeeaf4


More Javadoc and tests

Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/bfcdeeaf
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/bfcdeeaf
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/bfcdeeaf

Branch: refs/heads/master
Commit: bfcdeeaf441feffba724f03602cec2cf7b181a86
Parents: a5ad80d
Author: Sebb <sebb@apache.org>
Authored: Fri Dec 11 23:10:32 2015 +0000
Committer: Sebb <sebb@apache.org>
Committed: Fri Dec 11 23:10:32 2015 +0000

----------------------------------------------------------------------
 .../java/org/apache/commons/lang3/StringUtils.java    | 14 ++++++++++----
 .../commons/lang3/StringUtilsEqualsIndexOfTest.java   |  7 +++++++
 2 files changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bfcdeeaf/src/main/java/org/apache/commons/lang3/StringUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index c7583c9..df53c59 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -1205,7 +1205,8 @@ public class StringUtils {
     /**
      * <p>Finds the n-th index within a CharSequence, handling {@code null}.
      * This method uses {@link String#indexOf(String)} if possible.</p>
-     *
+     * <p><b>Note:</b> The code starts looking for a match at the start
of the target,
+     * incrementing the starting index by one after each successful match.</p>
      * <p>A {@code null} CharSequence will return {@code -1}.</p>
      *
      * <pre>
@@ -1224,9 +1225,14 @@ public class StringUtils {
      *
      * <p>Matches may overlap:</p>
      * <pre>
-     * StringUtils.ordinalIndexOf("ababab","aba", 1)          = 0
-     * StringUtils.ordinalIndexOf("ababab","aba", 2)          = 2
-     * StringUtils.ordinalIndexOf("ababab","aba", 3)          = -1
+     * StringUtils.ordinalIndexOf("ababab","aba", 1)   = 0
+     * StringUtils.ordinalIndexOf("ababab","aba", 2)   = 2
+     * StringUtils.ordinalIndexOf("ababab","aba", 3    = -1
+     *
+     * StringUtils.ordinalIndexOf("abababab", "abab", 1) = 0
+     * StringUtils.ordinalIndexOf("abababab", "abab", 2) = 2
+     * StringUtils.ordinalIndexOf("abababab", "abab", 3) = 4
+     * StringUtils.ordinalIndexOf("abababab", "abab", 4) = -1
      * </pre>
      *
      * <p>Note that 'head(CharSequence str, int n)' may be implemented as: </p>

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bfcdeeaf/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
index f509290..4f9d743 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
@@ -1148,6 +1148,7 @@ public class StringUtilsEqualsIndexOfTest  {
         assertEquals(8, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 9));
         assertEquals(-1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 10));
 
+        // match at each possible position
         assertEquals(0, StringUtils.ordinalIndexOf("aaaaaa", "aa", 1));
         assertEquals(1, StringUtils.ordinalIndexOf("aaaaaa", "aa", 2));
         assertEquals(2, StringUtils.ordinalIndexOf("aaaaaa", "aa", 3));
@@ -1158,6 +1159,12 @@ public class StringUtilsEqualsIndexOfTest  {
         assertEquals(0, StringUtils.ordinalIndexOf("ababab", "aba", 1));
         assertEquals(2, StringUtils.ordinalIndexOf("ababab", "aba", 2));
         assertEquals(-1, StringUtils.ordinalIndexOf("ababab", "aba", 3));
+
+        assertEquals(0, StringUtils.ordinalIndexOf("abababab", "abab", 1));
+        assertEquals(2, StringUtils.ordinalIndexOf("abababab", "abab", 2));
+        assertEquals(4, StringUtils.ordinalIndexOf("abababab", "abab", 3));
+        assertEquals(-1, StringUtils.ordinalIndexOf("abababab", "abab", 4));
+
     }
     
     @Test


Mime
View raw message