From da2ab0d2e29376384959a100fe0c0b95b29055f4 Mon Sep 17 00:00:00 2001
From: ribeaudc <ribeaudc>
Date: Thu, 15 May 2008 07:00:04 +0000
Subject: [PATCH] change: - Parameters in 'datamover' refactored.

SVN: 6055
---
 .../cisd/common/utilities/PropertyUtils.java  | 39 +++++++++++++++----
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/PropertyUtils.java b/common/source/java/ch/systemsx/cisd/common/utilities/PropertyUtils.java
index b9c9e962f8c..cb43b2cdd06 100644
--- a/common/source/java/ch/systemsx/cisd/common/utilities/PropertyUtils.java
+++ b/common/source/java/ch/systemsx/cisd/common/utilities/PropertyUtils.java
@@ -67,6 +67,30 @@ public final class PropertyUtils
         assert propertyKey != null : "Given property key can not be null.";
     }
 
+    /**
+     * Searches for the property with the specified key in this property list.
+     * 
+     * @return <code>null</code> or the value trimmed if found.
+     */
+    public final static String getProperty(final Properties properties, final String propertyKey)
+    {
+        assertParameters(properties, propertyKey);
+        final String property = properties.getProperty(propertyKey);
+        return property == null ? null : property.trim();
+    }
+
+    /**
+     * Searches for the property with the specified key in this property list.
+     * 
+     * @return <code>null</code> or the value trimmed if found.
+     */
+    public final static String getProperty(final Properties properties, final String propertyKey,
+            final String defaultValue)
+    {
+        final String property = getProperty(properties, propertyKey);
+        return property == null ? defaultValue : property;
+    }
+
     /**
      * Looks up given mandatory <var>propertyKey</var> in given <var>properties</var>.
      * 
@@ -77,14 +101,13 @@ public final class PropertyUtils
             final String propertyKey) throws ConfigurationFailureException
     {
         assertParameters(properties, propertyKey);
-        String property = properties.getProperty(propertyKey);
+        String property = getProperty(properties, propertyKey);
         if (property == null)
         {
             throw ConfigurationFailureException.fromTemplate(NOT_FOUND_PROPERTY_FORMAT,
                     propertyKey, CollectionUtils.abbreviate(Collections.list(properties
                             .propertyNames()), 10));
         }
-        property = property.trim();
         if (property.length() == 0)
         {
             throw ConfigurationFailureException.fromTemplate(EMPTY_STRING_FORMAT, propertyKey);
@@ -101,7 +124,7 @@ public final class PropertyUtils
             final long defaultValue, final ISimpleLogger loggerOrNull)
     {
         assertParameters(properties, propertyKey);
-        final String longOrNull = properties.getProperty(propertyKey);
+        final String longOrNull = getProperty(properties, propertyKey);
         if (longOrNull == null)
         {
             return defaultValue;
@@ -139,7 +162,7 @@ public final class PropertyUtils
     {
         assertParameters(properties, propertyKey);
         assert defaultValue > -1 : "Negative default value (< 0).";
-        final String longOrNull = properties.getProperty(propertyKey);
+        final String longOrNull = getProperty(properties, propertyKey);
         if (longOrNull == null)
         {
             return defaultValue;
@@ -176,7 +199,7 @@ public final class PropertyUtils
             final int defaultValue, final ISimpleLogger loggerOrNull)
     {
         assertParameters(properties, propertyKey);
-        final String intOrNull = properties.getProperty(propertyKey);
+        final String intOrNull = getProperty(properties, propertyKey);
         if (intOrNull == null)
         {
             return defaultValue;
@@ -214,7 +237,7 @@ public final class PropertyUtils
     {
         assertParameters(properties, propertyKey);
         assert defaultValue > -1 : "Negative default value (< 0).";
-        final String intOrNull = properties.getProperty(propertyKey);
+        final String intOrNull = getProperty(properties, propertyKey);
         if (intOrNull == null)
         {
             return defaultValue;
@@ -251,7 +274,7 @@ public final class PropertyUtils
             final boolean defaultValue, final ISimpleLogger loggerOrNull)
     {
         assertParameters(properties, propertyKey);
-        final String booleanOrNull = properties.getProperty(propertyKey);
+        final String booleanOrNull = getProperty(properties, propertyKey);
         if (booleanOrNull == null)
         {
             return defaultValue;
@@ -289,7 +312,7 @@ public final class PropertyUtils
             final char defaultValue, final ISimpleLogger loggerOrNull)
     {
         assertParameters(properties, propertyKey);
-        final String charOrNull = properties.getProperty(propertyKey);
+        final String charOrNull = getProperty(properties, propertyKey);
         if (charOrNull == null)
         {
             return defaultValue;
-- 
GitLab