commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ep...@apache.org
Subject cvs commit: jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration CompositeConfiguration.java
Date Wed, 18 Jun 2003 17:45:50 GMT
epugh       2003/06/18 10:45:50

  Modified:    configuration/src/test/org/apache/commons/configuration
                        TestCompositeConfiguration.java
               configuration/xdocs tasks.xml
               configuration/src/java/org/apache/commons/configuration
                        CompositeConfiguration.java
  Log:
  Fix for CompositeConfiguration.getKeys() being unordered.
  Now it is ordered.
  
  Revision  Changes    Path
  1.8       +44 -1     jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java
  
  Index: TestCompositeConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestCompositeConfiguration.java	22 Mar 2003 05:18:16 -0000	1.7
  +++ TestCompositeConfiguration.java	18 Jun 2003 17:45:50 -0000	1.8
  @@ -56,6 +56,9 @@
   
   import java.io.File;
   import java.util.Vector;
  +import java.util.Iterator;
  +import java.util.List;
  +import java.util.ArrayList;
   
   import junit.framework.TestCase;
   
  @@ -271,4 +274,44 @@
           // we should get 0 packages here
           assertEquals(0, packages.length);
       }
  +    
  +    /**
  +      * 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();){
  +            orderedList.add(keys.next());
  +        }
  +        List iteratedList = new ArrayList();
  +        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));
  +        }        
  +    }    
  +
  +    /**
  +      * 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();){
  +            orderedList.add(keys.next());
  +        }
  +        List iteratedList = new ArrayList();
  +        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));
  +        }        
  +    }        
   }
  
  
  
  1.4       +9 -0      jakarta-commons-sandbox/configuration/xdocs/tasks.xml
  
  Index: tasks.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/configuration/xdocs/tasks.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- tasks.xml	7 Jun 2003 19:30:44 -0000	1.3
  +++ tasks.xml	18 Jun 2003 17:45:50 -0000	1.4
  @@ -49,6 +49,15 @@
   </section>
   <section name='Completed'>
       <subsection name="Since Last Release"> 
  +       <ul>
  +          <li>
  +              <strong>CompositeConfiguration.getKeys() Fix</strong>
  +			  The CompositeConfiguration.getKeys() method was returning an
  +			  unordered list of configuration values.  However, many apps
  +			  expect the order that keys are returned to be the order they
  +			  are added into the properties file.
  +          </li>
  +       </ul>
       </subsection>
   </section>
     </body>
  
  
  
  1.11      +10 -6     jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java
  
  Index: CompositeConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- CompositeConfiguration.java	7 Jun 2003 19:30:43 -0000	1.10
  +++ CompositeConfiguration.java	18 Jun 2003 17:45:50 -0000	1.11
  @@ -57,6 +57,7 @@
   import java.util.ArrayList;
   import java.util.HashSet;
   import java.util.Iterator;
  +import java.util.List;
   import java.util.ListIterator;
   import java.util.NoSuchElementException;
   import java.util.Properties;
  @@ -138,19 +139,20 @@
        */
       public Iterator getKeys()
       {
  -        HashSet keys = new HashSet();
  +        List keys = new ArrayList();
           for (ListIterator i = configList.listIterator(); i.hasNext();)
           {
               Configuration config = (Configuration) i.next();
               for (Iterator j = config.getKeys(); j.hasNext();)
               {
                   String key = (String) j.next();
  -                keys.add(key);
  +                if (!keys.contains(key)){
  +                    keys.add(key);
  +                }
               }
           }
           return keys.iterator();
       }
  -
       /**
        * Get the list of the keys contained in the configuration
        * repository.
  @@ -159,14 +161,16 @@
        */
       public Iterator getKeys(String key)
       {
  -        HashSet keys = new HashSet();
  +        List keys = new ArrayList();
           for (ListIterator i = configList.listIterator(); i.hasNext();)
           {
               Configuration config = (Configuration) i.next();
               for (Iterator j = config.getKeys(key); j.hasNext();)
               {
                   String newKey = (String) j.next();
  -                keys.add(newKey);
  +                if (!keys.contains(newKey)){
  +                     keys.add(newKey);
  +                 }
               }
           }
           return keys.iterator();
  
  
  

---------------------------------------------------------------------
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