You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by mg...@apache.org on 2013/06/20 00:29:38 UTC

svn commit: r1494788 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Util.java

Author: mgentry
Date: Wed Jun 19 22:29:37 2013
New Revision: 1494788

URL: http://svn.apache.org/r1494788
Log:
Added join() method from 3.0/3.1.

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Util.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Util.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Util.java?rev=1494788&r1=1494787&r2=1494788&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Util.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Util.java Wed Jun 19 22:29:37 2013
@@ -64,9 +64,9 @@ import org.xml.sax.XMLReader;
  * Contains various unorganized static utility methods used across Cayenne.
  */
 public class Util {
-    
+
     private static DefaultAdhocObjectFactory objectFactory;
-    
+
     static {
         objectFactory = new DefaultAdhocObjectFactory();
     }
@@ -119,6 +119,29 @@ public class Util {
     }
 
     /**
+     * @param strings The list of strings to join.
+     * @param separator The separator between the strings.
+     * @return A single string of all the input strings separated by the separator.
+     */
+    public static String join(List<String> strings, String separator) {
+        if (strings == null || strings.size() == 0)
+            return "";
+
+        if (separator == null)
+            separator = "";
+
+        StringBuilder builder = new StringBuilder();
+
+        for (String string : strings) {
+            if (builder.length() > 0)
+                builder.append(separator);
+            builder.append(string);
+        }
+
+        return builder.toString();
+    }
+
+    /**
      * Replaces all backslashes "\" with forward slashes "/". Convenience method to
      * convert path Strings to URI format.
      */
@@ -179,7 +202,7 @@ public class Util {
      * Compares two objects similar to "Comparable.compareTo(Object)". Unlike
      * Comparable.compareTo(..), this method doesn't throw an exception if any of the two
      * objects is null.
-     * 
+     *
      * @since 1.1
      */
     public static <T> int nullSafeCompare(boolean nullsFirst, Comparable<T> o1, T o2) {
@@ -264,7 +287,7 @@ public class Util {
 
     /**
      * Returns an unqualified class name for the fully qualified name.
-     * 
+     *
      * @since 3.0
      */
     public static String stripPackageName(String className) {
@@ -281,7 +304,7 @@ public class Util {
 
     /**
      * Creates a mutable map out of two arrays with keys and values.
-     * 
+     *
      * @since 1.2
      */
     public static <K, V> Map<K, V> toMap(K[] keys, V[] values) {
@@ -332,7 +355,7 @@ public class Util {
     /**
      * Strips "\n", "\r\n", "\r" from the argument string, replacing them with a provided
      * character.
-     * 
+     *
      * @since 3.1
      */
     public static String stripLineBreaks(String string, char replaceWith) {
@@ -405,7 +428,7 @@ public class Util {
 
     /**
      * Trims long strings substituting middle part with "...".
-     * 
+     *
      * @param str String to trim.
      * @param maxLength maximum allowable length. Must be at least 5, or an
      *            IllegalArgumentException is thrown.
@@ -470,7 +493,7 @@ public class Util {
     /**
      * Returns true if a Member is accessible via reflection under normal Java access
      * controls.
-     * 
+     *
      * @since 1.2
      */
     public static boolean isAccessible(Member member) {
@@ -481,7 +504,7 @@ public class Util {
     /**
      * Creates a Java class, handling regular class names as well as single-dimensional
      * arrays and primitive types.
-     * 
+     *
      * @since 1.2
      */
     public static Class<?> getJavaClass(String className) throws ClassNotFoundException {