Added toStringSeparatedBy Character methods.
This commit is contained in:
parent
668bb8fbb7
commit
164c9a07aa
3 changed files with 96 additions and 0 deletions
|
@ -1963,6 +1963,32 @@ public class StringList extends ArrayList<String> 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
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue