You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by eb...@apache.org on 2005/08/24 13:15:29 UTC

svn commit: r239602 - /jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java

Author: ebourg
Date: Wed Aug 24 04:15:27 2005
New Revision: 239602

URL: http://svn.apache.org/viewcvs?rev=239602&view=rev
Log:
Code simplification in BaseConfiguration

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java?rev=239602&r1=239601&r2=239602&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java Wed Aug 24 04:15:27 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License")
  * you may not use this file except in compliance with the License.
@@ -16,10 +16,10 @@
 
 package org.apache.commons.configuration;
 
+import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.List;
-import java.util.ArrayList;
+import java.util.Map;
 
 import org.apache.commons.collections.map.LinkedMap;
 
@@ -53,54 +53,33 @@
     private Map store = new LinkedMap();
 
     /**
-     * Empty constructor.  You must add all the values to this configuration.
-     */
-    public BaseConfiguration()
-    {
-        super();
-    }
-
-    /**
      * 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
+     * @param value object to store
      */
-    protected void addPropertyDirect(String key, Object obj)
+    protected void addPropertyDirect(String key, Object value)
     {
-        Object o = getProperty(key);
-        Object objAdd = null;
+        Object previousValue = getProperty(key);
 
-        if (o == null)
+        if (previousValue == null)
         {
-            objAdd = obj;
+            store.put(key, value);
         }
-        else
+        else if (previousValue instanceof List)
         {
-            if (o instanceof List)
-            {
-                ((List) o).add(obj);
-            }
-            else
-            {
-                // The token key is not a list.
-                List list = new ArrayList();
-
-                // There is an element. Put it into the list
-                // at the first position
-                list.add(o);
-
-                // Now gobble up the supplied object
-                list.add(obj);
-
-                objAdd = list;
-            }
+            // the value is added to the existing list
+            ((List) previousValue).add(value);
         }
-
-        if (objAdd != null)
+        else
         {
-            store.put(key, objAdd);
+            // the previous value is replaced by a list containing the previous value and the new value
+            List list = new ArrayList();
+            list.add(previousValue);
+            list.add(value);
+
+            store.put(key, list);
         }
     }
 



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