[Schmitzm-commits] r1612 - trunk/schmitzm-core/src/main/java/de/schmitzm/lang

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jun 23 12:55:00 CEST 2011


Author: mojays
Date: 2011-06-23 12:54:59 +0200 (Thu, 23 Jun 2011)
New Revision: 1612

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
Log:
new LangUtil.trimToSize(.) with trimToNull-option

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2011-06-18 19:06:18 UTC (rev 1611)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2011-06-23 10:54:59 UTC (rev 1612)
@@ -307,18 +307,37 @@
 	 *            source string
 	 * @param maxSize
 	 *            maximum size
+	 * @param trimToNull
+	 *            if trimmed string becomes empty {@code null} will
+	 *            be returned
 	 * @return {@code null} if {@code null} is given
 	 */
-	public static String trimToSize(String str, int maxSize) {
+	public static String trimToSize(String str, int maxSize, boolean trimToNull) {
 		if (str == null)
 			return null;
 		str = str.trim();
 		if (str.length() <= maxSize)
 			return str;
+		if ( trimToNull )
+		  return StringUtils.trimToNull(str);
 		return str.substring(0, maxSize);
+		
 	}
 
-	/**
+    /**
+     * Trims a string to a maximum length.
+     * 
+     * @param str
+     *            source string
+     * @param maxSize
+     *            maximum size
+     * @return {@code null} if {@code null} is given
+     */
+    public static String trimToSize(String str, int maxSize) {
+        return trimToSize(str, maxSize, false);
+    }
+
+    /**
 	 * Checks whether both objects are {@code null} or equal.
 	 */
 	public static boolean checkEqual(Object o1, Object o2) {



More information about the Schmitzm-commits mailing list