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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Jun 14 13:08:13 CEST 2011


Author: mojays
Date: 2011-06-14 13:08:12 +0200 (Tue, 14 Jun 2011)
New Revision: 1608

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
Log:


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-14 08:21:05 UTC (rev 1607)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2011-06-14 11:08:12 UTC (rev 1608)
@@ -245,6 +245,21 @@
 		return stackTraceStr;
 	}
 
+  /**
+   * 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) {
+	  if ( str == null )
+	    return null;
+	  str = str.trim();
+	  if  ( str.length() <= maxSize )
+	    return str;
+	  return str.substring(0,maxSize);
+	}
+
 	/**
 	 * Checks whether both objects are {@code null} or equal.
 	 */



More information about the Schmitzm-commits mailing list