Author: oheger
Date: Wed Feb  6 23:17:56 2008
New Revision: 619296

URL: http://svn.apache.org/viewvc?rev=619296&view=rev
Log:
Removed dependency to commons-collections from PropertiesConfigurationLayout 
and some Java 1.5-related changes

Modified:
    
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
    
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java
    
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java

Modified: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java?rev=619296&r1=619295&r2=619296&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
 (original)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
 Wed Feb  6 23:17:56 2008
@@ -543,7 +543,7 @@
     public static class PropertiesReader extends LineNumberReader
     {
         /** Stores the comment lines for the currently processed property.*/
-        private List commentLines;
+        private List<String> commentLines;
 
         /** Stores the name of the last read property.*/
         private String propertyName;
@@ -575,7 +575,7 @@
         public PropertiesReader(Reader reader, char listDelimiter)
         {
             super(reader);
-            commentLines = new ArrayList();
+            commentLines = new ArrayList<String>();
             delimiter = listDelimiter;
         }
 
@@ -660,7 +660,7 @@
          * <code>readProperty()</code>
          * @since 1.3
          */
-        public List getCommentLines()
+        public List<String> getCommentLines()
         {
             return commentLines;
         }
@@ -854,11 +854,11 @@
          *
          * @throws IOException if an I/O error occurs
          */
-        public void writeProperty(String key, List values) throws IOException
+        public void writeProperty(String key, List<?> values) throws 
IOException
         {
-            for (int i = 0; i < values.size(); i++)
+            for (Object v : values)
             {
-                writeProperty(key, values.get(i));
+                writeProperty(key, v);
             }
         }
 
@@ -881,7 +881,7 @@
 
             if (value instanceof List)
             {
-                List values = (List) value;
+                List<?> values = (List<?>) value;
                 if (forceSingleLine)
                 {
                     v = makeSingleLineValue(values);
@@ -970,13 +970,13 @@
          * @return a string with the single line value (can be <b>null</b>)
          * @since 1.3
          */
-        private String makeSingleLineValue(List values)
+        private String makeSingleLineValue(List<?> values)
         {
             if (!values.isEmpty())
             {
-                Iterator it = values.iterator();
+                Iterator<?> it = values.iterator();
                 String lastValue = escapeValue(it.next());
-                StringBuffer buf = new StringBuffer(lastValue);
+                StringBuilder buf = new StringBuilder(lastValue);
                 while (it.hasNext())
                 {
                     // if the last value ended with an escape character, it has

Modified: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java?rev=619296&r1=619295&r2=619296&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java
 (original)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java
 Wed Feb  6 23:17:56 2008
@@ -19,12 +19,11 @@
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
-import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.commons.collections.map.LinkedMap;
 import org.apache.commons.configuration2.event.ConfigurationEvent;
 import org.apache.commons.configuration2.event.ConfigurationListener;
 import org.apache.commons.lang.StringUtils;
@@ -127,7 +126,7 @@
     private PropertiesConfiguration configuration;
 
     /** Stores a map with the contained layout information. */
-    private Map layoutData;
+    private Map<String, PropertyLayoutData> layoutData;
 
     /** Stores the header comment. */
     private String headerComment;
@@ -166,7 +165,7 @@
                     "Configuration must not be null!");
         }
         configuration = config;
-        layoutData = new LinkedMap();
+        layoutData = new LinkedHashMap<String, PropertyLayoutData>();
         config.addConfigurationListener(this);
 
         if (c != null)
@@ -363,7 +362,7 @@
      *
      * @return a set with all contained property keys
      */
-    public Set getKeys()
+    public Set<String> getKeys()
     {
         return layoutData.keySet();
     }
@@ -453,9 +452,8 @@
                 writer.writeln(null);
             }
 
-            for (Iterator it = layoutData.keySet().iterator(); it.hasNext();)
+            for (String key : layoutData.keySet())
             {
-                String key = (String) it.next();
                 if (getConfiguration().containsKey(key))
                 {
 
@@ -661,7 +659,7 @@
      * @param to the end index (inclusive)
      * @return the comment string (<b>null</b> if it is undefined)
      */
-    private String extractComment(List commentLines, int from, int to)
+    private String extractComment(List<String> commentLines, int from, int to)
     {
         if (to < from)
         {
@@ -670,7 +668,7 @@
 
         else
         {
-            StringBuffer buf = new StringBuffer((String) 
commentLines.get(from));
+            StringBuilder buf = new StringBuilder(commentLines.get(from));
             for (int i = from + 1; i <= to; i++)
             {
                 buf.append(CR);
@@ -684,22 +682,21 @@
      * Checks if parts of the passed in comment can be used as header comment.
      * This method checks whether a header comment can be defined (i.e. whether
      * this is the first comment in the loaded file). If this is the case, it 
is
-     * searched for the lates blanc line. This line will mark the end of the
+     * searched for the latest blanc line. This line will mark the end of the
      * header comment. The return value is the index of the first line in the
      * passed in list, which does not belong to the header comment.
      *
      * @param commentLines the comment lines
      * @return the index of the next line after the header comment
      */
-    private int checkHeaderComment(List commentLines)
+    private int checkHeaderComment(List<String> commentLines)
     {
         if (loadCounter == 1 && getHeaderComment() == null
                 && layoutData.isEmpty())
         {
             // This is the first comment. Search for blanc lines.
             int index = commentLines.size() - 1;
-            while (index >= 0
-                    && ((String) commentLines.get(index)).length() > 0)
+            while (index >= 0 && commentLines.get(index).length() > 0)
             {
                 index--;
             }
@@ -719,12 +716,11 @@
      */
     private void copyFrom(PropertiesConfigurationLayout c)
     {
-        for (Iterator it = c.getKeys().iterator(); it.hasNext();)
+        for (String key : c.getKeys())
         {
-            String key = (String) it.next();
             PropertyLayoutData data = (PropertyLayoutData) c.layoutData
                     .get(key);
-            layoutData.put(key, data.clone());
+            layoutData.put(key, (PropertyLayoutData) data.clone());
         }
     }
 

Modified: 
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java?rev=619296&r1=619295&r2=619296&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java
 (original)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java
 Wed Feb  6 23:17:56 2008
@@ -61,6 +61,7 @@
     /** A properties builder that can be used for testing. */
     PropertiesBuilder builder;
 
+    @Override
     protected void setUp() throws Exception
     {
         super.setUp();
@@ -77,7 +78,7 @@
     {
         assertTrue("Object contains keys", layout.getKeys().isEmpty());
         assertNull("Header comment not null", layout.getHeaderComment());
-        Iterator it = config.getConfigurationListeners().iterator();
+        Iterator<?> it = config.getConfigurationListeners().iterator();
         assertTrue("No event listener registered", it.hasNext());
         assertSame("Layout not registered as event listener", layout, 
it.next());
         assertFalse("Multiple event listeners registered", it.hasNext());
@@ -575,9 +576,8 @@
                 config, layout);
         assertEquals("Wrong number of keys", layout.getKeys().size(), l2
                 .getKeys().size());
-        for (Iterator it = layout.getKeys().iterator(); it.hasNext();)
+        for (String key : layout.getKeys())
         {
-            Object key = it.next();
             assertTrue("Key was not found: " + key, 
l2.getKeys().contains(key));
         }
     }


Reply via email to