Implemented: New UtilMisc method collectionToString(...) building safely a

String with the given collection and delimiter
(OFBIZ-9397)

The added method UtilMisc.collectionToString(Collection values, String delimiter) 
creates a String from the values of a collection, separated with the given 
delimiter. This is done in a safe way without a "null" literal.

Thanks: Martin Becker

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1804970 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2017-08-14 09:52:49 +00:00
parent 514cdb1ae5
commit a85c94dc2f
@@ -264,6 +264,29 @@ public final class UtilMisc {
}
return theSet;
}
/**
* Generates a String from given values delimited by delimiter.
*
* @param values
* @param delimiter
* @return String
* @throws IOException
*/
public static String collectionToString(Collection<? extends Object> values, String delimiter) {
if (UtilValidate.isEmpty(values)) {
return null;
}
if (delimiter == null) {
delimiter = "";
}
StringBuilder out = new StringBuilder();
for (Object val : values) {
out.append(UtilFormatOut.safeToString(val)).append(delimiter);
}
return out.toString();
}
/**
* Create a set from the passed objects.