(no commit message)
authorAndreas Müller <a.mueller@bgbm.org>
Mon, 28 Apr 2008 23:16:00 +0000 (23:16 +0000)
committerAndreas Müller <a.mueller@bgbm.org>
Mon, 28 Apr 2008 23:16:00 +0000 (23:16 +0000)
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/CdmUtils.java

index 19fe58c156b6f69f5ad152b908e1b277bae788db..cbba306dda43110e986b805f7ddb446bf176a003 100644 (file)
@@ -6,6 +6,7 @@
 * The contents of this file are subject to the Mozilla Public License Version 1.1\r
 * See LICENSE.TXT at the top of this package for the full license terms.\r
 */\r
+\r
 package eu.etaxonomy.cdm.common;\r
 \r
 import java.io.BufferedReader;\r
@@ -110,5 +111,43 @@ public class CdmUtils {
        static public String Nz(String value){\r
                return (value == null ? "" : value);\r
        }\r
+\r
+       \r
+       static public Integer Nz(Integer value){\r
+               return (value == null ? 0 : value);\r
+       }\r
+       \r
+       /**\r
+        * Concatenates the an Array of Strings, using the defined seperator.\r
+        * Null values are interpreted as empty Strings\r
+        * If all Strings are null a null is returned \r
+        * @param strings\r
+        * @param seperator\r
+        * @return String \r
+        */\r
+       static public String concat(CharSequence seperator, String[] strings){\r
+               String result = "";\r
+               boolean allNull = true;\r
+               for (String string : strings){\r
+                       if (string != null){\r
+                               if (result.length() > 0 && string.length() > 0){\r
+                                       result += seperator;\r
+                               }\r
+                               result += string;\r
+                               allNull = false;\r
+                       }\r
+               }\r
+               //if all strings are null result should be null, not ""\r
+               if (allNull){\r
+                       return null;\r
+               }else {\r
+                       return result;\r
+               }\r
+       }\r
+\r
+       static public String concat(CharSequence seperator, String string1, String string2){\r
+               String[] strings = {string1, string2};\r
+               return concat(seperator, strings);\r
+       }\r
        \r
 }
\ No newline at end of file