Adds toString(prefix, separator, postfix) method. Fix

toStringSeparatedBy size.
This commit is contained in:
Christian P. MOMON 2015-05-23 02:13:42 +02:00
parent fc45c63019
commit 78255d797d
2 changed files with 60 additions and 2 deletions

View file

@ -757,6 +757,40 @@ public class StringList extends ArrayList<String> implements CharSequence
return (result);
}
/**
*
* @param prefix
* @param separator
* @param postifx
* @return
*/
public String toString(final String prefix, final String separator, final String postfix)
{
String result;
StringList buffer = new StringList(1 + size() * 2 + 1);
buffer.append(prefix);
for (String string : this)
{
buffer.append(string);
buffer.append(separator);
}
if (separator != null)
{
buffer.removeLast();
}
buffer.append(postfix);
result = buffer.toString();
//
return result;
}
/**
* Returns an array containing all of the strings in this list in proper
* sequence (from first to last element).
@ -791,8 +825,8 @@ public class StringList extends ArrayList<String> implements CharSequence
{
String result;
//
StringList buffer = new StringList(this.length() * 2);
StringList buffer = new StringList(this.size() * 2);
for (String string : this)
{
buffer.append(string);

View file

@ -26,6 +26,30 @@ package fr.devinsy.util.strings;
*/
public class StringListUtils
{
/**
*
* @param prefix
* @param separator
* @param postfix
* @return
*/
public String toString(final StringList source, final String prefix, final String separator, final String postfix)
{
String result;
if (source == null)
{
result = prefix + postfix;
}
else
{
result = source.toString(prefix, separator, postfix);
}
//
return result;
}
/**
* Builds a string list concatenating several time one string.
*