commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1515448 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/AbstractConfiguration.java test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
Date Mon, 19 Aug 2013 14:34:23 GMT
Author: oheger
Date: Mon Aug 19 14:34:23 2013
New Revision: 1515448

URL: http://svn.apache.org/r1515448
Log:
Implemented getStringArray() in terms of the generic getArray() method.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java?rev=1515448&r1=1515447&r2=1515448&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
Mon Aug 19 14:34:23 2013
@@ -1558,40 +1558,8 @@ public abstract class AbstractConfigurat
      */
     public String[] getStringArray(String key)
     {
-        Object value = getProperty(key);
-
-        String[] array;
-
-        if (value instanceof String)
-        {
-            array = new String[1];
-
-            array[0] = interpolate((String) value);
-        }
-        else if (value instanceof List)
-        {
-            List<?> list = (List<?>) value;
-            array = new String[list.size()];
-
-            for (int i = 0; i < array.length; i++)
-            {
-                array[i] = interpolate(ObjectUtils.toString(list.get(i), null));
-            }
-        }
-        else if (value == null)
-        {
-            array = new String[0];
-        }
-        else if (isScalarValue(value))
-        {
-            array = new String[1];
-            array[0] = value.toString();
-        }
-        else
-        {
-            throw new ConversionException('\'' + key + "' doesn't map to a String/List object");
-        }
-        return array;
+        String[] result = (String[]) getArray(String.class, key);
+        return (result == null) ? new String[0] : result;
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java?rev=1515448&r1=1515447&r2=1515448&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
Mon Aug 19 14:34:23 2013
@@ -491,6 +491,17 @@ public class TestAbstractConfigurationBa
     }
 
     /**
+     * Tests getStringArray() if the key cannot be found.
+     */
+    @Test
+    public void testGetStringArrayUnknown()
+    {
+        BaseConfiguration config = new BaseConfiguration();
+        String[] array = config.getStringArray(KEY_PREFIX);
+        assertEquals("Got elements", 0, array.length);
+    }
+
+    /**
      * Helper method for checking getList() if the property value is a scalar.
      * @param value the value of the property
      */



Mime
View raw message