You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2017/08/14 09:52:49 UTC

svn commit: r1804970 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java

Author: jleroux
Date: Mon Aug 14 09:52:49 2017
New Revision: 1804970

URL: http://svn.apache.org/viewvc?rev=1804970&view=rev
Log:
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

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java?rev=1804970&r1=1804969&r2=1804970&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java Mon Aug 14 09:52:49 2017
@@ -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.