commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject cvs commit: jakarta-commons/configuration/xdocs changes.xml
Date Tue, 05 Oct 2004 22:56:58 GMT
ebourg      2004/10/05 15:56:58

  Modified:    configuration/src/java/org/apache/commons/configuration
                        CompositeConfiguration.java
               configuration/src/test/org/apache/commons/configuration
                        TestCompositeConfiguration.java
               configuration/xdocs changes.xml
  Log:
  The getStringArray() method in CompositeConfiguration now interpotales the strings.
  
  Revision  Changes    Path
  1.19      +12 -11    jakarta-commons/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java
  
  Index: CompositeConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- CompositeConfiguration.java	19 Sep 2004 22:01:50 -0000	1.18
  +++ CompositeConfiguration.java	5 Oct 2004 22:56:58 -0000	1.19
  @@ -312,15 +312,7 @@
        */
       public Vector getVector(String key, Vector defaultValue)
       {
  -        List list = getList(key, defaultValue);
  -        Vector vector = new Vector(list.size());
  -
  -        for (Iterator it = list.iterator(); it.hasNext();)
  -        {
  -            vector.add(it.next());
  -        }
  -
  -        return vector;
  +        return new Vector(getList(key, defaultValue));
       }
   
       /**
  @@ -329,7 +321,16 @@
       public String[] getStringArray(String key)
       {
           List list = getList(key);
  -        return (String []) list.toArray(new String [0]);
  +
  +        // interpolate the strings
  +        String[] tokens = new String[list.size()];
  +
  +        for (int i = 0; i < tokens.length; i++)
  +        {
  +            tokens[i] = interpolate(String.valueOf(list.get(i)));
  +        }
  +
  +        return tokens;
       }
   
       /**
  
  
  
  1.14      +69 -52    jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java
  
  Index: TestCompositeConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TestCompositeConfiguration.java	22 Sep 2004 17:17:30 -0000	1.13
  +++ TestCompositeConfiguration.java	5 Oct 2004 22:56:58 -0000	1.14
  @@ -37,7 +37,9 @@
       protected XMLConfiguration xmlConf;
       protected CompositeConfiguration cc;
   
  -    /** The File that we test with */
  +    /**
  +     * The File that we test with
  +     */
       private String testProperties = new File("conf/test.properties").getAbsolutePath();
       private String testProperties2 = new File("conf/test2.properties").getAbsolutePath();
       private String testPropertiesXML = new File("conf/test.xml").getAbsolutePath();
  @@ -81,7 +83,7 @@
           Vector v = cc.getVector("packages");
           assertTrue(v.contains("packagea"));
       }
  -    
  +
       public void testGetProperty() throws Exception
       {
           cc.addConfiguration(conf1);
  @@ -103,24 +105,24 @@
           cc.removeConfiguration(internal);
   
           assertEquals(1, cc.getNumberOfConfigurations());
  -
       }
   
       public void testGetPropertyMissing() throws Exception
       {
           cc.addConfiguration(conf1);
           cc.addConfiguration(conf2);
  -        try{
  +        try
  +        {
               assertNull(cc.getString("bogus.property"));
               fail("Should have thrown a NoSuchElementException");
           }
  -        catch(NoSuchElementException nsee){
  -            assertTrue(nsee.getMessage().indexOf("bogus.property")>-1);
  +        catch (NoSuchElementException nsee)
  +        {
  +            assertTrue(nsee.getMessage().indexOf("bogus.property") > -1);
           }
   
           assertTrue("Should be false", !cc.getBoolean("test.missing.boolean", false));
           assertTrue("Should be true", cc.getBoolean("test.missing.boolean.true", true));
  -
       }
   
       /**
  @@ -251,8 +253,8 @@
       }
   
       /**
  -      * Tests <code>List</code> parsing.
  -      */
  +     * Tests <code>List</code> parsing.
  +     */
       public void testList() throws Exception
       {
           cc.addConfiguration(conf1);
  @@ -284,8 +286,8 @@
       }
   
       /**
  -      * Tests <code>String</code> array parsing.
  -      */
  +     * Tests <code>String</code> array parsing.
  +     */
       public void testStringArray() throws Exception
       {
           cc.addConfiguration(conf1);
  @@ -356,19 +358,17 @@
           cc.addProperty("array", "value5");
   
           List list = cc.getList("array");
  -        
  -        for (Iterator it = list.iterator(); it.hasNext(); )
  +
  +        for (Iterator it = list.iterator(); it.hasNext();)
           {
               Object value = it.next();
  -            System.out.println(value.getClass().getName() + " -> " + value);
           }
   
           Vector lVector = cc.getVector("array");
  -        
  -        for (Iterator it = lVector.iterator(); it.hasNext(); )
  +
  +        for (Iterator it = lVector.iterator(); it.hasNext();)
           {
               Object value = it.next();
  -            System.out.println(value.getClass().getName() + " -> " + value);
           }
   
           // test the new vector
  @@ -381,45 +381,51 @@
       }
   
       /**
  -      * Tests <code>getKeys</code> preserves the order
  -      */
  +     * Tests <code>getKeys</code> preserves the order
  +     */
       public void testGetKeysPreservesOrder() throws Exception
       {
           cc.addConfiguration(conf1);
           List orderedList = new ArrayList();
  -        for (Iterator keys = conf1.getKeys();keys.hasNext();){
  +        for (Iterator keys = conf1.getKeys(); keys.hasNext();)
  +        {
               orderedList.add(keys.next());
           }
           List iteratedList = new ArrayList();
  -        for (Iterator keys = cc.getKeys();keys.hasNext();){
  +        for (Iterator keys = cc.getKeys(); keys.hasNext();)
  +        {
               iteratedList.add(keys.next());
           }
  -        assertEquals(orderedList.size(),iteratedList.size());
  -        for (int i =0;i<orderedList.size();i++){
  -            assertEquals(orderedList.get(i),iteratedList.get(i));
  -        }        
  -    }    
  +        assertEquals(orderedList.size(), iteratedList.size());
  +        for (int i = 0; i < orderedList.size(); i++)
  +        {
  +            assertEquals(orderedList.get(i), iteratedList.get(i));
  +        }
  +    }
   
       /**
  -      * Tests <code>getKeys(String key)</code> preserves the order
  -      */
  +     * Tests <code>getKeys(String key)</code> preserves the order
  +     */
       public void testGetKeys2PreservesOrder() throws Exception
       {
           cc.addConfiguration(conf1);
           List orderedList = new ArrayList();
  -        for (Iterator keys = conf1.getKeys("test");keys.hasNext();){
  +        for (Iterator keys = conf1.getKeys("test"); keys.hasNext();)
  +        {
               orderedList.add(keys.next());
           }
           List iteratedList = new ArrayList();
  -        for (Iterator keys = cc.getKeys("test");keys.hasNext();){
  +        for (Iterator keys = cc.getKeys("test"); keys.hasNext();)
  +        {
               iteratedList.add(keys.next());
           }
  -        assertEquals(orderedList.size(),iteratedList.size());
  -        for (int i =0;i<orderedList.size();i++){
  -            assertEquals(orderedList.get(i),iteratedList.get(i));
  -        }        
  -    }        
  -    
  +        assertEquals(orderedList.size(), iteratedList.size());
  +        for (int i = 0; i < orderedList.size(); i++)
  +        {
  +            assertEquals(orderedList.get(i), iteratedList.get(i));
  +        }
  +    }
  +
       public void testGetStringWithDefaults()
       {
           BaseConfiguration defaults = new BaseConfiguration();
  @@ -445,23 +451,17 @@
           }
   
           //test defaults
  -        assertEquals(
  -            "test string",
  -            c.getString("string", "some default value"));
  +        assertEquals("test string", c.getString("string", "some default value"));
           assertEquals("default string", c.getString("default"));
  -        assertEquals(
  -            "default string",
  -            c.getString("default", "some default value"));
  -        assertEquals(
  -            "some default value",
  -            c.getString("XXX", "some default value"));
  +        assertEquals("default string", c.getString("default", "some default value"));
  +        assertEquals("some default value", c.getString("XXX", "some default value"));
       }
  -    
  +
       public void testCheckingInMemoryConfiguration() throws Exception
       {
           String TEST_KEY = "testKey";
           Configuration defaults = new PropertiesConfiguration();
  -        defaults.setProperty(TEST_KEY,"testValue");
  +        defaults.setProperty(TEST_KEY, "testValue");
           Configuration testConfiguration = new CompositeConfiguration(defaults);
           assertTrue(testConfiguration.containsKey(TEST_KEY));
           assertFalse(testConfiguration.isEmpty());
  @@ -470,14 +470,31 @@
           //assertTrue(i instanceof IteratorChain);
           //IteratorChain ic = (IteratorChain)i;
           //assertEquals(2,i.size());
  -        for (;i.hasNext();){
  -            String key = (String)i.next();
  -            if(key.equals(TEST_KEY)){
  +        for (; i.hasNext();)
  +        {
  +            String key = (String) i.next();
  +            if (key.equals(TEST_KEY))
  +            {
                   foundTestKey = true;
               }
           }
           assertTrue(foundTestKey);
           testConfiguration.clearProperty(TEST_KEY);
           assertFalse(testConfiguration.containsKey(TEST_KEY));
  -    }    
  +    }
  +
  +    public void testStringArrayInterpolation()
  +    {
  +        CompositeConfiguration config = new CompositeConfiguration();
  +        config.addProperty("base", "foo");
  +        config.addProperty("list", "${base}.bar1");
  +        config.addProperty("list", "${base}.bar2");
  +        config.addProperty("list", "${base}.bar3");
  +
  +        String[] array = config.getStringArray("list");
  +        assertEquals("size", 3, array.length);
  +        assertEquals("1st element", "foo.bar1", array[0]);
  +        assertEquals("2nd element", "foo.bar2", array[1]);
  +        assertEquals("3rd element", "foo.bar3", array[2]);
  +    }
   }
  
  
  
  1.53      +4 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- changes.xml	5 Oct 2004 21:17:25 -0000	1.52
  +++ changes.xml	5 Oct 2004 22:56:58 -0000	1.53
  @@ -7,6 +7,10 @@
   
     <body>
       <release version="1.0" date="IN CVS">
  +      <action dev="ebourg" type="fix" issue="29616">
  +        The getStringArray() method in CompositeConfiguration now interpotales
  +        the strings.
  +      </action>
         <action dev="ebourg" type="fix" issue="31540">
           SubsetConfiguration now shares the "throwExceptionOnMissing" property
           with its parent.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message