geirm       01/05/09 17:40:10

  Modified:    collections/src/java/org/apache/commons/collections
                        ExtendedProperties.java
               collections/src/test/org/apache/commons/collections
                        TestExtendedProperties.java
  Log:
  Fixed the problem reported by Thomas Fahrmeyer <[EMAIL PROTECTED]>
  where ExtendedProperties would re-process data when making a subset.  Hope no one
  was depending on that :)
  
  Also adjusted the testcase to test this.
  
  Revision  Changes    Path
  1.3       +31 -30    
jakarta-commons/collections/src/java/org/apache/commons/collections/ExtendedProperties.java
  
  Index: ExtendedProperties.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/ExtendedProperties.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ExtendedProperties.java   2001/05/04 02:22:48     1.2
  +++ ExtendedProperties.java   2001/05/10 00:40:08     1.3
  @@ -168,7 +168,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]>Kent Johnson</a>
    * @author <a href="mailto:[EMAIL PROTECTED]>Daniel Rall</a>
    * @author <a href="mailto:[EMAIL PROTECTED]>Ilkka Priha</a>
  - * @version $Id: ExtendedProperties.java,v 1.2 2001/05/04 02:22:48 geirm Exp $
  + * @version $Id: ExtendedProperties.java,v 1.3 2001/05/10 00:40:08 geirm Exp $
    */
   public class ExtendedProperties extends Hashtable
   {
  @@ -519,7 +519,6 @@
                       else
                       {
                           addProperty(key,value);
  -                        //setProperty(key,value);
                       }                       
                   }
               }
  @@ -581,7 +580,6 @@
        * @param String key
        * @param String value
        */
  -    //public void setProperty(String key, Object token)
       public void addProperty(String key, Object token)
       {
           Object o = this.get(key);
  @@ -635,7 +633,7 @@
                   while (tokenizer.hasMoreTokens())
                   {
                       String value = tokenizer.nextToken();
  -                    
  +                   
                       /*
                        * we know this is a string, so make sure it
                        * just goes in rather than risking vectorization
  @@ -655,24 +653,35 @@
                    * to perform operations with configuration
                    * in a definite order it will be possible.
                    */
  -
  -                /*
  -                 * safety check
  -                 */
  -
  -                if( !containsKey( key ) )
  -                {
  -                    keysAsListed.add(key);
  -                }
   
  -                /*
  -                 * and the value
  -                 */
  -                put(key, token);
  +                addPropertyDirect( key, token );
               }                
           }
       }
   
  +    /**
  +     *   Adds a key/value pair to the map.  This routine does
  +     *   no magic morphing.  It ensures the keylist is maintained
  +     *
  +     *  @param key key to use for mapping
  +     *  @param obj object to store
  +     */
  +    private void addPropertyDirect( String key, Object obj )
  +    {
  +        /*
  +         * safety check
  +         */
  +        
  +        if( !containsKey( key ) )
  +        {
  +            keysAsListed.add(key);
  +        }
  +        
  +        /*
  +         * and the value
  +         */
  +        put(key, obj);
  +    }
   
       /**
        *  Sets a string property w/o checking for commas - used
  @@ -719,12 +728,7 @@
           }
           else
           {
  -            if( !containsKey( key ) )
  -            {
  -                keysAsListed.add(key);
  -            }
  -
  -            put( key, token);
  +            addPropertyDirect( key, token );
           }
       }
   
  @@ -809,7 +813,6 @@
           for (Iterator i = c.getKeys() ; i.hasNext() ;)
           {
               String key = (String) i.next();
  -            //clearProperty(key);
               setProperty( key, c.get(key) );
           }
       }
  @@ -918,14 +921,12 @@
                   }                    
                   
                   /*
  -                 * Make sure to use the setProperty() method and not
  -                 * just put(). setProperty() takes care of catching
  -                 * all the keys in the order they appear in a
  -                 * properties files or the order they are set
  -                 * dynamically.
  +                 *  use addPropertyDirect() - this will plug the data as 
  +                 *  is into the Map, but will also do the right thing
  +                 *  re key accounting
                    */
   
  -                c.setProperty(newKey, get(key));
  +                c.addPropertyDirect( newKey, get(key) );
               }
           }
           
  
  
  
  1.2       +27 -3     
jakarta-commons/collections/src/test/org/apache/commons/collections/TestExtendedProperties.java
  
  Index: TestExtendedProperties.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestExtendedProperties.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestExtendedProperties.java       2001/05/04 02:23:44     1.1
  +++ TestExtendedProperties.java       2001/05/10 00:40:09     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestExtendedProperties.java,v
 1.1 2001/05/04 02:23:44 geirm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/05/04 02:23:44 $
  + * $Header: 
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestExtendedProperties.java,v
 1.2 2001/05/10 00:40:09 geirm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/05/10 00:40:09 $
    *
    * ====================================================================
    *
  @@ -70,7 +70,7 @@
    *   class
    * 
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
  - *   @version $Id: TestExtendedProperties.java,v 1.1 2001/05/04 02:23:44 geirm Exp $
  + *   @version $Id: TestExtendedProperties.java,v 1.2 2001/05/10 00:40:09 geirm Exp $
    */
   public class TestExtendedProperties extends TestCase
   {
  @@ -119,5 +119,29 @@
            *  property
            */
           assert("This returns scalar", ( eprop.getString("number") instanceof String 
) );
  +
  +        /*
  +         * test comma separated string properties
  +         */
  +        String prop = "hey, that's a test";
  +        eprop.setProperty("prop.string", prop);
  +        assert("This returns vector", ( eprop.getVector("prop.string") instanceof 
java.util.Vector ) );
  +        
  +        String prop2 = "hey\\, that's a test";
  +        eprop.remove("prop.string");
  +        eprop.setProperty("prop.string", prop2);
  +        assert("This returns array", ( eprop.getString("prop.string") instanceof 
java.lang.String) );
  +        
  +        /*
  +         * test subset : we want to make sure that the EP doesn't reprocess the 
data 
  +         *  elements when generating the subset
  +         */
  +
  +        ExtendedProperties subEprop = eprop.subset("prop");
  +
  +        assert("Returns the full string",  subEprop.getString("string").equals( 
prop ) );
  +        assert("This returns string for subset", ( subEprop.getString("string") 
instanceof java.lang.String) );
  +        assert("This returns array for subset", ( subEprop.getVector("string") 
instanceof java.util.Vector) );
  +        
       }
   }
  
  
  

Reply via email to