[Schmitzm-commits] r2071 - trunk/schmitzm-core/src/main/java/de/schmitzm/lang
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Thu Jul 5 16:26:47 CEST 2012
Author: mojays
Date: 2012-07-05 16:26:46 +0200 (Thu, 05 Jul 2012)
New Revision: 2071
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
Log:
LangUtil: Workaround to use parseStringDefaultNull(.) without the use of removeWhitespacesToEmpty(.) and RegexCache
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2012-07-02 13:01:10 UTC (rev 2070)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2012-07-05 14:26:46 UTC (rev 2071)
@@ -92,6 +92,14 @@
public class LangUtil {
private static NumberFormat DEFAULT_DELAY_FORMAT = new DecimalFormat("0.00");
+ /** If {@code true} {@link #removeWhitespacesToEmpty(String)} (which uses {@link RegexCache})
+ * is called in {@link #parseStringDefaultNull(String, boolean)}.
+ * To avoid this behavior for an application, this flag can be set to {@code false}.<br>
+ * Default: {@code true}
+ */
+ public static boolean REMOVE_WHITESPACES_ON_PARSE_STRING = true;
+
+
/** Eine Sekunde in Millisekunden. */
public static final long SEC_MILLIS = 1000;
/** Eine Minute in Millisekunden. */
@@ -170,7 +178,27 @@
return "";
return string.trim();
}
+
+ /**
+ * Checks whether {@link RegexCache} is available. In some cases the
+ * "Apache Lucene" library is excluded because of application size
+ * issues ("FatJar"). This method checks this case and sets the
+ * {@link #REMOVE_WHITESPACES_ON_PARSE_STRING} flag.
+ * This method can be called at the beginning of an application.
+ */
+ public static boolean checkRegexCacheAvailable() {
+ try {
+ RegexCache.getInstance();
+ REMOVE_WHITESPACES_ON_PARSE_STRING = true;
+ return true;
+ } catch (Throwable e) {
+ // RegexCache can not be used
+ REMOVE_WHITESPACES_ON_PARSE_STRING = false;
+ return false;
+ }
+ }
+
/**
* Returns "+" for positive values and "-" for negative values.
*
@@ -2404,8 +2432,13 @@
public static Boolean parseStringDefaultNull(String str, boolean lax) {
if (str == null)
return null;
- String trimmedLowcase = removeWhitespacesToEmpty(str.toLowerCase())
- .trim();
+// String trimmedLowcase = removeWhitespacesToEmpty(str.toLowerCase())
+// .trim();
+ String trimmedLowcase = str.toLowerCase();
+ if ( REMOVE_WHITESPACES_ON_PARSE_STRING )
+ trimmedLowcase = removeWhitespacesToEmpty(trimmedLowcase);
+ trimmedLowcase = trimmedLowcase.trim();
+
if (trimmedLowcase.startsWith("no"))
return false;
if (trimmedLowcase.endsWith("no"))
More information about the Schmitzm-commits
mailing list