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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user