diff --git a/src/fr/devinsy/strings/StringList.java b/src/fr/devinsy/strings/StringList.java index ce19d8d..e8212b0 100644 --- a/src/fr/devinsy/strings/StringList.java +++ b/src/fr/devinsy/strings/StringList.java @@ -1963,6 +1963,32 @@ public class StringList extends ArrayList implements CharSequence, Appen return result; } + /** + * Returns a string containing the concatenation of the strings of this list. + * Between each string of this list, a separator argument string is concatenated + * too. + * + * @param separator + * the separator + * @return the string + */ + public String toStringSeparatedBy(final Character separator) + { + String result; + + if (separator == null) + { + result = toStringSeparatedBy(""); + } + else + { + result = toStringSeparatedBy("" + separator); + } + + // + return result; + } + /** * Returns a string containing the concatenation of the strings of this list. * Between each string of this list, a separator argument string is concatenated diff --git a/src/fr/devinsy/strings/StringsUtils.java b/src/fr/devinsy/strings/StringsUtils.java index 42dba62..282579a 100644 --- a/src/fr/devinsy/strings/StringsUtils.java +++ b/src/fr/devinsy/strings/StringsUtils.java @@ -1498,6 +1498,32 @@ public class StringsUtils return result; } + /** + * To string separated by. + * + * @param source + * the source + * @param separator + * the separator + * @return the string + */ + public static String toStringSeparatedBy(final StringList source, final Character separator) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.toStringSeparatedBy(separator); + } + + // + return result; + } + /** * To string separated by. * diff --git a/test/fr/devinsy/strings/StringListTest.java b/test/fr/devinsy/strings/StringListTest.java index fcedf19..d64f8c4 100644 --- a/test/fr/devinsy/strings/StringListTest.java +++ b/test/fr/devinsy/strings/StringListTest.java @@ -758,4 +758,48 @@ public class StringListTest // this.logger.debug("===== test done."); } + + /** + * Test to string separated by 01. + */ + @Test + public void testToStringSeparatedBy01() + { + // + this.logger.debug("===== test starting..."); + + // + { + StringList source = new StringList("aaa").append("bbb").append("ccc"); + String target = source.toStringSeparatedBy((String) null); + Assert.assertEquals("aaabbbccc", target); + } + + { + StringList source = new StringList("aaa").append("bbb").append("ccc"); + String target = source.toStringSeparatedBy(""); + Assert.assertEquals("aaabbbccc", target); + } + + { + StringList source = new StringList("aaa").append("bbb").append("ccc"); + String target = source.toStringSeparatedBy("<->"); + Assert.assertEquals("aaa<->bbb<->ccc", target); + } + + { + StringList source = new StringList("aaa").append("bbb").append("ccc"); + String target = source.toStringSeparatedBy((Character) null); + Assert.assertEquals("aaabbbccc", target); + } + + { + StringList source = new StringList("aaa").append("bbb").append("ccc"); + String target = source.toStringSeparatedBy('|'); + Assert.assertEquals("aaa|bbb|ccc", target); + } + + // + this.logger.debug("===== test done."); + } }