[teiid-commits] teiid SVN: r1193 - in trunk: common-core/src/main/java/com/metamatrix/common/util and 1 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Jul 27 14:50:49 EDT 2009


Author: shawkins
Date: 2009-07-27 14:50:49 -0400 (Mon, 27 Jul 2009)
New Revision: 1193

Modified:
   trunk/build/kit-runtime/deploy.properties
   trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
   trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java
Log:
TEIID-740 update to numeric getters to check for ws and empty strings

Modified: trunk/build/kit-runtime/deploy.properties
===================================================================
--- trunk/build/kit-runtime/deploy.properties	2009-07-27 03:24:44 UTC (rev 1192)
+++ trunk/build/kit-runtime/deploy.properties	2009-07-27 18:50:49 UTC (rev 1193)
@@ -123,8 +123,8 @@
 server.portNumber=31000
 server.bindAddress=localhost
 server.maxSocketThreads=15
-server.inputBufferSize=0       
-server.outputBufferSize=0      
+server.inputBufferSize=0
+server.outputBufferSize=0
 
 # SSL Settings
 ssl.enabled=false

Modified: trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java	2009-07-27 03:24:44 UTC (rev 1192)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java	2009-07-27 18:50:49 UTC (rev 1193)
@@ -42,7 +42,6 @@
 import java.util.Properties;
 
 import com.metamatrix.common.properties.UnmodifiableProperties;
-import com.metamatrix.common.protocol.URLHelper;
 import com.metamatrix.core.CorePlugin;
 import com.metamatrix.core.MetaMatrixRuntimeException;
 import com.metamatrix.core.util.ArgCheck;
