You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2020/09/12 22:23:29 UTC
[commons-lang] branch master updated: LANG-1606
StringUtils.countMatches - fix Javadoc
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 38a9209 LANG-1606 StringUtils.countMatches - fix Javadoc
38a9209 is described below
commit 38a9209456be83a4ec65e7c69993ddb8748145be
Author: Sebb <se...@apache.org>
AuthorDate: Sat Sep 12 23:23:18 2020 +0100
LANG-1606 StringUtils.countMatches - fix Javadoc
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/lang3/StringUtils.java | 4 +++-
.../java/org/apache/commons/lang3/StringUtilsSubstringTest.java | 8 ++++++++
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f876ca4..25d0ee0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -51,6 +51,7 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="LANG-1600" type="fix" dev="ggregory" due-to="Michael F">Restore handling of collections for non-JSON ToStringStyle #610.</action>
<action type="fix" dev="ggregory" due-to="iamchao1129">ContextedException Javadoc add missing semicolon #581.</action>
<!-- UPDATES -->
+ <action issue="LANG-1606" type="update" dev="sebb" due-to="Rustem Galiev">StringUtils.countMatches - clarify Javadoc.</action>
<action issue="LANG-1591" type="update" dev="kinow" due-to="bhawna94">Remove redundant argument from substring call.</action>
<action issue="LANG-1579" type="update" dev="aherbert" due-to="XenoAmess">Improve StringUtils.stripAccents conversion of remaining accents.</action>
<action issue="LANG-1596" type="update" dev="aherbert" due-to="Richard Eckart de Castilho">ArrayUtils.toPrimitive(Object) does not support boolean and other types #607.</action>
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index a93d34a..0949398 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -1425,7 +1425,8 @@ public class StringUtils {
// Count matches
//-----------------------------------------------------------------------
/**
- * <p>Counts how many times the substring appears in the larger string.</p>
+ * <p>Counts how many times the substring appears in the larger string.
+ * Note that the code only counts non-overlapping matches.</p>
*
* <p>A {@code null} or empty ("") String input returns {@code 0}.</p>
*
@@ -1437,6 +1438,7 @@ public class StringUtils {
* StringUtils.countMatches("abba", "a") = 2
* StringUtils.countMatches("abba", "ab") = 1
* StringUtils.countMatches("abba", "xxx") = 0
+ * StringUtils.countMatches("ababa", "aba") = 1
* </pre>
*
* @param str the CharSequence to check, may be null
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java
index 9a1c014..d876d7c 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java
@@ -349,6 +349,14 @@ public class StringUtilsSubstringTest {
StringUtils.countMatches("one long someone sentence of one", "two"));
assertEquals(4,
StringUtils.countMatches("oooooooooooo", "ooo"));
+ assertEquals(0, StringUtils.countMatches(null, "?"));
+ assertEquals(0, StringUtils.countMatches("", "?"));
+ assertEquals(0, StringUtils.countMatches("abba", null));
+ assertEquals(0, StringUtils.countMatches("abba", ""));
+ assertEquals(2, StringUtils.countMatches("abba", "a"));
+ assertEquals(1, StringUtils.countMatches("abba", "ab"));
+ assertEquals(0, StringUtils.countMatches("abba", "xxx"));
+ assertEquals(1, StringUtils.countMatches("ababa", "aba"));
}
@Test