You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/08/01 23:02:16 UTC
cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang StringUtils.java
scolebourne 2003/08/01 14:02:16
Modified: lang/src/test/org/apache/commons/lang StringUtilsTest.java
lang/src/java/org/apache/commons/lang StringUtils.java
Log:
Add join(Object[]) as a replacement for concatenate
Revision Changes Path
1.42 +12 -2 jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java
Index: StringUtilsTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- StringUtilsTest.java 31 Jul 2003 20:38:26 -0000 1.41
+++ StringUtilsTest.java 1 Aug 2003 21:02:16 -0000 1.42
@@ -205,6 +205,16 @@
"Hello aPACHE", StringUtils.swapCase("hELLO Apache") );
}
+ public void testJoin_Objectarray() {
+ assertEquals(null, StringUtils.join(null));
+ assertEquals("", StringUtils.join(EMPTY_ARRAY_LIST));
+ assertEquals("", StringUtils.join(NULL_ARRAY_LIST));
+ assertEquals("abc", StringUtils.join(new String[] {"a", "b", "c"}));
+ assertEquals("a", StringUtils.join(new String[] {null, "a", ""}));
+ assertEquals("foo", StringUtils.join(MIXED_ARRAY_LIST));
+ assertEquals("foo2", StringUtils.join(MIXED_TYPE_LIST));
+ }
+
public void testJoin_ArrayChar() {
assertEquals(null, StringUtils.join((Object[]) null, ','));
assertEquals(TEXT_LIST_CHAR, StringUtils.join(ARRAY_LIST, SEPARATOR_CHAR));
@@ -250,7 +260,7 @@
assertEquals(TEXT_LIST, StringUtils.join(Arrays.asList(ARRAY_LIST).iterator(), SEPARATOR));
}
- public void testConcatenate_Array() {
+ public void testConcatenate_Objectarray() {
assertEquals(null, StringUtils.concatenate(null));
assertEquals("", StringUtils.concatenate(EMPTY_ARRAY_LIST));
assertEquals("", StringUtils.concatenate(NULL_ARRAY_LIST));
1.85 +26 -4 jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java
Index: StringUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -r1.84 -r1.85
--- StringUtils.java 1 Aug 2003 20:45:17 -0000 1.84
+++ StringUtils.java 1 Aug 2003 21:02:16 -0000 1.85
@@ -1909,9 +1909,6 @@
* Null objects or empty strings within the array are represented by
* empty strings.</p>
*
- * <p>The difference from join is that concatenate has no delimiter -- i.e., <br>
- * <code>StringUtils.concatenate(array) = StringUtils.join(array, null)</code>.</p>
- *
* <pre>
* StringUtils.concatenate(null) = null
* StringUtils.concatenate([]) = ""
@@ -1922,8 +1919,33 @@
*
* @param array the array of values to concatenate, may be null
* @return the concatenated String, <code>null</code> if null array input
+ * @deprecated Use the better named {@link #join(Object[])} instead.
+ * Method will be removed in Commons Lang 3.0.
*/
public static String concatenate(Object[] array) {
+ return join(array, null);
+ }
+
+ /**
+ * <p>Joins the elements of the provided array into a single String
+ * containing the provided list of elements.</p>
+ *
+ * <p>No separator is added to the joined String.
+ * Null objects or empty strings within the array are represented by
+ * empty strings.</p>
+ *
+ * <pre>
+ * StringUtils.join(null) = null
+ * StringUtils.join([]) = ""
+ * StringUtils.join([null]) = ""
+ * StringUtils.join(["a", "b", "c"]) = "abc"
+ * StringUtils.join([null, "", "a"]) = "a"
+ * </pre>
+ *
+ * @param array the array of values to join together, may be null
+ * @return the joined String, <code>null</code> if null array input
+ */
+ public static String join(Object[] array) {
return join(array, null);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org