@@ -346,63 +345,83 @@
     }
 
     public static int getIntProperty(Properties props, String propName, int defaultValue) throws InvalidPropertyException {
-        int val = defaultValue;
         String stringVal = props.getProperty(propName);
-        if(stringVal != null && stringVal.trim().length() > 0) {
-            try {
-                val = Integer.parseInt(stringVal);
-            } catch(NumberFormatException e) {
-                throw new InvalidPropertyException(propName, stringVal, Integer.class, e);
-            }
+        if(stringVal == null) {
+        	return defaultValue;
         }
-        return val;
+    	stringVal = stringVal.trim();
+    	if (stringVal.length() == 0) {
+    		return defaultValue;
+    	}
+        try {
+            return Integer.parseInt(stringVal);
+        } catch(NumberFormatException e) {
+            throw new InvalidPropertyException(propName, stringVal, Integer.class, e);
+        }
     }
 
     public static long getLongProperty(Properties props, String propName, long defaultValue) {
-        long val = defaultValue;
         String stringVal = props.getProperty(propName);
-        if(stringVal != null && stringVal.trim().length() > 0) {
-            try {
-                val = Long.parseLong(props.getProperty(propName));
-            } catch(NumberFormatException e) {
-            	throw new InvalidPropertyException(propName, stringVal, Integer.class, e);
-            }
+        if(stringVal == null) {
+        	return defaultValue;
         }
-        return val;
+    	stringVal = stringVal.trim();
+    	if (stringVal.length() == 0) {
+    		return defaultValue;
+    	}
+        try {
+            return Long.parseLong(stringVal);
+        } catch(NumberFormatException e) {
+        	throw new InvalidPropertyException(propName, stringVal, Long.class, e);
+        }
     }
 
     public static float getFloatProperty(Properties props, String propName, float defaultValue) {
-        float val = defaultValue;
-        if(props.containsKey(propName)) {
-            try {
-                Float f = new Float(props.getProperty(propName));
-                val = f.floatValue();
-            } catch(NumberFormatException e) {
-                // ignore
-            }
+        String stringVal = props.getProperty(propName);
+        if(stringVal == null) {
+        	return defaultValue;
         }
-        return val;
+    	stringVal = stringVal.trim();
+    	if (stringVal.length() == 0) {
+    		return defaultValue;
+    	}
+        try {
+            return Float.parseFloat(stringVal);
+        } catch(NumberFormatException e) {
+        	throw new InvalidPropertyException(propName, stringVal, Float.class, e);
+        }
     }
 
     public static double getDoubleProperty(Properties props, String propName, double defaultValue) {
-        double val = defaultValue;
-        if(props.containsKey(propName)) {
-            try {
-                Double d = new Double(props.getProperty(propName));
-                val = d.doubleValue();
-            } catch(NumberFormatException e) {
-                // ignore
-            }
+        String stringVal = props.getProperty(propName);
+        if(stringVal == null) {
+        	return defaultValue;
         }
-        return val;
+    	stringVal = stringVal.trim();
+    	if (stringVal.length() == 0) {
+    		return defaultValue;
+    	}
+        try {
+            return Double.parseDouble(stringVal);
+        } catch(NumberFormatException e) {
+        	throw new InvalidPropertyException(propName, stringVal, Double.class, e);
+        }
     }
 
     public static boolean getBooleanProperty(Properties props, String propName, boolean defaultValue) {
-        boolean val = defaultValue;
-        if(props.containsKey(propName)) {
-            val = Boolean.valueOf(props.getProperty(propName)).booleanValue();
+        String stringVal = props.getProperty(propName);
+        if(stringVal == null) {
+        	return defaultValue;
         }
-        return val;
+    	stringVal = stringVal.trim();
+    	if (stringVal.length() == 0) {
+    		return defaultValue;
+    	}
+        try {
+            return Boolean.valueOf(stringVal);
+        } catch(NumberFormatException e) {
+        	throw new InvalidPropertyException(propName, stringVal, Float.class, e);
+        }
     }
 
     /**

Modified: trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java	2009-07-27 03:24:44 UTC (rev 1192)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java	2009-07-27 18:50:49 UTC (rev 1193)
@@ -646,29 +646,29 @@
     public void testOverrideProperties() {
         Properties p = new Properties();
         
-        p.setProperty("foo", "bar"); 
-        p.setProperty("foo1", "bar1");
-        p.setProperty("foo2", "bar2");
+        p.setProperty("foo", "bar");  //$NON-NLS-1$ //$NON-NLS-2$
+        p.setProperty("foo1", "bar1"); //$NON-NLS-1$ //$NON-NLS-2$
+        p.setProperty("foo2", "bar2"); //$NON-NLS-1$ //$NON-NLS-2$
         
         Properties p1 = new Properties(p);
         
-        p1.setProperty("foo", "x");
+        p1.setProperty("foo", "x"); //$NON-NLS-1$ //$NON-NLS-2$
         
         PropertiesUtils.setOverrideProperies(p1, p);
         
-        assertEquals("bar", p1.getProperty("foo"));
+        assertEquals("bar", p1.getProperty("foo")); //$NON-NLS-1$ //$NON-NLS-2$
         
         assertEquals(1, p1.size());
     }
     
     public void testGetInvalidInt() {
     	Properties p = new Properties();
-    	p.setProperty("x", "y");
+    	p.setProperty("x", "y"); //$NON-NLS-1$ //$NON-NLS-2$
     	try {
-    		PropertiesUtils.getIntProperty(p, "x", 1);
-    		fail("expected exception");
+    		PropertiesUtils.getIntProperty(p, "x", 1); //$NON-NLS-1$
+    		fail("expected exception"); //$NON-NLS-1$
     	} catch (InvalidPropertyException e) {
-    		assertEquals("Property 'x' with value 'y' is not a valid Integer.", e.getMessage());
+    		assertEquals("Property 'x' with value 'y' is not a valid Integer.", e.getMessage()); //$NON-NLS-1$
     	}
     }
     
@@ -707,25 +707,31 @@
     public void testSetBeanProperties() {
     	Bean bean = new Bean();
     	Properties p = new Properties();
-    	p.setProperty("prop", "0");
-    	p.setProperty("prop1", "1");
-    	p.setProperty("prop2", "2");
-    	p.setProperty("prop3", "3");
+    	p.setProperty("prop", "0");  //$NON-NLS-1$//$NON-NLS-2$
+    	p.setProperty("prop1", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+    	p.setProperty("prop2", "2"); //$NON-NLS-1$ //$NON-NLS-2$
+    	p.setProperty("prop3", "3"); //$NON-NLS-1$ //$NON-NLS-2$
     	
     	PropertiesUtils.setBeanProperties(bean, p, null);
     	
     	assertEquals(0, bean.getProp());
-    	assertEquals("1", bean.getProp1());
+    	assertEquals("1", bean.getProp1()); //$NON-NLS-1$
     	assertEquals(2d, bean.getProp2());
-    	assertEquals(Arrays.asList("3"), bean.getProp3());
+    	assertEquals(Arrays.asList("3"), bean.getProp3()); //$NON-NLS-1$
     	
-    	p.setProperty("prop", "?");
+    	p.setProperty("prop", "?"); //$NON-NLS-1$ //$NON-NLS-2$
     	
     	try {
     		PropertiesUtils.setBeanProperties(bean, p, null);
-    		fail("expected exception");
+    		fail("expected exception"); //$NON-NLS-1$
     	} catch (InvalidPropertyException e) {
     		
     	}
     }
+    
+    public void testGetInt() {
+    	Properties p = new Properties();
+    	p.setProperty("prop", "0  "); //$NON-NLS-1$ //$NON-NLS-2$
+    	assertEquals(PropertiesUtils.getIntProperty(p, "prop", -1), 0); //$NON-NLS-1$
+    }
 }



More information about the teiid-commits mailing list