You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2008/02/07 08:29:45 UTC
svn commit: r619297 - in
/commons/proper/configuration/branches/configuration2_experimental/src:
main/java/org/apache/commons/configuration2/BaseConfiguration.java
test/java/org/apache/commons/configuration2/TestBaseConfiguration.java
Author: oheger
Date: Wed Feb 6 23:29:44 2008
New Revision: 619297
URL: http://svn.apache.org/viewvc?rev=619297&view=rev
Log:
Removed dependency to commons-collections from BaseConfiguration and some Java 1.5-related changes
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/BaseConfiguration.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestBaseConfiguration.java
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/BaseConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/BaseConfiguration.java?rev=619297&r1=619296&r2=619297&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/BaseConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/BaseConfiguration.java Wed Feb 6 23:29:44 2008
@@ -19,11 +19,10 @@
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.collections.map.LinkedMap;
-
/**
* Basic configuration classe. Stores the configuration data but does not
* provide any load or save functions. If you want to load your Configuration
@@ -45,13 +44,13 @@
* @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @author <a href="mailto:ksh@scand.com">Konstantin Shaposhnikov</a>
- * @author <a href="mailto:oliver.heger@t-online.de">Oliver Heger</a>
+ * @author Oliver Heger
* @version $Id$
*/
public class BaseConfiguration extends AbstractConfiguration implements Cloneable
{
/** stores the configuration key-value pairs */
- private Map store = new LinkedMap();
+ private Map<String, Object> store = new LinkedHashMap<String, Object>();
/**
* Adds a key/value pair to the map. This routine does no magic morphing.
@@ -60,6 +59,7 @@
* @param key key to use for mapping
* @param value object to store
*/
+ @SuppressWarnings("unchecked")
protected void addPropertyDirect(String key, Object value)
{
Object previousValue = getProperty(key);
@@ -71,12 +71,12 @@
else if (previousValue instanceof List)
{
// the value is added to the existing list
- ((List) previousValue).add(value);
+ ((List<Object>) previousValue).add(value);
}
else
{
// the previous value is replaced by a list containing the previous value and the new value
- List list = new ArrayList();
+ List<Object> list = new ArrayList<Object>();
list.add(previousValue);
list.add(value);
@@ -146,7 +146,7 @@
*
* @return An Iterator.
*/
- public Iterator getKeys()
+ public Iterator<String> getKeys()
{
return store.keySet().iterator();
}
@@ -159,12 +159,13 @@
* @return the copy
* @since 1.3
*/
+ @SuppressWarnings("unchecked")
public Object clone()
{
try
{
BaseConfiguration copy = (BaseConfiguration) super.clone();
- copy.store = (Map) ConfigurationUtils.clone(store);
+ copy.store = (Map<String, Object>) ConfigurationUtils.clone(store);
return copy;
}
catch (CloneNotSupportedException cex)
Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestBaseConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestBaseConfiguration.java?rev=619297&r1=619296&r2=619297&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestBaseConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestBaseConfiguration.java Wed Feb 6 23:29:44 2008
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Properties;
@@ -32,7 +33,6 @@
import junitx.framework.ListAssert;
import junitx.framework.ObjectAssert;
-import org.apache.commons.collections.set.ListOrderedSet;
import org.apache.commons.configuration2.AbstractConfiguration;
import org.apache.commons.configuration2.BaseConfiguration;
import org.apache.commons.configuration2.Configuration;
@@ -53,9 +53,10 @@
protected BaseConfiguration config = null;
- protected static Class missingElementException = NoSuchElementException.class;
- protected static Class incompatibleElementException = ConversionException.class;
+ protected static Class<?> missingElementException = NoSuchElementException.class;
+ protected static Class<?> incompatibleElementException = ConversionException.class;
+ @Override
protected void setUp() throws Exception
{
config = new BaseConfiguration();
@@ -409,7 +410,7 @@
{
config.addProperty("number", "1");
config.addProperty("number", "2");
- List list = config.getList("number");
+ List<?> list = config.getList("number");
assertNotNull("The list is null", list);
assertEquals("List size", 2, list.size());
assertTrue("The number 1 is missing from the list", list.contains("1"));
@@ -435,7 +436,7 @@
config.addProperty("array", "${number}");
config.addProperty("array", "${number}");
- List list = new ArrayList();
+ List<String> list = new ArrayList<String>();
list.add("1");
list.add("1");
@@ -501,7 +502,7 @@
public void testAddProperty() throws Exception
{
- Collection props = new ArrayList();
+ Collection<Object> props = new ArrayList<Object>();
props.add("one");
props.add("two,three,four");
props.add(new String[] { "5.1", "5.2", "5.3,5.4", "5.5" });
@@ -510,10 +511,10 @@
Object val = config.getProperty("complex.property");
assertTrue(val instanceof Collection);
- Collection col = (Collection) val;
+ Collection<?> col = (Collection<?>) val;
assertEquals(10, col.size());
- props = new ArrayList();
+ props = new ArrayList<Object>();
props.add("quick");
props.add("brown");
props.add("fox,jumps");
@@ -523,8 +524,8 @@
config.setProperty("complex.property", data);
val = config.getProperty("complex.property");
assertTrue(val instanceof Collection);
- col = (Collection) val;
- Iterator it = col.iterator();
+ col = (Collection<?>) val;
+ Iterator<?> it = col.iterator();
StringTokenizer tok = new StringTokenizer("The quick brown fox jumps over the lazy dog.", " ");
while(tok.hasMoreTokens())
{
@@ -593,7 +594,7 @@
fail("Should return a list");
}
- Iterator it = subEprop.getKeys();
+ Iterator<String> it = subEprop.getKeys();
it.next();
assertFalse(it.hasNext());
@@ -702,7 +703,7 @@
assertEquals("first element of the 'array' property", "foo", config.resolveContainerStore("array"));
// list of objects
- List list = new ArrayList();
+ List<String> list = new ArrayList<String>();
list.add("foo");
list.add("bar");
config.addPropertyDirect("list", list);
@@ -710,7 +711,7 @@
assertEquals("first element of the 'list' property", "foo", config.resolveContainerStore("list"));
// set of objects
- Set set = new ListOrderedSet();
+ Set<String> set = new LinkedHashSet<String>();
set.add("foo");
set.add("bar");
config.addPropertyDirect("set", set);
@@ -774,7 +775,7 @@
}
BaseConfiguration config2 = (BaseConfiguration) config.clone();
- for (Iterator it = config.getKeys(); it.hasNext();)
+ for (Iterator<String> it = config.getKeys(); it.hasNext();)
{
String key = (String) it.next();
assertTrue("Key not found: " + key, config2.containsKey(key));