You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2015/05/05 20:33:22 UTC
[1/3] [lang] LANG-701 - Added new joinWith method to support varargs
Repository: commons-lang
Updated Branches:
refs/heads/master 98220ad03 -> 7fae5b0b1
LANG-701 - Added new joinWith method to support varargs
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/155cec10
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/155cec10
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/155cec10
Branch: refs/heads/master
Commit: 155cec1085f9bd5383241e4c93fb40117081aaba
Parents: 1cb5573
Author: jamessawle <ja...@hotmail.com>
Authored: Mon May 4 22:19:18 2015 +0100
Committer: jamessawle <ja...@hotmail.com>
Committed: Mon May 4 22:19:18 2015 +0100
----------------------------------------------------------------------
.../org/apache/commons/lang3/StringUtils.java | 41 +++++++++++++++++++-
.../apache/commons/lang3/StringUtilsTest.java | 18 +++++++++
2 files changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/155cec10/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 279c472..5ebadde 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -17,7 +17,6 @@
package org.apache.commons.lang3;
import java.io.UnsupportedEncodingException;
-
import java.nio.charset.Charset;
import java.text.Normalizer;
import java.util.ArrayList;
@@ -4179,6 +4178,46 @@ public class StringUtils {
return join(iterable.iterator(), separator);
}
+ /**
+ * <p>Joins the elements of the provided varargs into a
+ * single String containing the provided elements.</p>
+ *
+ * <p>No delimiter is added before or after the list.
+ * {@code null} elements and separator are treated as empty Strings ("").</p>
+ *
+ * <pre>
+ * StringUtils.joinWith(",", {"a", "b"}) = "a,b"
+ * StringUtils.joinWith(",", {"a", "b",""}) = "a,b,"
+ * StringUtils.joinWith(",", {"a", null, "b"}) = "a,,b"
+ * StringUtils.joinWith(null, {"a", "b"}) = "ab"
+ * </pre>
+ *
+ * @param separator the separator character to use, null treated as ""
+ * @param objects the varargs providing the values to join together. {@code null} elements are treated as ""
+ * @return the joined String.
+ * @throws java.lang.IllegalArgumentException if a null varargs is provided
+ */
+ public static String joinWith(final String separator, Object... objects) {
+ if (objects == null) {
+ throw new IllegalArgumentException("Object varargs must not be null");
+ }
+
+ String sanitizedSeparator = defaultString(separator, StringUtils.EMPTY);
+
+ StringBuilder result = new StringBuilder();
+
+ Iterator<Object> iterator = Arrays.asList(objects).iterator();
+ while (iterator.hasNext()) {
+ result.append(ObjectUtils.toString(iterator.next()));
+
+ if (iterator.hasNext()) {
+ result.append(sanitizedSeparator);
+ }
+ }
+
+ return result.toString();
+ }
+
// Delete
//-----------------------------------------------------------------------
/**
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/155cec10/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
index f11ec70..44200bd 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
@@ -461,6 +461,24 @@ public class StringUtilsTest {
}
@Test
+ public void testJoinWith() {
+ assertEquals("", StringUtils.joinWith(",", new Object[0])); // empty array
+ assertEquals("", StringUtils.joinWith(",", NULL_ARRAY_LIST));
+ assertEquals("null", StringUtils.joinWith(",", NULL_TO_STRING_LIST)); //toString method prints 'null'
+
+ assertEquals("a,b,c", StringUtils.joinWith(",", new String[]{"a", "b", "c"}));
+ assertEquals(",a,", StringUtils.joinWith(",", new String[]{null, "a", ""}));
+
+ assertEquals("ab", StringUtils.joinWith(null, "a", "b"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testJoinWithThrowsException() {
+ StringUtils.joinWith(",", null);
+ }
+
+
+ @Test
public void testSplit_String() {
assertNull(StringUtils.split(null));
assertEquals(0, StringUtils.split("").length);
[2/3] [lang] Add LANG-701 to changes.xml
Posted by br...@apache.org.
Add LANG-701 to changes.xml
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/9752bbc2
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/9752bbc2
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/9752bbc2
Branch: refs/heads/master
Commit: 9752bbc299a880745e02df8f920e076a0fae86bd
Parents: 155cec1
Author: Benedikt Ritter <br...@apache.org>
Authored: Tue May 5 20:31:48 2015 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Tue May 5 20:31:48 2015 +0200
----------------------------------------------------------------------
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/9752bbc2/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f151745..2ecf557 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -22,6 +22,7 @@
<body>
<release version="3.5" date="tba" description="tba">
+ <action issue="LANG-701" type="add" dev="britter" due-to="James Sawle">StringUtils join with var args</action>
<action issue="LANG-1105" type="add" dev="britter" due-to="Hendrik Saly">Add ThreadUtils - A utility class which provides helper methods related to java.lang.Thread</action>
<action issue="LANG-1031" type="add" dev="britter" due-to="Felipe Adorno">Add annotations to exclude fields from ReflectionEqualsBuilder, ReflectionToStringBuilder and ReflectionHashCodeBuilder</action>
<action issue="LANG-1127" type="add" dev="chas">Unit test helpers which set and reset default Locale and TimeZone</action>
[3/3] [lang] Merge branch 'LANG-701'
Posted by br...@apache.org.
Merge branch 'LANG-701'
LANG-701: StringUtils join with var args. Thanks to James Sawle.
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/7fae5b0b
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/7fae5b0b
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/7fae5b0b
Branch: refs/heads/master
Commit: 7fae5b0b17dbfa46236243cc53f0ea853ed89f5c
Parents: 98220ad 9752bbc
Author: Benedikt Ritter <br...@apache.org>
Authored: Tue May 5 20:32:39 2015 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Tue May 5 20:32:39 2015 +0200
----------------------------------------------------------------------
src/changes/changes.xml | 1 +
.../org/apache/commons/lang3/StringUtils.java | 41 +++++++++++++++++++-
.../apache/commons/lang3/StringUtilsTest.java | 18 +++++++++
3 files changed, 59 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/7fae5b0b/src/changes/changes.xml
----------------------------------------------------------------------
diff --cc src/changes/changes.xml
index 3523968,2ecf557..ab6245e
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@@ -22,8 -22,7 +22,9 @@@
<body>
<release version="3.5" date="tba" description="tba">
+ <action issue="LANG-701" type="add" dev="britter" due-to="James Sawle">StringUtils join with var args</action>
+ <action issue="LANG-1130" type="fix" dev="britter">Fix critical issues reported by SonarQube</action>
+ <action issue="LANG-1131" type="fix" dev="britter">StrBuilder.equals(StrBuilder) doesn't check for null inputs</action>
<action issue="LANG-1105" type="add" dev="britter" due-to="Hendrik Saly">Add ThreadUtils - A utility class which provides helper methods related to java.lang.Thread</action>
<action issue="LANG-1031" type="add" dev="britter" due-to="Felipe Adorno">Add annotations to exclude fields from ReflectionEqualsBuilder, ReflectionToStringBuilder and ReflectionHashCodeBuilder</action>
<action issue="LANG-1127" type="add" dev="chas">Unit test helpers which set and reset default Locale and TimeZone</action>