commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r705342 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/CompositeConfiguration.java test/java/org/apache/commons/configuration2/TestCompositeConfiguration.java
Date Thu, 16 Oct 2008 19:58:22 GMT
Author: oheger
Date: Thu Oct 16 12:58:19 2008
New Revision: 705342

URL: http://svn.apache.org/viewvc?rev=705342&view=rev
Log:
Java 1.5 related changes:
Removed type-safety warnings.
Added @Override annotations.

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/CompositeConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestCompositeConfiguration.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/CompositeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/CompositeConfiguration.java?rev=705342&r1=705341&r2=705342&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/CompositeConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/CompositeConfiguration.java
Thu Oct 16 12:58:19 2008
@@ -152,6 +152,7 @@
     /**
      * Remove all configuration reinitialize the in memory configuration.
      */
+    @Override
     public void clear()
     {
         configList.clear();
@@ -169,6 +170,7 @@
      * @param key The Key to add the property to.
      * @param token The Value to add.
      */
+    @Override
     protected void addPropertyDirect(String key, Object token)
     {
         inMemoryConfiguration.addProperty(key, token);
@@ -184,9 +186,8 @@
     public Object getProperty(String key)
     {
         Configuration firstMatchingConfiguration = null;
-        for (Iterator i = configList.iterator(); i.hasNext();)
+        for (Configuration config : configList)
         {
-            Configuration config = (Configuration) i.next();
             if (config.containsKey(key))
             {
                 firstMatchingConfiguration = config;
@@ -209,8 +210,7 @@
         List<String> keys = new ArrayList<String>();
         for (Configuration config : configList)
         {
-            Iterator<String> j = config.getKeys();
-            while (j.hasNext())
+            for (Iterator<String> j = config.getKeys(); j.hasNext();)
             {
                 String key = j.next();
                 if (!keys.contains(key))
@@ -223,15 +223,15 @@
         return keys.iterator();
     }
 
+    @Override
     public Iterator<String> getKeys(String key)
     {
         List<String> keys = new ArrayList<String>();
         for (Configuration config : configList)
         {
-            Iterator j = config.getKeys(key);
-            while (j.hasNext())
+            for (Iterator<String> j = config.getKeys(key); j.hasNext();)
             {
-                String newKey = (String) j.next();
+                String newKey = j.next();
                 if (!keys.contains(newKey))
                 {
                     keys.add(newKey);
@@ -245,9 +245,8 @@
     public boolean isEmpty()
     {
         boolean isEmpty = true;
-        for (Iterator i = configList.iterator(); i.hasNext();)
+        for (Configuration config : configList)
         {
-            Configuration config = (Configuration) i.next();
             if (!config.isEmpty())
             {
                 return false;
@@ -257,20 +256,19 @@
         return isEmpty;
     }
 
+    @Override
     protected void clearPropertyDirect(String key)
     {
-        for (Iterator i = configList.iterator(); i.hasNext();)
+        for (Configuration config : configList)
         {
-            Configuration config = (Configuration) i.next();
             config.clearProperty(key);
         }
     }
 
     public boolean containsKey(String key)
     {
-        for (Iterator i = configList.iterator(); i.hasNext();)
+        for (Configuration config : configList)
         {
-            Configuration config = (Configuration) i.next();
             if (config.containsKey(key))
             {
                 return true;
@@ -279,6 +277,7 @@
         return false;
     }
 
+    @Override
     public <T> List<T> getList(String key, List<T> defaultValue)
     {
         List list = new ArrayList();
@@ -311,9 +310,10 @@
         return list;
     }
 
+    @Override
     public String[] getStringArray(String key)
     {
-        List list = getList(key);
+        List<?> list = getList(key);
 
         // interpolate the strings
         String[] tokens = new String[list.size()];
@@ -358,6 +358,7 @@
      * @return the copy
      * @since 1.3
      */
+    @Override
     public Object clone()
     {
         try
@@ -397,6 +398,7 @@
      * @param delimiterParsingDisabled the new value of the flag
      * @since 1.4
      */
+    @Override
     public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
     {
         ((BaseConfiguration) getInMemoryConfiguration())
@@ -411,6 +413,7 @@
      * @param listDelimiter the new list delimiter character
      * @since 1.4
      */
+    @Override
     public void setListDelimiter(char listDelimiter)
     {
         ((BaseConfiguration) getInMemoryConfiguration())
@@ -449,9 +452,8 @@
         }
 
         Configuration source = null;
-        for (Iterator it = configList.iterator(); it.hasNext();)
+        for (Configuration conf : configList)
         {
-            Configuration conf = (Configuration) it.next();
             if (conf.containsKey(key))
             {
                 if (source != null)

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestCompositeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestCompositeConfiguration.java?rev=705342&r1=705341&r2=705342&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestCompositeConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestCompositeConfiguration.java
Thu Oct 16 12:58:19 2008
@@ -22,26 +22,18 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
-import java.util.Collection;
 
-import org.apache.commons.configuration2.CompositeConfiguration;
-import org.apache.commons.configuration2.Configuration;
-import org.apache.commons.configuration2.ConfigurationConverter;
-import org.apache.commons.configuration2.ConfigurationException;
-import org.apache.commons.configuration2.ConfigurationRuntimeException;
-import org.apache.commons.configuration2.PropertiesConfiguration;
-import org.apache.commons.configuration2.StrictConfigurationComparator;
-import org.apache.commons.configuration2.XMLConfiguration;
+import junit.framework.TestCase;
+
 import org.apache.commons.configuration2.event.ConfigurationEvent;
 import org.apache.commons.configuration2.event.ConfigurationListener;
 import org.apache.commons.configuration2.flat.BaseConfiguration;
 import org.apache.commons.configuration2.reloading.FileAlwaysReloadingStrategy;
 
-import junit.framework.TestCase;
-
 /**
  * Test loading multiple configurations.
  *
@@ -64,6 +56,7 @@
     private String testProperties2 = ConfigurationAssert.getTestFile("test2.properties").getAbsolutePath();
     private String testPropertiesXML = ConfigurationAssert.getTestFile("test.xml").getAbsolutePath();
 
+    @Override
     protected void setUp() throws Exception
     {
         cc = new CompositeConfiguration();
@@ -97,7 +90,7 @@
     {
         cc.addConfiguration(conf1);
         cc.addConfiguration(conf2);
-        List l = cc.getList("packages");
+        List<?> l = cc.getList("packages");
         assertTrue(l.contains("packagea"));
     }
 
@@ -276,11 +269,11 @@
         cc.addConfiguration(conf1);
         cc.addConfiguration(xmlConf);
 
-        List packages = cc.getList("packages");
+        List<?> packages = cc.getList("packages");
         // we should get 3 packages here
         assertEquals(3, packages.size());
 
-        List defaultList = new ArrayList();
+        List<String> defaultList = new ArrayList<String>();
         defaultList.add("1");
         defaultList.add("2");
 
@@ -321,7 +314,7 @@
         cc.addConfiguration(conf2);
 
         // check the composite 'array' property
-        List list = cc.getList("array");
+        List<?> list = cc.getList("array");
         assertNotNull("null list", list);
         assertEquals("list size", 2, list.size());
         assertTrue("'value1' not found in the list", list.contains("value1"));
@@ -345,13 +338,13 @@
     public void testGetKeysPreservesOrder() throws Exception
     {
         cc.addConfiguration(conf1);
-        List orderedList = new ArrayList();
-        for (Iterator keys = conf1.getKeys(); keys.hasNext();)
+        List<String> orderedList = new ArrayList<String>();
+        for (Iterator<String> keys = conf1.getKeys(); keys.hasNext();)
         {
             orderedList.add(keys.next());
         }
-        List iteratedList = new ArrayList();
-        for (Iterator keys = cc.getKeys(); keys.hasNext();)
+        List<String> iteratedList = new ArrayList<String>();
+        for (Iterator<String> keys = cc.getKeys(); keys.hasNext();)
         {
             iteratedList.add(keys.next());
         }
@@ -368,13 +361,13 @@
     public void testGetKeys2PreservesOrder() throws Exception
     {
         cc.addConfiguration(conf1);
-        List orderedList = new ArrayList();
-        for (Iterator keys = conf1.getKeys("test"); keys.hasNext();)
+        List<String> orderedList = new ArrayList<String>();
+        for (Iterator<String> keys = conf1.getKeys("test"); keys.hasNext();)
         {
             orderedList.add(keys.next());
         }
-        List iteratedList = new ArrayList();
-        for (Iterator keys = cc.getKeys("test"); keys.hasNext();)
+        List<String> iteratedList = new ArrayList<String>();
+        for (Iterator<String> keys = cc.getKeys("test"); keys.hasNext();)
         {
             iteratedList.add(keys.next());
         }
@@ -425,13 +418,13 @@
         assertTrue(testConfiguration.containsKey(TEST_KEY));
         assertFalse(testConfiguration.isEmpty());
         boolean foundTestKey = false;
-        Iterator i = testConfiguration.getKeys();
+        Iterator<String> i = testConfiguration.getKeys();
         //assertTrue(i instanceof IteratorChain);
         //IteratorChain ic = (IteratorChain)i;
         //assertEquals(2,i.size());
         for (; i.hasNext();)
         {
-            String key = (String) i.next();
+            String key = i.next();
             if (key.equals(TEST_KEY))
             {
                 foundTestKey = true;
@@ -469,7 +462,7 @@
         PropertiesConfiguration c2 = new PropertiesConfiguration();
         c2.addProperty("c2.value", "test2");
         cc.addConfiguration(c2);
-        List lst = cc.getList("c1.value");
+        List<?> lst = cc.getList("c1.value");
         assertEquals("Wrong list size", 2, lst.size());
         assertEquals("Wrong first element", "test1", lst.get(0));
         assertEquals("Wrong second element", "test2", lst.get(1));
@@ -534,7 +527,7 @@
 
     public void testInstanciateWithCollection()
     {
-        Collection configs = new ArrayList();
+        Collection<Configuration> configs = new ArrayList<Configuration>();
         configs.add(xmlConf);
         configs.add(conf1);
         configs.add(conf2);



Mime
View raw message