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/src/java/org/apache/commons/configuration AbstractConfiguration.java BaseConfiguration.java ConfigurationFactory.java HierarchicalConfiguration.java HierarchicalConfigurationXMLReader.java
Date Mon, 05 Jul 2004 09:54:17 GMT
ebourg      2004/07/05 02:54:17

  Modified:    configuration/src/java/org/apache/commons/configuration
                        AbstractConfiguration.java BaseConfiguration.java
                        ConfigurationFactory.java
                        HierarchicalConfiguration.java
                        HierarchicalConfigurationXMLReader.java
  Log:
  Removed the AbstractConfiguration.Container inner class, a List is used instead
  
  Revision  Changes    Path
  1.17      +15 -102   jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java
  
  Index: AbstractConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AbstractConfiguration.java	24 Jun 2004 14:01:03 -0000	1.16
  +++ AbstractConfiguration.java	5 Jul 2004 09:54:17 -0000	1.17
  @@ -238,8 +238,8 @@
   
           //
           // We keep the sequence of the keys here and
  -        // we also keep it in the Container. So the
  -        // Keys are added to the store in the sequence that
  +        // we also keep it in the List. So the
  +        // keys are added to the store in the sequence that
           // is given in the properties
           return list;
       }
  @@ -367,21 +367,8 @@
        */
       public Object getProperty(String key)
       {
  -        // first, try to get from the 'user value' store
  -        Object o = getPropertyDirect(key);
  -
  -
  -        //
  -        // We must never give a Container Object out. So if the
  -        // Return Value is a Container, we fix it up to be a
  -        // List
  -        //
  -        if (o instanceof Container)
  -        {
  -            o = ((Container) o).asList();
  -        }
  -        return o;
  -   }
  +        return getPropertyDirect(key);
  +    }
   
       /**
        * {@inheritDoc}
  @@ -949,13 +936,14 @@
   
               tokens[0] = interpolate((String) value);
           }
  -        else if (value instanceof Container)
  +        else if (value instanceof List)
           {
  -            tokens = new String[((Container) value).size()];
  +            List list = (List) value;
  +            tokens = new String[list.size()];
   
               for (int i = 0; i < tokens.length; i++)
               {
  -                tokens[i] = interpolate((String) ((Container) value).get(i));
  +                tokens[i] = interpolate((String) list.get(i));
               }
           }
           else if (value == null)
  @@ -991,10 +979,6 @@
               list = new ArrayList(1);
               list.add(value);
           }
  -        else if (value instanceof Container)
  -        {
  -            list = ((Container) value).asList();
  -        }
           else if (value instanceof List)
           {
               list = (List) value;
  @@ -1017,21 +1001,20 @@
       }
   
       /**
  -     * Returns an object from the store described by the key.
  -     * If the value is a Container object, replace it with the
  -     * first object in the container
  +     * Returns an object from the store described by the key. If the value is
  +     * a List object, replace it with the first object in the list.
        *
        * @param key The property key.
        *
  -     * @return value Value, transparently resolving a possible
  -     *         Container dependency.
  +     * @return value Value, transparently resolving a possible List dependency.
        */
       private Object resolveContainerStore(String key)
       {
           Object value = getPropertyDirect(key);
  -        if (value != null && value instanceof Container)
  +        if (value != null && value instanceof List)
           {
  -            value = ((Container) value).get(0);
  +            List list = (List) value;
  +            value = list.isEmpty() ? null : list.get(0);
           }
           return value;
       }
  @@ -1080,74 +1063,4 @@
           }
       } // class PropertiesTokenizer
   
  -    /**
  -     * Private Wrapper class for List, so we can distinguish between
  -     * List objects and our container
  -     */
  -    static class Container
  -    {
  -        /** We're wrapping a List object (A List) */
  -        private List list;
  -
  -        /**
  -         * Constructor
  -         */
  -        public Container()
  -        {
  -            list = new ArrayList(INITIAL_LIST_SIZE);
  -        }
  -
  -        /**
  -         * Add an Object to the Container
  -         *
  -         * @param o The Object
  -         */
  -        public void add(Object o)
  -        {
  -            list.add(o);
  -        }
  -
  -        /**
  -         * Returns the current size of the Container
  -         *
  -         * @return The Number of elements in the container
  -         */
  -        public int size()
  -        {
  -            return list.size();
  -        }
  -
  -        /**
  -         * Returns the Element at an index
  -         *
  -         * @param index The Index
  -         * @return The element at that index
  -         */
  -        public Object get(int index)
  -        {
  -            return list.get(index);
  -        }
  -
  -        /**
  -         * Returns an Iterator over the container objects
  -         *
  -         * @return An Iterator
  -         */
  -        public Iterator iterator()
  -        {
  -            return list.iterator();
  -        }
  -
  -        /**
  -         * Returns the Elements of the Container as a List. This is not the
  -         * internal list element but a shallow copy of the internal list. You
  -         * may modify the returned list without modifying the container.
  -         *
  -         * @return A List containing the elements of the Container.
  -         */
  -        public List asList()
  -        {
  -            return new ArrayList(list);
  -        }
  -    }
   }
  
  
  
  1.8       +11 -9     jakarta-commons/configuration/src/java/org/apache/commons/configuration/BaseConfiguration.java
  
  Index: BaseConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BaseConfiguration.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BaseConfiguration.java	24 Jun 2004 12:35:14 -0000	1.7
  +++ BaseConfiguration.java	5 Jul 2004 09:54:17 -0000	1.8
  @@ -18,6 +18,8 @@
   
   import java.util.Iterator;
   import java.util.Map;
  +import java.util.List;
  +import java.util.ArrayList;
   
   import org.apache.commons.collections.map.LinkedMap;
   
  @@ -77,23 +79,23 @@
           }
           else
           {
  -            if (o instanceof Container)
  +            if (o instanceof List)
               {
  -                ((Container) o).add(obj);
  +                ((List) o).add(obj);
               }
               else
               {
  -                // The token key is not a container.
  -                Container c = new Container();
  +                // The token key is not a list.
  +                List list = new ArrayList();
   
  -                // There is an element. Put it into the container
  +                // There is an element. Put it into the list
                   // at the first position
  -                c.add(o);
  +                list.add(o);
   
                   // Now gobble up the supplied object
  -                c.add(obj);
  +                list.add(obj);
   
  -                objAdd = c;
  +                objAdd = list;
               }
           }
   
  
  
  
  1.14      +2 -2      jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java
  
  Index: ConfigurationFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ConfigurationFactory.java	24 Jun 2004 14:01:03 -0000	1.13
  +++ ConfigurationFactory.java	5 Jul 2004 09:54:17 -0000	1.14
  @@ -637,7 +637,7 @@
                   AdditionalConfigurationData cdata =
                   (AdditionalConfigurationData) it.next();
                   result.addNodes(cdata.getAt(),
  -                createRootNode(cdata).getChildren().asList());
  +                createRootNode(cdata).getChildren());
               }
   
               return result.isEmpty() ? null : result;
  
  
  
  1.9       +20 -34    jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
  
  Index: HierarchicalConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- HierarchicalConfiguration.java	24 Jun 2004 12:35:15 -0000	1.8
  +++ HierarchicalConfiguration.java	5 Jul 2004 09:54:17 -0000	1.9
  @@ -148,23 +148,23 @@
           }
           else
           {
  -            Container cont = new Container();
  +            List list = new ArrayList();
               for (Iterator it = nodes.iterator(); it.hasNext();)
               {
  -                Node nd = (Node) it.next();
  -                if (nd.getValue() != null)
  +                Node node = (Node) it.next();
  +                if (node.getValue() != null)
                   {
  -                    cont.add(nd.getValue());
  +                    list.add(node.getValue());
                   }
               }
   
  -            if (cont.size() < 1)
  +            if (list.size() < 1)
               {
                   return null;
               }
               else
               {
  -                return (cont.size() == 1) ? cont.get(0) : cont;
  +                return (list.size() == 1) ? list.get(0) : list;
               }
           }
       }
  @@ -322,7 +322,7 @@
               Node nd = (Node) it.next();
               nd.visit(visitor, null);
   
  -            Container children = visitor.getClone().getChildren();
  +            List children = visitor.getClone().getChildren();
               if (children.size() > 0)
               {
                   for (int i = 0; i < children.size(); i++)
  @@ -431,7 +431,7 @@
           else
           {
               String key = keyPart.nextKey(true);
  -            Container children = node.getChildren(key);
  +            List children = node.getChildren(key);
               if (keyPart.hasIndex())
               {
                   if (keyPart.getIndex() < children.size()
  @@ -524,15 +524,15 @@
   
           if (keyIt.hasNext())
           {
  -            Container c = node.getChildren(keyPart);
  -            int idx = (keyIt.hasIndex()) ? keyIt.getIndex() : c.size() - 1;
  -            if (idx < 0 || idx >= c.size())
  +            List list = node.getChildren(keyPart);
  +            int idx = (keyIt.hasIndex()) ? keyIt.getIndex() : list.size() - 1;
  +            if (idx < 0 || idx >= list.size())
               {
                   return node;
               }
               else
               {
  -                return findLastPathNode(keyIt, (Node) c.get(idx));
  +                return findLastPathNode(keyIt, (Node) list.get(idx));
               }
           }
   
  @@ -567,20 +567,6 @@
       }
   
       /**
  -     * Helper method for adding all elements of a collection to a container.
  -     *
  -     * @param cont the container
  -     * @param items the collection to be added
  -     */
  -    private static void addContainer(Container cont, Collection items)
  -    {
  -        for (Iterator it = items.iterator(); it.hasNext();)
  -        {
  -            cont.add(it.next());
  -        }
  -    }
  -
  -    /**
        * A data class for storing (hierarchical) property information. A property
        * can have a value and an arbitrary number of child properties.
        *
  @@ -707,15 +693,15 @@
            * @return a list with the children (can be empty, but never
            * <b>null</b>)
            */
  -        public Container getChildren()
  +        public List getChildren()
           {
  -            Container result = new Container();
  +            List result = new ArrayList();
   
               if (children != null)
               {
                   for (Iterator it = children.values().iterator(); it.hasNext();)
                   {
  -                    addContainer(result, (Collection) it.next());
  +                    result.addAll((Collection) it.next());
                   }
               }
   
  @@ -729,21 +715,21 @@
            * @return a list with all chidren with this name; may be empty, but
            * never <b>null</b>
            */
  -        public Container getChildren(String name)
  +        public List getChildren(String name)
           {
               if (name == null || children == null)
               {
                   return getChildren();
               }
   
  -            Container cont = new Container();
  +            List list = new ArrayList();
               List c = (List) children.get(name);
               if (c != null)
               {
  -                addContainer(cont, c);
  +                list.addAll(c);
               }
   
  -            return cont;
  +            return list;
           }
   
           /**
  
  
  
  1.5       +6 -6      jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfigurationXMLReader.java
  
  Index: HierarchicalConfigurationXMLReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfigurationXMLReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HierarchicalConfigurationXMLReader.java	24 Jun 2004 12:35:15 -0000	1.4
  +++ HierarchicalConfigurationXMLReader.java	5 Jul 2004 09:54:17 -0000	1.5
  @@ -16,6 +16,8 @@
   
   package org.apache.commons.configuration;
   
  +import java.util.List;
  +
   import org.apache.commons.configuration.HierarchicalConfiguration.Node;
   import org.xml.sax.Attributes;
   import org.xml.sax.helpers.AttributesImpl;
  @@ -163,17 +165,15 @@
           protected Attributes fetchAttributes(Node node)
           {
               AttributesImpl attrs = new AttributesImpl();
  -            AbstractConfiguration.Container children = node.getChildren();
  +            List children = node.getChildren();
   
               for (int i = 0; i < children.size(); i++)
               {
                   Node child = (Node) children.get(i);
                   if (isAttributeNode(child) && child.getValue() != null)
                   {
  -                    String attr = ConfigurationKey.attributeName(
  -                    child.getName());
  -                    attrs.addAttribute(NS_URI, attr, attr, ATTR_TYPE,
  -                    child.getValue().toString());
  +                    String attr = ConfigurationKey.attributeName(child.getName());
  +                    attrs.addAttribute(NS_URI, attr, attr, ATTR_TYPE, child.getValue().toString());
                   }
               }
   
  
  
  

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